
The First Programming Assignment (1) (Copy and paste when necessary)
ChangeMaker.java
/**
* File: ChangeMaker.java
*
* @ Name
*
* I affirm that this program is entirely my own work and
* none of it is the work of any other person.
*/
import java.text.NumberFormat; // to format o/p as currency
/**
* Computes change due - using the minimum coinage possible - when
* the user enters the amount of a purchase and the amount tendered
*/
public class ChangeMaker
{
// instance var's
private double amountDue ; // total cost of purchases
private double amountTendered ; // amount paid
private int dollarsDue ; // number of dollar coins due in change
private int quartersDue ; // number of quarters due
private int dimesDue ; // number of dimes due
private int nickelsDue ; // number of nickels due
private int penniesDue ; // number of pennies due
private NumberFormat formatter = NumberFormat.getCurrencyInstance() ;
/**
* Constructs a ChangeMaker object
* @param totalDue the amount of the purchase
* @param amountReceived the amount tendered (paid)
*/
public ChangeMaker(double totalDue, double amountReceived)
{
// set instance variables to parameters passed
amountDue = totalDue ;
amountTendered = amountReceived ;
// other instance var's automatically initialized to 0