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
one day when rahul went to his computer lab and saw that all the computers were connected to a single printer and whoever is giv
amm1812

Explanation:

you can connect multiple PCs to the wireless printer and print your documents from each one of them as long as the printer can be connected to the same network . You need the disc that came with the wireless printer to install the correct drivers on your computers and laptops.

hope it helps ( brainleist please )

7 0
2 years ago
What option for deploying software to users provides a link to install an application within Control Panel's Programs and Featur
grin007 [14]

Answer:

This question is related to the  following options:

1. Published  - 2. Delegated -  3. Assigned  - 4. Mandated

And the option within Control Panel > Programs and Features > that includes a link to install an application is ; <em>"Published"</em>  thereby the answer would be <em>(</em><em>1.</em><em>)</em>

7 0
3 years ago
What are two type of physicals connection
netineya [11]
Two types of physical connection are:

A wired connection using a cable

A wireless connection using radio waves
7 0
3 years ago
Which of these is an example of an input?
boyakko [2]

Answer:

typing on a key board

this is the best Ans.

8 0
3 years ago
Review the HTML tags that we have gone over in this lesson. Research HTML tags on the web and identify two new tags. Use these t
NemiM [27]

Answer:

w3schools

Explanation:

there is a webiste called w3schools that really helped me through my web page design class, just click on learn html

4 0
3 years ago
Other questions:
  • One of the disadvantages of cable technology is that:
    7·1 answer
  • Operating system software allows you to use your fingers, a mouse or other pointing device to select screen controls, such as bu
    5·2 answers
  • What is the difference between primary storage,secondary storage and offline storage what type of storage can be
    6·2 answers
  • Programming CRe-type the code and fix any errors. The code should convert non-positive numbers to 1.
    12·1 answer
  • Bluetooth © and Wifi are two examples of transmission protocols. Which of the following statements about them is true?
    9·1 answer
  • Steps in the systems development life cycle​
    15·2 answers
  • relational integrity constraints are rules that enforce basic and fundamental information-based constraints. True or False
    9·1 answer
  • ANSWER ASAP!!!!!
    10·2 answers
  • Hey, Another question. I'm sure it's possible in the future, but I wanted to ask if HIE would be possible. I'm sure it would be,
    12·1 answer
  • Using programming libraries is one way of incorporating existing code into new programs.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!