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
Mary uploaded some images on her website. She chose an image and downloaded it. She found that the image she saw on screen did n
zalisa [80]

Answer:

A.

Some image resolution was lost while uploading it

As she uploaded them on her website not downloading as choice B&D show while E is false and C is rarely occur

7 0
3 years ago
_________________ allows cloud controller to locate instances on separate zones to boost redundancy.
kogti [31]

Answer:

_____Router___ allows the cloud controller to locate instances on separate zones to boost redundancy.

Explanation:

A router, as a networking device, forwards data packets between one computer network and other networks.  With a router, one can use wired and wireless devices to connect to the Internet.  Unlike a modem, which connects the home network to a wider internet, a router can enable the networks to interact with one another without using the Internet.

8 0
2 years ago
What are the common characteristics of a bastion host?
Ksju [112]
The bastion host node is typically an influential server with better-quality security actions and custom software. It frequently hosts only a single request because it wants to be very good at whatever it does. The software is commonly modified, limited and not obtainable to the public. This host is envisioned to be the strong fact in the network to care for the system last it. Therefore, it often endures unvarying maintenance and audit. Occasionally bastion hosts are used to draw occurrences so that the basis of the attacks may be outlined. The bastion host practices and filters all inward traffic and averts malicious traffic from incoming the network, acting much like a gateway. 
6 0
2 years ago
Which type of game is least likely to need a structured narrative?
Anon25 [30]

Answer:

Explanation:

i love robolx and

6 0
2 years ago
NEED HELP AS SOON AS POSSIBLE
BaLLatris [955]
Vertical: goes straight up and down parallel to the y-axis
4 0
3 years ago
Other questions:
  • Why are listening and speaking part of the Common Core and ELD Standards? Why is this particularly important for our ELD student
    14·1 answer
  • Write a program that lets the user enter the name of a team and then displays the number of times that team has won the World Se
    9·1 answer
  • Class sizes of various sections of college algebra at your university are an example of which type of data? quiizlet
    13·1 answer
  • What is the FICO system?
    12·1 answer
  • Audio editing software contains several codecs that allow you to
    15·1 answer
  • Write a program to randomly fill an array of float of 10 elements (use the rand() function and make sure to use #include ) in ma
    11·1 answer
  • You should always assign the Needs Met rating before assigning the Page Quality rating, T or F ?
    6·2 answers
  • Can a 3048 hp motherboard support a i7 10700k cpu?
    11·2 answers
  • When a Select Case statement executes, the value of the test expression is compared with the values that follow each of the ____
    7·1 answer
  • The users, groups, and roles that have access to a server are called ______________________________.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!