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]
3 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:
vekshin13 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
Explain how power surges can affect computers and how this problem can be minimised or removed<br>​
Crank

Answer:

It places electrical pressure on the wires in your computer, causing them to heat up and burn. Some wires may melt and even if your computer survives the surge, the strain alone can cause damage in the long run. A way to minimize a power surge is to use a surge protector.

6 0
3 years ago
Users in a corporation currently authenticate with a username and password. A security administrator wishes to implement two-fac
Katen [24]

Answer:

Option (C) is the correct answer of this question.

Explanation:

Smart card is the security administrator wishes to implement two-factor authentication to improve security.Normally this data is affiliated with either meaning, information, or both, and will be stored and transmitted within the chip of the card.A smart card, usually a Chip Card type.

  • It is a flexible card that holds an integral computer chip that preserves and sends a signal data, either database or semiconductor form.
  • Used for controlling access to a resource.
  • Data authentication, encryption, cloud storage, and software processing can be established by smart cards.

Other options are incorrect.

4 0
3 years ago
What does brainliest do?
balandron [24]

Answer it gives u points I think

Explanation:

6 0
2 years ago
Read 2 more answers
Which of the following would an A/V technician NOT typically do? (Select all that apply).
nydimaria [60]
Where is the options?
7 0
3 years ago
What allows a programmer to write code quickly and efficiently for an action that must be repeated?
Marta_Voda [28]
An literation :))!! i hope u get it right lol
6 0
2 years ago
Read 2 more answers
Other questions:
  • Explain each of the three important concepts behind the Federal Networking Council's definition of the term Internet. Explain ho
    8·1 answer
  • You can minimize the Ribbon with a command contained on the _____.
    7·1 answer
  • Cuales son las caracteristicas de los celulares
    9·1 answer
  • Certain files, such as the ____ and Security log in Windows, might lose essential network activity records if power is terminate
    9·1 answer
  • Write a C program to calculate and display the coordinates of midpoint - M of a linesegment between two given points - say A and
    7·1 answer
  • A website for a certain political party or candidate is likely to have unbiased
    6·1 answer
  • Describe the uses of computer in different fileds? please help me ​
    14·1 answer
  • Write a function that accepts a positive random number as a parameter and returns the sum of the random number's digits. Write a
    10·1 answer
  • An epic games service is unavailable at the moment
    8·1 answer
  • A. A set of electronic program that makes of computer perform tasks
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!