10
answers
1
watching
307
views

IN JAVA

Write a class called PocketChange that models a handful of change you might find in your pocket. The class has the following specifications:
Instance Variables - all instance variables are private


o int toonies - the number of toonies in the user's pocket o int
loonies - the number of loonies in the user's pocket o int
quarters - the number of quarters in the user's pocket o int
dimes - the number of dimes in the user's pocket o int nickels -
the number of nickels in the user's pocket o int pennies - the
number of pennies in the user's pocket Methods:

o PocketChange() - default constructor assigns 0 as a default value to all instance variables.

o PocketChange(toonies, loonies, quarters, dimes, nickels, pennies) - sets the values of all the instance variables to the programmer-specified parameter values.

o Accessor and mutator methods for each instance variable - all coin values must be 0 or positive values. Exceptions should be thrown if an attempt is made to set an instance variable to a negative value.

o calcAmount() - This method calculates and returns the total amount of money in the user's pocket, based on the values in each of the instance variables.

o toString() - returns a String with the following format:

o Toonies: t o Loonies: L o Quarters: q o Dimes: d

o Nickels: n Pennies: p where t, L, q, d, n, and p are the number of toonies, loonies, quarters, dimes, nickels and pennies. 

For unlimited access to Homework Help, a Homework+ subscription is required.

Unlock all answers

Get 1 free homework help answer.
Already have an account? Log in
Already have an account? Log in
Already have an account? Log in
Avatar image
Read by 1 person
Already have an account? Log in
Avatar image
Read by 1 person
Already have an account? Log in
Avatar image
Read by 1 person
Already have an account? Log in
Avatar image
Read by 1 person
Already have an account? Log in
Avatar image
Read by 2 people
Already have an account? Log in
Avatar image
Read by 3 people
Already have an account? Log in
Avatar image
Read by 4 people
Already have an account? Log in

Related questions

Related Documents

Weekly leaderboard

Start filling in the gaps now
Log in