I have class project and was asked to design 2 classes. 1 : Class Coin designated by coin type (PENNY, NICKEL, DIME, QUARTER OR DOLLAR)
2: Create Class CoinChanger To allow coin changing : say if one were to buy something to return the correct change. I have the following so far. Please Help!!!
This is my class COIN :
public enum Coin
{
penny(1, "penny"), nickel(5,"nicke l"), dime(10,"dime") , quarter(25,"qua rter");
//Constructor
Coin(int value, String name) { this.value = value;
this.name = name;}
public int value() { return value; }
public String CoinName() { return name; }
private final int value;
private final String name;}// end of class
My Class CoinChanger is as follow:
I would like to know how to keep track of my instance using type coin in the coinChanger constructor. I am contemplating this:
public class CoinChanger
{
/**
*
*/
private double my_balance;// keep track of much money I have
private int purchase; // the the total amount of user purchase
private int payment; // the amount payed for the purchase
private Coin my_dollars; // total amnt of $
private Coin my_dimes;// total dimes
private Coin my_quarters;// total quarters
private Coin my_nickels;
private Coin my_pennies;
final static int a =4;// to determine the $ value using quarters
// Pass object of type coin or primitive?
CoinChanger(Str ing aName)
{
// keeping track of pennies how???
my_pennies = Coin.penny; // the value of my_pennies is PENNY(1)
//then add penny to list???
my_nickels = Coin.valueOf("n ickel");
my_dimes = Coin.valueOf("d ime");
my_quarters = Coin.valueOf("q uarter");
// How to detirmine the value of a $????/
my_dollars= Coin.valueOf("q uarter");
}
2: Create Class CoinChanger To allow coin changing : say if one were to buy something to return the correct change. I have the following so far. Please Help!!!
This is my class COIN :
public enum Coin
{
penny(1, "penny"), nickel(5,"nicke l"), dime(10,"dime") , quarter(25,"qua rter");
//Constructor
Coin(int value, String name) { this.value = value;
this.name = name;}
public int value() { return value; }
public String CoinName() { return name; }
private final int value;
private final String name;}// end of class
My Class CoinChanger is as follow:
I would like to know how to keep track of my instance using type coin in the coinChanger constructor. I am contemplating this:
public class CoinChanger
{
/**
*
*/
private double my_balance;// keep track of much money I have
private int purchase; // the the total amount of user purchase
private int payment; // the amount payed for the purchase
private Coin my_dollars; // total amnt of $
private Coin my_dimes;// total dimes
private Coin my_quarters;// total quarters
private Coin my_nickels;
private Coin my_pennies;
final static int a =4;// to determine the $ value using quarters
// Pass object of type coin or primitive?
CoinChanger(Str ing aName)
{
// keeping track of pennies how???
my_pennies = Coin.penny; // the value of my_pennies is PENNY(1)
//then add penny to list???
my_nickels = Coin.valueOf("n ickel");
my_dimes = Coin.valueOf("d ime");
my_quarters = Coin.valueOf("q uarter");
// How to detirmine the value of a $????/
my_dollars= Coin.valueOf("q uarter");
}
Comment