Java: An Introduction to Problem Solving and Programming (7th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 9, Problem 2PP

Write a program that uses the class calculator in Listing 9.12 to create a more powerful calculator. This calculator will allow you to save one result in memory and call the result back. The commands the calculator takes are

  • e for end
  • c for Clear; sets result to zero
  • m for save in memory; sets memory equal to result
  • r for recall memory; displays the value of memory but does not change result

You should define a derived class of the class calculator that has one more instance variable for the memory, a new main method that runs the improved calculator, a redefinition of the method hanndleUnknownOpException, and anything else new or redefined that you need. A sample interaction with the user is shown next. Your program need not produce identical output, but it should be similar and just as clear or even clearer.

Calculator on: result = 0.0

+ 4

result + 4.0 = 4.0

updated result =4.0

/ 2

result / 2.0 = 2.0

updated result =2.0

m

result saved in memory

c

result = 0.0

+ 99

result + 99.0 = 99.0

updated result = 99.0

/ 3

result / 3.0 = 33.0

updated result =33.0

r

recalled memory value = 2.0

result =33.0

+ 2

result: + 2.0 = 35.0

updated result = 35.0

e

End of program

Blurred answer
Students have asked these similar questions
Reuse your Car class . In a main, build an object of that class, and print out the object using System.out.println(). Notice that this simply reports the memory address of the object in question, and we’d like to do something more useful. To replace (or override) the toString (or equals) function. Now, build a toString function that prints out the make, model, and odometer reading for a vehicle object. public class Car {    //instance variables    private int odometer;    private String make;    private String model;        //overloading    //constructors    public Car(int odometer,String make, String model) {        this.odometer = odometer;        this.make = make;        this.model = model;    }    public Car(String make, String model) {        this.make = make;        this.model = model;    }        public Car(String make) {        this.make = make;    }        /*     *getter & setter methods     */    public int getOdometer() {        return odometer;    }     public void…
You are required to build a class ArithematicProblem that represent a binaryarithematic problem such as addition, subtraction, multiplication and division.The ArithematicProblem class is a super class which is there to provide the mostgeneric version of the ArithematicProblem concept. This class has followinginstance variables1. Operator1 (double)2. Operator2 (double)3. Answer(double)4. Error(boolean)The value of Operator1 and Operator2 will be initialized through parameters in theconstructor while the value of answer is Double.POSITIVE_INFINITY and error is falseby default.Provide getters for all but setters for only operand1 and operand2Provide the toString method so that the string representation of each operationthe standard representation in mathematics i.e. if its an addition problem then itshould be printed as 2 + 3 = 5 and so on.Provide a method double solve() in this class. This method performs the arithematicoperation on the operands, calculates answer, sets the value of…
Modify the above code to use the alternative method for multithreading (i.e., implementing the Runnable interface). Name your main class RunnableHelloBye and your subsidiary classes Hello and Goodbye respectively. The fi rst should display the message ‘Hello!’ ten times (with a random delay of 0–2 s between consecutive displays), while the second should do the same with the message ‘Goodbye!’. Note that it will NOT be the main class that implements the Runnable interface, but each of the two subsidiary classes.

Chapter 9 Solutions

Java: An Introduction to Problem Solving and Programming (7th Edition)

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
9.1: What is an Array? - Processing Tutorial; Author: The Coding Train;https://www.youtube.com/watch?v=NptnmWvkbTw;License: Standard Youtube License