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
Need help in python please
There is a class team ,that holds information about the team name, number of players in the team,and player's code.design the constructor function that decides the number of player in the team and intializes code for each player.create a team and display it's all data.( Implement dynamic memory allocation).
In C++ code. Create a class called publication that stores the title (char array) and price (float) of a publication. From this class derive two classes: book, which adds a page count (int) and tape, which adds a playing time in minutes (float). Each of the three classes should have a getdata() function to get its data from the user using input from the keyboard and a putdata() function todisplay the data. Write a main function that creates an array of pointers to publication. In a loop, ask the user for data about a particular type of book or tape to hold data. Put the pointer to the object in the array. When the user has finished entering data for all the books and tapes, display the resulting data for all the books and tapes entered, using a for loop and a single statement such as: pubarr[j] -> putdata(); To display the data from each object in the array.

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