Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am in Intro Algorithmic Design II need help completeing this i need comment through program also. INCLASS:CashRegisterDemo Complete P12.1 (uses section 12.1) -- Class

I am in Intro Algorithmic Design II need help completeing this i need comment through program also.

INCLASS:CashRegisterDemo

Complete P12.1 (uses section 12.1) -- Class name: CashRegisterDemo (also Coin, CashRegister)

You will create the CashRegisterDemo to test the CashRegister

Question

P12.1 Modify the giveChange method of the CashRegister class in the sample code for Section 12.1 so that it returns the number of coins of a particular type to return:

int giveChange(Coin coinType)

The caller needs to invoke this method for each coin type, in decreasing value.

12.1 Sample Code For Question:

public class CashRegister { public static final double NICKEL_VALUE = 0.05; public static final double DIME_VALUE = 0.1; public static final double QUARTER_VALUE = 0.25; . . . public void enterPayment(int dollars, int quarters, int dimes, int nickels, int pennies) { . . .} . . . }

There are really two concepts here: a cash register that holds coins and computes their total, and the values of individual coins. (For simplicity, we assume that the cash register only holds coins, not bills. Exercise P12.2 discusses a more general solution.) It makes sense to have a separate Coin class and have coins responsible for knowing their values.

public class Coin { . . . public Coin(double aValue, String aName) { . . . } public double getValue() { . . . } . . . }

Then the CashRegister class can be simplified:

public class CashRegister { . . . public void enterPayment(int coinCount, Coin coinType) { . . . } . . . }

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