1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
timama [110]
2 years ago
15

For this exercise, we are going to take a look at an alternate Calculator class, but this one is broken. There are several scope

issues in the calculator class that are preventing it from running. Your task is to fix the Calculator class so that it runs and prints out the correct results. The CalculatorTester is completed and should function correctly once you fix the Calculator class.
public class Calculator {
private int total;
private int value;
public Calculator(int startingValue){
int total = startingValue;
value = 0;
}
public int add(int value){
int total = total + value;
return total;
}
/**
* Adds the instance variable value to the total
*/
public int add(){
int total += value;
return total;
}
public int multiple(int value){
int total *= value;
return total;
}
public void setValue(int value){
value = value;
}
public int getValue(){
return value;
}
}
Computers and Technology
1 answer:
vekshin12 years ago
7 0

Answer:

public class Calculator {

   private int total;

   private int value;

   

   public Calculator(int startingValue){

       // no need to create a new total variable here, we need to set to the our instance total variable

       total = startingValue;

       value = 0;

   }

   public int add(int value){

       //same here, no need to create a new total variable. We need to add the value to the instance total variable

       total = total + value;

       return total;

   }

   /**

   * Adds the instance variable value to the total

   */

   public int add(){

       // no need to create a new total variable. We need to add the value to the instance total variable

       total += value;

       return total;

   }

   public int multiple(int value){

       // no need to create a new total variable. We need to multiply the instance total variable by value.

       total *= value;

       return total;

   }

   //We need to specify which value refers to which variable. Otherwise, there will be confusion. Since you declare the parameter as value, you need to put this keyword before the instance variable so that it will be distinguishable by the compiler.

   public void setValue(int value){

       this.value = value;

   }

   public int getValue(){

       return value;

   }

}

Explanation:

I fixed the errors. You may see them as comments in the code

You might be interested in
Signe wants to improve the security of the small business where she serves as a security manager. She determines that the busine
jek_recluse [69]

Answer:Obscurity

Explanation: Security through the obscurity is the mechanism that is used for the security purpose in an operating system by inducing the confidentiality in the internal parts of the operating system.

The functioning of the security through obscurity(STO) works by hiding the  flaws and errors related to security  of the operating system.Thus , Signe is willing to use obscurity system.

 

6 0
3 years ago
You manage a network that uses a single switch. All ports within your building connect through the single switch. In the lobby o
Karo-lina-s [1.5K]

Answer:

<u>VLANs</u>

Explanation:

Virtual LANs (VLANs) are a type of network connection or arrangement of network devices in the same broadcast domain. They are called Virtual LANs because they represent fractions or subgroups in the switch ports found in an Ethernet LAN.

Indeed, because of their topological arrangement, this reduces the security risk of unauthorized access to sensitive data or devices since the host can be placed on a different VLAN. Hence, in this scenario, using this network feature would allow visitors to plug into these ports to gain internet access, but they would not have access to any other devices on the private network.

5 0
2 years ago
A user logs into Active Directory on a workstation and the user home directory does not redirect to a network share on a file se
inysia [295]

Answer:

gpresult

Explanation:

Group Policy provides the system administrator with settings that would be necessary to manage the different user accounts available in an organization. It also controls their work environment centrally by configuring the user Operating System (OS), applications and user accounts.

Group policy settings or configurations are referred to as Group Policy Objects (GPOs). These objects can be linked to organizational units (OUs), domains or sites.

There are various group policy commands such as;

  1. rstrui (System Restore tool will run),
  2. runas (using different permission to run a tool or program),
  3. tasklist (currently running programs are shown
  4. gpupdate (Group policies are refreshed)
  5. gpresult (group policy configurations are displayed for verification)

gpresult command can be used to verify the group policy configurations for adjustment or optimization. The technician can start troubleshooting from viewing the active settings, then running the rstrui to start the System Restore utility to restore the computer to an earlier date

6 0
2 years ago
Which of the example DFSs discussed in this chapter would handle a large, multiclient database application most efficiently? Exp
Tju [1.3M]

Answer: A.F.S- known as Andrew File System.

Explanation:

This is a distributed network file system created to handle large multiclient database. It support Information sharing on a large scale by reducing client-server communication.

3 0
2 years ago
A newspaper runs stories that suggest that most people in the country support cutting taxes. After reading the stories, people w
Nataliya [291]

Answer:

Spiral of silence

Explanation:

The spiral of silence theory states that people remain silent regarding a topic when they feel that their views are in opposition with the rest of the majority.

As stated in the question, the newspaper's stories suggest that majority of the people support cutting taxes, this leads people who supoort raising taxes to not air their opinions because they think that everyone else supports cutting taxes like the papers say.

5 0
3 years ago
Read 2 more answers
Other questions:
  • Assume that the classes listed in the Java Quick Reference have been imported where appropriate.
    14·1 answer
  • Make the correct match.
    11·1 answer
  • when seeking information on the on the internet about a variety of subjects the most useful place to look would be?
    13·1 answer
  • _____ create computer programs by using their knowledge of computer science, math, and other disciplines.
    11·1 answer
  • How does technology helps save the environment?​
    6·1 answer
  • Which of the selections below represents a recursive query?
    12·1 answer
  • The merge sort algorithm____________.A. Can be used only on vectors of even length.B. Works by reducing vectors down to the base
    9·1 answer
  • Rhea has been asked to interview the new CEO of an energy company. She has scheduled a meeting with him in the company’s meeting
    9·2 answers
  • Which cable standard is a standard for newer digital cable, satellite, and cable modem connections?
    11·1 answer
  • The most important preinstalled software is the ______ software that allows you to use the computer the first time you turn it o
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!