Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ISTE-120 Lab 03: Calculators Exercise 1: The Calculator Class The first part of this lab is to write a class that simulates a calculator. Our

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

ISTE-120 Lab 03: Calculators Exercise 1: The Calculator Class The first part of this lab is to write a class that simulates a calculator. Our calculator will be pretty simple. It will do addition, subtraction, multiplication, and division Calculators work with a single storage cell, called the accumulator, that keeps track of the current value in the calculator. This accumulator will be (the only) attribute of this class. It will be private (of course) and its type will be double. A double value in Java is one which stores a number (as opposed, for instance, a String). Further, a double can store a number with a fractional component (i.e. with digits to the right of the decimal point) Our only constructor will be the default constructor (the one without any parameters inside the parentheses). It will initialize the accumulator to zero The methods will be An accessor (getAccumulator) A method to add a number to the accumulator A method to subtract a number from the accumulator A method to multiply the accumulator by a number A method to divide a number into the accumulator . . . A method to clear the calculator (i.e. set the accumulator to zero) A toString method that returns the accumulator as a String . The division method will refuse to divide 0 into the accumulator. If the user tries to do this, it will print the error message It will NOT change the accumulator in this case Consider this simple test class to understand how the calculator can be made to work. public class TestCalcl [ ATTEMPT TO DIVIDE BY ZERO - IGNORE public static void main (String[] args) Calculator myCalc = new Calculator(); double myWeight = 145; // instead of 145 use your weight in pounds myCalc.add (myWeight) myCalc.multiply (0.453952) System.out .print 1n("Hy weight is " + myWeight + "lb = " + /I convert weight to KG myCalc + "kg")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Explain the difference between set point and basal metabolic rate.

Answered: 1 week ago