Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package a1main;
- /**
- *
- * @author Tony
- */
- public class A1main {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- double balance = 0;
- double quarterValue = .25;
- double dimeValue = .10;
- double nickelValue = .05;
- String sideUp;
- Coin quarter = new Coin();
- Coin dime = new Coin();
- Coin nickel = new Coin();
- System.out.println("Your current balance is $" + balance + ". Let's begin.");
- do {
- if (quarter.face == 0){
- sideUp = "Heads";
- balance = quarterValue + balance;
- System.out.println("The quarter landed " + sideUp + ", and " + quarterValue + " was added. The balance is now $" + balance + ".");
- } else {
- sideUp = "Tails";
- System.out.println("The quarter landed " + sideUp + ". The current balance remains at $" + balance + ".");
- }
- if (dime.face == 0){
- sideUp = "Heads";
- balance = dimeValue + balance;
- } else {
- sideUp = "Tails";
- }
- if (nickel.face == 0){
- sideUp = "Heads";
- balance = nickelValue + balance;
- } else {
- sideUp = "Tails";
- }
- } while(balance < 1);
- if (balance == 1){
- System.out.println("Your balance is $" + balance + ". Congratulations, you win!");
- } else if (balance > 1){
- System.out.println("Your balance is $" + balance + ". So sorry, but you lose!");
- }
- }
- }
- AND THEN THIS IS THE COIN CLASS
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package a1main;
- /**
- *
- * @author Tony
- */
- class Coin {
- public final int HEADS = 0;
- public static int face;
- public static void flip() {
- face = (int) (Math.random() * 2);
- }
- public String sideUp() {
- String sideUp;
- if (face == HEADS) {
- sideUp = "Heads";
- } else {
- sideUp = "Tails";
- }
- return sideUp;
- }
- public static void main(String[] args) {
- System.out.println("Outcomes:");
- int countH = 0;
- do {
- countH++;
- flip();
- System.out.println(new Coin().toString());
- } while (countH != 1);
- }
- }
Add Comment
Please, Sign In to add comment