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;
}
}

Answers

Answer 1

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


Related Questions

what came first the chicken or the egg?

Answers

Answer:

The Egg comes first.

Explanation:

The egg is the first stage of a chicken after the mother births the egg. she must protect it until it hatches. once it hatched, a chick will come out the egg. then, the chick will start to grow into a chicken.

Answer:

The chicken

Explanation:

To birds made a BIRD egg, but unexpected a chicken came out, which then made chicken eggs

Consider the following method, which is intended to return the index of the first negative integer in a given array of integers. public int positionOfFirstNegative(int[] values) { int index = 0; while (values[index] >= 0) { index++; } return index; } What precondition is needed on the values array so that the method will work as intended?

Answers

Answer:

The answer is "The array values must contain at least one negative integer".

Explanation:

In the above-given code, a method "positionOfFirstNegative" is declared, that accepts an array "values" as a parameter, inside the method an integer variable index is declared, that use in the while loop to check array value is greater than equal to 0, if the conditional is true it will increments the index value and return its value, that's why in this question array value include at least one negative value.

flowchart is written using english language.
true or false​

Answers

the answer is true hope it helps

Answer is true I believe

Martha has a large data list and wants to sort it quickly and efficiently. Which algorithm should Martha use

Answers

Answer:

quicksort

Explanation:

There are many types of asymptotically efficient sorting algorithms that can be used but one of the more commonly used for large data lists would be quicksort. This is a sorting algorithm that focuses on choosing a value from the list and working around that value in order to sort the data piece by piece. For larger data sets this method is widely used due to its speed and efficiency which is exactly what Martha needs in this scenario.

HELP NEEDED ASAP!!!
Early mixing systems had some severe limitations. Which of the following statements best describes one of those
limitations:
1. They could not fast forward.
2. They could not edit.
3. They could not play more than one track at a time.
4. They could not play in reverse.

Answers

