Skip to main content
ICT
Lesson A3 - Primitive Data Types
 
Main   Previous
 

LAB ASSIGNMENT A3.2 page 14 of 14

Coins

Background:

Some cash register systems use change machines that automatically dispense coins. This lab will investigate the problem solving and programming behind such machinery. You always want to use the fewest coins possible. You should use integer mathematics to solve this problem.

Provide the number of cents through the constructor. Write a method that calculates the number of each type of coin.

Examples:
     
 35 cents =>
 Quarter(s)   1
 Dime(s)      1
 Nickel(s)    0
 Penny(s)     0
 
 41 cents =>
 Quarter(s)   1
 Dime(s)      1
 Nickel(s)    1
 Penny(s)     1

Assignment:

  1. Follow the same format that was used in Lab Assignment A3.1 (Easter), using a driver and a class called Coins.

  2. Run the samples from above to check your work.

  3. Run the following three samples and copy the sample runs into your class file, print out the code for the class and hand in.

    94 cents
    59 cents
    19 cents

  4. Do not worry about singular versus plural endings, i.e. quarter/quarters.

 

Main   Previous
Contact
 © ICT 2006, All Rights Reserved.