Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 2: Change Calculator (20 marks) Complete the change calculator. In this question you will write an Enumeration for the various coins and notes available

Question 2: Change Calculator (20 marks)

Complete the change calculator. In this question you will write an Enumeration for the various coins and notes available in pounds sterling.

i) NotesAndCoins Enumeration

Complete the enumeration with the following constants below

You also need to create a constructor to set the properties to match the table below and getterMethods for valueInP and name. These must be called getValueInP() and getName()

image text in transcribed

ii) calcChange method (8 marks)

Complete the calcChange method it takes two arguments:

A double called price, the amount the shopping costs

A double called paid, How much money was handed over.

The method should return a TreeMap. The Tree maps keys are the collection of constants in the NotesAndCoins enumeration and the values are how many of each denomination is required to make up the correct change.

For example, if the price is 28.99 and the paid amount is 40.00 the TreeMap returned would contain:

{pound50=0, pound20=0, pound10=1, pound5=0, pound2=0, pound1=1, pence50=0, pence20=0, pence10=0, pence5=0, pence2=0, pence1=1} Constant valueInP name PENCE1 1 1p PENCE2 2 2p PENCE5 5 5p PENCE10 10 10p PENCE20 20 20p PENCE50 50 50p POUND1 100 1 POUND2 200 2 POUND5 500 5 POUND10 1000 10 POUND20 2000 20" POUND50 5000 50

For the TreeMap you will need to create an implementation of Comparator to order the keys. It is recommended you order from from largest denomination (50.00) to the smallest (1p), as this will simplify your task.

\begin{tabular}{|l|r|l|l|} \hline Constant & valuelnP & name \\ \hline PENCE1 & 1 & "1p" \\ \hline PENCE2 & 2 & "2p" \\ \hline PENCE5 & 5 & "5p" \\ \hline PENCE10 & 10 & "10p" \\ \hline PENCE20 & 20 & "20p" \\ \hline PENCE50 & 50 & "50p" \\ \hline POUND1 & 100 & "1" \\ \hline POUND2 & 200 & "2" \\ \hline POUND5 & 500 & "5" \\ \hline POUND10 & 1000 & "10" \\ \hline POUND20 & 2000 & "20" \\ \hline POUND50 & 5000 & "50" \\ \hline \end{tabular}

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

Samsung Galaxy S23 Ultra Comprehensive User Manual

Authors: Leo Scott

1st Edition

B0BVPBJK5Q, 979-8377286455

More Books

Students also viewed these Databases questions

Question

1. Explain why talent management is important.

Answered: 1 week ago

Question

8-6 Who poses the biggest security threat: insiders or outsiders?

Answered: 1 week ago