/** * This class will mimic a coin. * * @author Mr. Merlis * @version 12/16/2008 */ public class Coin { // instance variables - replace the example below with your own private String myName; private int myValue; /** * Default constructor creates a penny */ public Coin() { // initialise instance variables myName = "penny"; myValue = 1; }//=============================== /** * Takes a value and determines the coin name */ public Coin(int value) { // initialise instance variables myValue = value; if(myValue == 1) myName = "penny"; else if(myValue == 5) myName = "nickel"; else if(myValue == 10) myName = "dime"; else if(myValue == 25) myName = "quarter"; else if(myValue == 50) myName = "half-dollar"; else myName = "not a coin!"; }//=============================== /** * Takes the name of the coin and determines its value */ public Coin(String name) { // initialise instance variables myName = name; if(myName.equals("penny")) myValue = 1; else if(myName.equals("nickel")) myValue = 5; else if(myName.equals("dime")) myValue = 10; else if(myName.equals("quarter")) myValue = 25; else if(myName.equals("half-dollar")) myValue = 50; else myValue = 0; }//=============================== /** * An example of a method - replace this comment with your own * * @param y a sample parameter for a method * @return the sum of x and y */ public int sampleMethod(int y) { // put your code here return 1; } }