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
A(n)<br> is a fast compute with lots of storage. pls help
Pachacha [2.7K]

Answer:

Surface Laptop 3 - 15", Platinum (metal), AMD Ryzen 5 3580U, 8GB, 128GB

4 0
3 years ago
Read 2 more answers
Create a function named CountVowels() that takes one parameter name epsilon
LenaWriter [7]

def CountVowels(epsilon):

   countNum = 0

   for x in range(len(epsilon)):

       letter = epsilon[x]

       if letter.lower() in "aeiou":

           countNum += 1

   return countNum

def ExtractOdds(zeta):

   result = ""

   for x in range(len(zeta)):

       if x % 2 == 1:

           result += zeta[x]

   return result

sentence_A = input("Enter a sentence: ")

sentence_B = input("Enter a sentence: ")

print(CountVowels(sentence_A))

print(ExtractOdds(sentence_B))

I hope this helps!

5 0
2 years ago
Is white 444 a hacker​
anastassius [24]

Answer:

WHITE 444 playing like a Hacker in Rank Game in Indian Server ||All are say Hacker|| Freefire · Raman Gamer.

Explanation:

boogers

3 0
2 years ago
What are some innovations that a cell phone has undergone since its original invention?
Contact [7]
- They now have color screens
- Touch screen
- Higher bandwidth due to different radio
- More memory and processing power
- Ability to install and run apps

One could joke that battery life has not improved...
4 0
3 years ago
When workers demonstrate patience, are able to manage there emotions, and get along with other employees, which skills are being
LenKa [72]
The skill thar is being displayed I thing is being outgoing and loyal
6 0
3 years ago
Read 2 more answers
Other questions:
  • ________ are viruses that masquerade as useful programs or files. hydras spyware programs worms adware programs trojan horses
    6·1 answer
  • It's time for you to schedule a dental checkup. The responsible thing to do is to ___
    11·1 answer
  • What is a benifit of having a client/server network?
    6·1 answer
  • A person clicks on an ad of a fitness club in a blog on nutrition. The person conducts a search on yoga and moves to another web
    8·1 answer
  • Which numbering system is used for some network addresses, to describe colors
    6·1 answer
  • What is the best game of 2020 in pc​
    12·2 answers
  • Coordinate with
    12·1 answer
  • At the start of the school year, Brianna’s history teacher announces that students’ final grades will be weighted based on how t
    8·2 answers
  • Explain what a datalist element does and is used for.
    12·1 answer
  • Transition words and phrase in a paragraph
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!