Skip to main content
ICT
Lesson A5 - Designing and Using Classes
 
Main Previous Next
Title Page >  
Summary >  
Lesson A1 >  
Lesson A2 >  
Lesson A3 >  
Lesson A4 >  
Lesson A5 >  
Lesson A6 >  
Lesson A7 >  
Lesson A8 >  
Lesson A9 >  
Lesson A10 >  
Lesson A11 >  
Lesson A12 >  
Lesson A13 >  
Lesson A14 >  
Lesson A15 >  
Lesson A16 >  
Lesson A17 >  
Lesson A18 >  
Lesson A19 >  
Lesson A20 >  
Lesson A21 >  
Lesson A22 >  
Lesson AB23 >  
Lesson AB24 >  
Lesson AB25 >  
Lesson AB26 >  
Lesson AB27 >  
Lesson AB28 >  
Lesson AB29 >  
Lesson AB30 >  
Lesson AB31 >  
Lesson AB32 >  
Lesson AB33 >  
Vocabulary >  
 

LAB ASSIGNMENT A5.1 page 10 of 11

PiggyBank

Assignment:

  1. Create your own PiggyBank class. This class will be used to create PiggyBank objects; therefore, everyone can have their own piggy bank! When your personal bank is created (instantiated), it may be stuffed with a certain number of pennies, nickels, dimes, and quarters. You will be able to access the number of each type of coin deposited into the bank as well as the bank’s total dollar value. You will also need to create methods that will allow the piggy bank to receive coins and update the appropriate values.

Here are some thoughts about what your class needs:

  • An instance variable for each of the following coins: pennies, nickels, dimes and quarters.

  • Constructors. There should be a default constructor that can create a brand new piggy bank without anything in it as well as a constructor that can accept initial values of each coin denomination. Would there be any other constructors that could come in handy?

  • Getter methods for returning the number of each type of coin currently in the bank.

  • A method or methods that will receive more coins and add them to the total. Think about the easiest way for your client to input the values. Would it be easiest to have one method that inputs all the values at once? What if the client only has a bunch of nickels? Or nickels and quarters? Keep these thoughts in mind when designing your methods.

  • A method to calculate the total value of the coins currently in the bank. Should this method print the value directly, or should it simply return the value and let the client deal with the data?

 

Main Previous Next
Contact
 © ICT 2006, All Rights Reserved.