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
___________ applications help you manage and present mathematical data easily and perfectly.
elixir [45]

Answer:

Spreadsheet

Explanation:

Spreadsheet applications like Microsoft Excel, Google Sheet, etc. makes the task of managing and presenting the mathematical data quite easy and perfect. It consists of rows and columns, and in each cell, we can apply a set of formulas. Its a great data mining tool as well, where the unprocessed data is cleaned, to form a piece of information at various levels, and fed to top management. It helps in all sorts of analysis, and like statistical analysis. And it supports data visualization as well. which makes the analysis even more fruitful and easy. However, its drawback is, the set of variables cannot be more than 3. And that is where the software like Microsoft Power BI and tableau comes into the picture. And they support spreadsheets as well as various other formats.

5 0
3 years ago
Today, the Nielsen Television Index provides weekly estimates of networks and major cable viewing audiences on a national level
Aleksandr-060686 [28]

Answer:

Audimeter

Explanation:

The television index is a measure of audience that estimates the percentage of households or viewers that are watching a television program and with respect to the total that your television is on during the broadcast. It manifests itself in a figure that results from the multiplication of individuals or households, by the time invested. This data is measured with audimeters.

6 0
3 years ago
Read 2 more answers
The following program is run. Then the user click the "bottomButton TWO TIMES, What will be displayed in the console
Mashutka [201]

Answer:

10

Explanation:

3 0
2 years ago
The UML models operations by listing the operation name preceded by an access modifier. A(n) ________ indicates a public operati
Nastasia [14]

Answer / Explanation

The question seem not to be complete. It can be found in search engines.

Kindly find the complete question below.

Question

The UML models operations by listing the operation name followed by a set of ____. A plus sign (+) in front of the operation name indicates that the operation is a public one in the UML (i.e., a public method in Java).

Answer:

To properly answer this question, let us first define what a UML is:

UML can be defined as or is simply refereed to as Unified Modelling Language. It is considered as the standard for modeling language that enables designers and developers to specify, visualize, construct and document object or programs made by them in the areas of software systems, Thus, UML makes this objects developed by computer gurus secure and robust in execution.

If we now go back to the question asked while referencing the explanation given of what a UML is, the answer to the question is

parentheses.

However, if the original question being asked is valid, the answer to it would be : sign (+) in front of the operation name

5 0
3 years ago
Read 2 more answers
Which type of drivers must always be certified in order to be installed in windows?
motikmotik
64 bit drivers must be certified in order to work. 
7 0
3 years ago
Read 2 more answers
Other questions:
  • Finally, Su uses the last slide of her presentation as a summary slide. She wants to make sure the text she types automatically
    12·2 answers
  • Automotive engine cylinder heads can be made of what?
    7·1 answer
  • What is the use of word art?
    10·1 answer
  • What is a sound wave
    7·2 answers
  • For what kind of shot is a fisheye lens most appropriate?
    8·1 answer
  • In the cis configuration, the methyl groups are placed _____.
    8·2 answers
  • 2.36 LAB: Warm up: Variables, input, and casting (1) Prompt the user to input an integer, a double, a character, and a string, s
    12·1 answer
  • Which of the following is an advantage of using variables?
    9·1 answer
  • The identification of the technology management framework contain?
    6·1 answer
  • Task 5: Create the GET_CREDIT_LIMIT procedure to obtain the full name and credit limit of the customer whose ID currently is sto
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!