Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/main/java/ICSatKCC/Bill.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package ICSatKCC;
/**
* Money Bill abstract super class.
* @author Lisa Miller
* @since 9/9/2017
*/

public abstract class Bill extends Money{
protected int serialNum;

/**
* Two parameter constructor
* CANNOT BE INSTANTIATED BY ITSELF
* @param v the bill value
* @param n the bill type name
*/
public Bill (double v, String n, int s) {
this.value = v;
this.name = n;
this.serialNum = s;
this.color = "green";
}

public int getSerialNum(){
return this.serialNum;

}

public String getColor(){
return this.color;
}

public String getName(){
return this.name + "dollar bill";

}
}
180 changes: 105 additions & 75 deletions src/main/java/ICSatKCC/Coin.java
Original file line number Diff line number Diff line change
@@ -1,82 +1,112 @@
package ICSatKCC;

import java.util.Random;
/**
* Basic Coin super class.
* Flippable Money Coin abstract super class.
* @author Lisa Miller
* @since 1/24/22
* @since 9/9/2017
*/

public class Coin {
//instance variables
/** the Coin value. */
private double value;
/** the name of the Coin type. */
private String name;
/** the image on the front of the Coin. */
private String front;
/** the image on the back. */
private String back;

/**
* Two parameter constructor.
* @param newValue the coin value
* @param newName the coin type name
*/
public Coin(double newValue, String newName, String newFront, String newBack) {
this.value = newValue;
this.name = newName;
this.front = newFront;
this.back = newBack;
}
public abstract class Coin extends Money implements Flippable, Comparable<Coin>{
//instance variables
// private int date;
// private String shape;
// //added for flippable
private int upSide;
private int downSide;

/**
* Two parameter constructor
* CANNOT BE INSTANTIATED BY ITSELF
* @param v the coin value
* @param n the coin type name
*/
public Coin (double v, String n, String c) {
this.value = v;
this.name = n;
this.color = c;
this.toss(); //randomly set upside/downSide
}

//abstract method - not implemented here
public abstract String getBack();

/*********** Rest is the same ******************/
//get methods get Value in Money now
// public double getValue() {
// return this.value;
// }
public String getName() {
return this.name;
}

//getColor method returns "Silver"
//by default
public String getColor() {
return this.color;
}


//get methods
/**
* Gets the value of this Coin.
* @return the value of the Coin.
*/
public double getValue() {
return this.value;
}

/**
* Gets the name of this Coin.
* @return the name of the Coin.
*/
public String getName() {
return this.name;
}

/**
* Gets the color of this Coin.
* Always returns Silver as the default color.
* @return the color of the Coin, Silver.
*/
public String getColor() {
return "Silver";
}

/**
* Gets the description of the front image.
* @return the front of the Coin.
*/
public String getFront() {
return this.front;
}

/**
* Gets the description of the back image.
* @return the back of the Coin.
*/
public String getBack() {
return this.back;
}

/**
* Sets the description of the back image.
* @param the back of the Coin.
*/
public void setBack(String newBack) {
this.back = newBack;
}
/**
* Switches value of upSide and downSide.
*/
@Override
public void flip() {
if (upSide == 0) {
upSide = 1;
downSide = 0;
} else {
upSide = 0;
downSide = 1;
}
}

/**
* Randomly sets upSide and corresponding downSide
*/
@Override
public void toss() {
Random r = new Random();
upSide = r.nextInt(2);
if (upSide == 0){
downSide = 1;
} else {
downSide = 0;
}
}

/**
* Returns the upSide
* @return the up facing side
*/
@Override
public int getUpSide () {
return upSide;
}

/**
* Sets the upSide
* @param i the new up facing side
*/
@Override
public void setUpSide (int i) {
upSide = i;
}

//to string method
public String toString(){
return this.value + " cents";
}

}
//compareTo method
public int compareTo(Coin c){
double diff;
int iDiff;
//have to call getValue for c because don't have access
diff = this.value - c.getValue();

iDiff = (int)(diff*100);//return integer difference in cents

return iDiff;

}
}
59 changes: 0 additions & 59 deletions src/main/java/ICSatKCC/CoinDriver.java

This file was deleted.

78 changes: 78 additions & 0 deletions src/main/java/ICSatKCC/CoinFlipper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package ICSatKCC;

/**
* Driver class for Flippable Coins.
* @author Lisa Miller
* @since 1/28/24
*/

public class CoinFlipper {
/** main method.
* @param args not used
*/
public static void main( String [] args){

//array of coins can hold all subclasses
Coin[] coinArr = new Coin[3];

coinArr[0] = new DollarCoin();
coinArr[1] = new Penny();
coinArr[2] = (Coin)doubleFlip(coinArr[0]); //call doubleFlip

for (int i = 0; i < coinArr.length; i++){
System.out.print("Coin type: " + coinArr[i].getName() + "\tValue: " + coinArr[i].getValue());
System.out.println("\tColor: " + coinArr[i].getColor() + "\tUp Side: " + coinArr[i].getUpSide());
}

//do ten coin tosses:
for (int i = 0; i < 10; i++) {
System.out.print(printUpSide(coinArr[0].getUpSide()) + " -> ");
coinArr[0].toss();
System.out.println(printUpSide(coinArr[0].getUpSide()));
}

for(int i = 0; i < coinArr.length; i++) {
System.out.println(coinArr[i]);
}



}//close main

/**
* private static method for getting upside as a string
* @param i the upSide int value
* @return the upSide String value
*/
private static String printUpSide(int i) {
if (i == 1){
return("Heads");
}else {
return("Tails");
}
}

/**
* mathod that takes in a flippable object, makes a new coin based on the side
* and returns it
* @param an object to get side
* @return a new COin object
*/
public static Flippable doubleFlip(Flippable f1){
f1.flip();
f1.flip();
int side = f1.getUpSide();
Flippable c = new Quarter();

switch(side){
case 0:
c = new Penny();
break;
case 1:
c = new Nickel();
break;
}
return c;
}//end doubleFlip

}//close class
19 changes: 9 additions & 10 deletions src/main/java/ICSatKCC/Dime.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package ICSatKCC;

/**
* Dime .10 value Coin Subclass.
* Dime Coin Subclass
* @author Lisa Miller
* @since 1/24/22
* @since 9/9/2017
*/
public class Dime extends Coin {

/**
* Constructor, needs no parameters.
* Sends default Dime values
*/
public Dime() {
super(.10, "Dime", "Franklin D. Roosevelt", "torch");
}
public Dime(){
super(.10,"dime", "silver");
}
//required by Coin abstract class
public String getBack(){
return "torch";
}
}
Loading