<8□}□{●{●{《{¤□■♡¤■▪︎gusygydfig8f6r7t8t437r7fyfu

Given main() and a base Book class, define a derived class called Encyclopedia. Within the derived Encyclopedia class, define a printInfo() method that overrides the Book class' printInfo() method by printing not only the title, author, publisher, and publication date, but also the edition and number of volumes.
Ex. If the input is:
The Hobbit J. R. R.
Tolkien
George Allen & Unwin
21 September 1937
The Illustrated Encyclopedia of the Universe
James W. Guthrie Watson-Guptill
2001
2nd
the output is:
Book Information:
Book Title: The Hobbit
Author: J. R. R. Tolkien
Publisher: George Allen & Unwin
Publication Date: 21 September 1937
Book Information:
Book Title: The Illustrated Encyclopedia of the Universe
Author: James W. Guthrie
Publisher: Watson-Guptill
Publication Date: 2001
Edition: 2nd
Number of Volumes: 1

Answers

The program relating to the encylopedia is illustrated below:

public class Encyclopedia extends Book {

  String edition;

  int numVolumes;

  public String getEdition() {

      return edition;

  }

  public void setEdition(String edition) {

      this.edition = edition;

  }

  print getNumVolumes() {

      return numVolumes;

  }

  public void setNumVolumes(int numVolumes) {

      this.numVolumes = numVolumes;

  }

  public void printInfo() {

      System.out.println("Book Information: ");

      System.out.println(" Book Title: " + super.title);

      System.out.println(" Author: " + author);

      System.out.println(" Publisher: " + publisher);

      System.out.println(" Publication Date: " + publicationDate);

      System.out.println(" Edition: " + getEdition());

      System.out.println(" Number of Volumes: " + getNumVolumes());

  }

How to illustrate the information?

After analyzing both of these classes I have created the following code that grabs and overrides the printInfo() method in order to add and print the edition and number of volumes as well.

In this case, the encylopedia was illustrated above.

Learn more about program on:

https://brainly.com/question/26642771

#SPJ1

anyone wanna review my pc pls, its my first time building one and i just want one more look over at my part picker pls. https://pcpartpicker.com/list/2m4KNP

Answers

Answer:

sorry I cannot wanna review

You should include the words "Under Construction" on your site while you are working on it True O False W This is not the answer​

Answers

Answer:

true

Explanation:

so that the idiots dont die if they walk through the site

Making __________ cache a part of the processor caused manufacturers to move from sockets to slots in the late 1990s

Answers

Answer:

The description of the discussion has been illustrated throughout the explanation segment elsewhere here.

Explanation:

Processors started to incorporate constructed L2 cache, acquired as completely separate chips from multiple vendors of Static Random access memory chip. This same processor and after that usually consists not of even single, and therefore of many other processors, that everything positioned upon its motherboard, which would then be inserted into another motherboard socket.

PLEASE ANSWER!! If my pixel has an RGB value of (R - 150, G - 0, B - 100), what is the dominant value? Why?

Answers

Red because 150 is the largest number

a 50.5 force is applied to a golf ball generating an initial acceleration of 15 m/s2 caculate the mass of the golf ball.

Answers

Answer:

Mass = 3.37 Kg

Explanation:

Given the following data;

Force = 50.5N

Acceleration = 15m/s²

To find the mass of the golf ball;

Force is given by the multiplication of mass and acceleration.

Mathematically, the formula for force is;

[tex] F = ma[/tex]

Where;

F represents force measured in Newton.m represents the mass of an object measured in kilograms.a represents acceleration measured in meter per seconds square.

Making mass (m) the subject of formula, we have;

[tex]Mass (m) = \frac{F}{a}[/tex]

Substituting into the equation;

[tex]Mass (m) = \frac{50.5}{15}[/tex]

Mass = 3.37 Kg

When measuring processor speed,a megahertz is much faster than a gigahertz.true or fals

Answers

Answer: False

Explanation:

The statement in the question is wrong. When measuring processor speed, a megahertz is slower than a gigahertz.

We should note that:

1 megahertz = 1 million cycles per second

1 gigahertz = 1 billion cycles per second.

Therefore, we can see that a gigahertz is faster than a megahertz.

Can someone please help me with 6.8 Code Practice adhesive.

Answers

Answer:

I'm looking for this one too

Answer:

import simplegui

import random

# global constants

WIDTH = 600

HEIGHT = 400

PARTICLE_RADIUS = 5

COLOR_LIST = ["Red", "Green", "Blue", "White"]

DIRECTION_LIST = [[1,0], [0, 1], [-1, 0], [0, -1]]

# definition of Particle class

class Particle:

  # initializer for particles

  def __init__(self, position, color):

      self.position = position

      self.color = color

  # method that updates position of a particle    

  def move(self, offset):

      self.position[0] += offset[0]

      self.position[1] += offset[1]

  # draw method for particles

  def draw(self, canvas):

      canvas.draw_circle(self.position, PARTICLE_RADIUS, 1, self.color, self.color)

  # string method for particles

  def __str__(self):

      return "Particle with position = " + str(self.position) + " and color = " + self.color

# draw handler

def draw(canvas):

  for p in particle_list:

      p.move(random.choice(DIRECTION_LIST))

  for p in particle_list:

      p.draw(canvas)

# create frame and register draw handler

frame = simplegui.create_frame("Particle simulator", WIDTH, HEIGHT)

frame.set_draw_handler(draw)

# create a list of particles

particle_list = []

for i in range(100):

  p = Particle([WIDTH / 2, HEIGHT / 2], random.choice(COLOR_LIST))

  particle_list.append(p)

# start frame

frame.start()

Explanation:

this worked for me, sorry if its to late. let me know if anything is wrong

A label control may be added to a form by double-clicking on the Label control icon in the ________ window.

Answers

Answer:

ToolBox.

Explanation:

A label control may be added to a form by double-clicking on the Label control icon in the ToolBox window.

Jonathan wants to create an online journal. He will use it to share with his friends all the cool places he visits while in Europe. Which social networking tool should Jonathan use to create a journal while on his trip?
a: email
b: a blog
c: a wiki
d: a forum

Answers

Answer:

a blog

Explanation:

a forum is for questions, a wiki doesn't make sense in this situation and email wouldn't be used for this either so it should be a blog

The correct answer is b I hope this helps luv

Will there be another season in Star vs the forces of evil?

Answers

The world may never kno

Answer: no the creator anounced that there will not be a fifth season

Explanation:

Describe how sharing and collaborating a spreadsheet can help the author of the spreadsheet.

hurry and answer you will get a brainly this is for a school assignment

Answers

It can help ensure that everything is correct. Having an extra set of eyes can never hurt :)

The author can save an Excel workbook as a shared workbook if they want multiple users to work in it at once. Then, users can enter data, add rows and columns, modify calculations, and alter formatting.

What is spreadsheet?

Data that has been arranged into rows and columns can be stored, displayed, and edited using spreadsheet software. The spreadsheet is one of the most used tools for personal computers. A spreadsheet is typically used to record numerical data and brief text strings.

A spreadsheet is a computer program used for tabular data organization, calculations, and storage. Spreadsheets were developed as electronic replacements for the old-fashioned paper accounting spreadsheets. The software runs on the data entered into a table's cells.

Thus, The author can save an Excel workbook as a shared workbook.

For more information about spreadsheet, click here:

https://brainly.com/question/8284022

#SPJ2

Which HTML tag is used to add an ordered list to a web page?

Answers

Answer:

<ol> Defines an ordered list

Answer:

<ol>

Explanation:

Analytical Engine was designed in​

Answers

Answer:

1838

Explanation:

Analytical Engine was designed in 1838. The designer is Charles Babbage, who was an English mathematician and widely known for his innovation in the engineering world. He is often considered to be the father of computers.

Following his inability to finish the creation of Difference Engine, Charles Babbage would later when ahead to conceived the Analytical Machine in 1834

He eventually finished the design of an Analytical Machine by 1838.

Answer:

Charles Babbage

Explanation:

Just did test

Write a program that will take the three test grades as input and tell what her average test grade is?

Answers

Answer:

Explanation:

The following code is written in Python programming language and as requested takes three int/float variables. Then it sums up the three grades and places the result into a variable called sum. Then it creates a variable called average and divides the sum by three to get the actual average. Finally, it prints the value of the average variable to the user.

def average(gradeOne, gradeTwo, gradeThree):

   sum = gradeOne + gradeTwo + gradeThree

   average = sum / 3

   print(average)

Which of the following describes the purpose of a goal? Choose all that apply.

It provides a marker by which to measure performance.

It doesn’t specify a direction.

It identifies guidelines of behavior.

It documents a commitment for action.

Answers

the first and last option

The definition of network is:
A. the world wide web
B. the internet
C. a special computer that is used to store files and programs
D. two or more computers linked by cable, telephone lines or other communication devices

Answers

[tex]\text{Hello there!}[/tex]

Networks were originally used as a government weapon 61 years ago to communicate information such as data and research. However, individual networks were eventually discontinued by the government and made open to the public to use for things such as PAN, LAN, MAN, WAN, SAN, and so on.

Our internet today is capable of communicating with bilions of computers. This is possible due to your modem using radio wave-like speeds to connect to your ISP. Your ISP then connects to a larger network, which is connecting to thousands of other networks. You see, the internet is just a large network of networks that are connected through very fast radiowaves. However, it is not just a single network being used anymore; it's thousands of them. The term, "internet" was used to describe this large selection of networks. In short, B would be incorrect.

The worldwide web is a protocol used by the internet to connect to select websites favourably from whoever's using it. This obviously would not define the network, as this is something that's used by it. Furthermore, A would not be correct.

As described already, the network was a selection of computers used to communicate information to each other. C would not be correct as it states that there is only one computer being used.

[tex]\fbox{Therefore, D would be the correct answer.}[/tex]

[tex]\rule{300}{1.5}[/tex]

Fix the code so that the list of elements that end with "e".
// //Q2: Create a list of elements that end with the letter "e"
// //Hint: The last index item is always length-1
var nameElementE = [];
for (var i = 0; i < nameElement.length; i++) {
if (nameElement[i].substring(0,1)=="E"){
appendItem(nameElementE, nameElement[i]);
}
}
console.log(nameElementE);

// //Console.log out your final list

Answers

Answer:

It's

B

Explanation:

You can have more that one image open at a time in GIMP. True or false

Answers

Answer:

true....... you can superimpose so that's more than 1 image

What is a conditional Statement that causes the program to change its course​

Answers

Answer:

In computer science, conditional statements, conditional expressions and conditional constructs are features of a programming language, which perform different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false.

Explanation:

Why to use different passwords for social media accounts? Use in your own words.

Answers

Answer:

well for one reason some people could guess your password and look at your stuff and i wouldn't want to be lame and have the same password it's fun making your own password.

Explanation:

Answer:

For protection

Explanation:

So a person cant hack u...

If a person knows one of ur acc pswrd, and they know u have a diff one, they can try to use the same pass from the first one to be able to log into ur other social media account. So it's best to use different ones to prevent hacking

Hope this helped!

Sry i took long, i wrote something but it kept sayin that it included sum inappropriate

Digital cameras have electronic sensors that record information to create pictures. What acronym refers to the sensitivity
of the electronic sensor?
DPI
ISO
LED
DMD

Answers

Answer:

ISO

Explanation:

A message can be...........
differently by different people.​

Answers

Answer:

Hope this help, did some research :D

Explanation:

" Audiences play a role in interpreting media messages because each audience member brings to the message a unique set of life experiences. Differences in age, gender, education and cultural upbringing will generate unique interpretations. "

Your Task
Think of an area that interests you: sports, arts, entertainment, international relief efforts, government, careers, or the weather.

Think of a question you would like to answer. Is it better to wait until the battery is low before you recharge your smartphone? How does a streaming service like Netflix or Hulu decide which shows to offer?

Look for a website where someone already collected a large quantity of data to answer that question. While commercial big data sets may have tens of thousands of values, for this project, look for a data set with at least 100 values.

You are not going to write a program to analyze these data because you have not yet covered how to read data files. You can describe how the researcher(s) who collected the data used them to answer your question.

Answers

To answer a question through commercial big data sets related to an area of ​​interest, such as the question "How does a streaming service decide which programs to offer" It is essential to understand the definition of big data and what such data is used for.

What is big data?

It corresponds to a tool for processing a large volume of data with strategic objectives for collecting, organizing and interpreting the data obtained, to obtain insights and aid in decision making.

Therefore, for businesses, big data is a strategic tool to help manage more focused and aligned with organizational objectives, being used by the marketing department to segment the market and generate value and positioning.

Find out more about big data here:

https://brainly.com/question/19049345

An organization is developing an authentication service for use at the entry and exit ports of country borders. The service will use data feeds obtained from passport systems, passenger manifests, and high-definition video feeds from CCTV systems that are located at the ports. The service will incorporate machine- learning techniques to eliminate biometric enrollment processes while still allowing authorities to identify passengers with increasing accuracy over time. The more frequently passengers travel, the more accurately the service will identify them. Which of the following biometrics will MOST likely be used, without the need for enrollment?

a. Voice
b. Gait
c. Vein
d. Facial
e. Retina
f. Fingerprint

Answers

Answer:

The correct answer is D. Facial biometrics.

Explanation:

A face recognition system is a computer program for identifying people from photos or videos. Face recognition is performed according to the geometric characteristics of the face and is compared with a database. It is also possible to determine the sex and estimate the age of persons. The main advantage of these systems is that the people who are going to be recognized by it do not need to enroll or provide their data on some previous basis, but, on the contrary, this system can extract images even without the consent of those investigated .

Other Questions
ANSWER QUICKLY!!!!!! Q: How does the rest of the class react when they see Scout getting whipped?a: They fall silent and concentrate on their workb: They rally around Scout and proclaim the injustice of the whippingc: They vow to report Miss Caroline to the school boardd: They laugh Q: What does Miss Caroline offer Walter?a: New clothes to replace the ragged onesb: A notebook to practice his letterc: A quarter for lunchd: Picture books to practice reading 4. Scout compares being able to read to being able to ____a: Seeb: Hearc: Breathed: Taste 5. Walter has hookworms in his face because he does not ___a: Use bug repellentb: Wear Shoesc: Wear a coatd: Use soapPS: Need to tell me the answers to each one, a,b,c or d. ? Find the value of the parallelogram. The value of x is _? What is the name for the largest city in India? Located on the western border, this city once known as Bombay, experienced horrific terrorists attacks in 2008. Which statement is the correct interpretation of the inequality 4 > 5? On a number line, 4 is located to the left of 0 and 5 is located to the right of 0. On a number line, 4 is located to the right of 0 and 5 is located to the left of 0. On a number line, 4 is located to the right of 5. On a number line, 4 is located to the left of 5. I will give brainlest to the right answer! Please I need help I will mark you brainliest What is the solution to this inequality?6x 5 > -29 X > -4o x > 4o x < -4o x < 4 how were people prosecuted for religion during WWII? explain your answer. Figure ABCD is a parallelogram.Parallelogram A B C D is shown. Angle B is (2 n + 15) degrees and angle D is (3 n minus 5) degrees.What are the measures of angles B and D?B = 55; D = 55B = 55; D = 125B = 97; D = 97B = 83; D = 97 What is true of sand dunes? A) they are built by waves B) they are made by rivers cutting through land C) they are built by water carrying sediment away D) they are built by deposition of sand by wing. what is 4/5 in simplest form??? 40 POINTS IM BEING TIMEDLayla and Cayden are racing at the playground. The playground is rectangular and has a length of 82 meters and a width of 50 meters. Cayden will run around the entire perimeter of the rectangular playground while Layla will run diagonally across the playground twice. (She will end where she started). Cayden runs 3 meters per second and Layla runs 2 meters per second.A: Who will finish first?B: How much faster will that person's finish time be?HELP PLEASEEEEEEEEEEEEEEEEEEEEEEEFOR THE FIFTH TIME I ASKED THIS QUESTION ;-; On a recent quiz, the class mean was 69 with a standard deviation of 4.8. Calculate the z score for a person who received score of 74. z score: A quadrilateral has vertices A(3,0),B(-4,4),C(-7,0) and D(-3,-5).Find the midpoints coordinates of each sides Describe the German Blitzkrieg. Write a balanced equation for the complete oxidation reaction that occurs when glucose (C6H12O6) reacts with oxygen. Use the smallest possible integer coefficients. HELP HELP HELP I WILL GIVE BRAINLEST An effective summary is characterized by an explanation of the reader's personal opinion repetition of words from the original text inclusion of only the most important details a listing of the facts from the original text 100 POINTSWhat is Markham's attitude in his poem "The Man with the Garden Tool" toward those in power?Here's the whole poem:The Man with the Garden ToolWRITTEN AFTER SEEING MILLET'S WORLD-FAMOUS PAINTINGGod made man in His own image;in the image of God made He him. --Genesis.Bowed by the weight of centuries he leansUpon his garden tool and gazes on the ground,The emptiness of ages in his face,And on his back the burden of the world.Who made him dead to rapture and despair,A thing that grieves not and that never hopes,Stolid and stunned, a brother to the ox?Who loosened and let down this brutal jaw?Whose was the hand that slanted back this brow?Whose breath blew out the light within this brain?Is this the thing the Lord God made and gaveTo have dominion over sea and land;To trace the stars and search the heavens for power;To feel the passion of eternity?Is this the Dream He dreamed who shaped the sunsAnd pillared the blue firmament with light?Down all the stretch of the bad place to its last gulfThere is no shape more terrible than thisMore tongued with cries against the world's blind greedMore filled with signs and portents for the soulMore fraught with menace to the universe.What gulfs between him and the seraphim!Worker of the wheel of labor, what to himAre Plato and the swing of Pleiades?What the long reaches of the peaks of song,The rift of dawn, the reddening of the rose?Through this dread shape the suffering ages look;Time's tragedy is in that aching stoop;Through this dread shape humanity betrayed,Plundered, profaned, and disinherited,Cries protest to the Powers that made the world,A protest that is also prophecy.O masters, lords and rulers in all lands,Is this the handiwork you give to God,This monstrous thing distorted and soul-quenched?How will you ever straighten up this shape;Touch it again with immortality;Give back the upward looking and the light;Rebuild in it the music and the dream;Make right the immemorial infamies,Perfidious wrongs, immedicable woes?O masters, lords and rulers in all lands,How will the future reckon with this Man?How answer his brute question in that hourWhen whirlwinds of rebellion shake the world?How will it be with kingdoms and with kingsWith those who shaped him to the thing he isWhen this speechless Terror shall reply to God,After the silence of the centuries?Edwin Markham How did the Enlightenment's theories ofrgovernment view the role of government