Guest User

Untitled

a guest
Oct 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package a1main;
  6.  
  7. /**
  8. *
  9. * @author Tony
  10. */
  11. public class A1main {
  12.  
  13. /**
  14. * @param args the command line arguments
  15. */
  16.  
  17.  
  18. public static void main(String[] args) {
  19. // TODO code application logic here
  20. double balance = 0;
  21. double quarterValue = .25;
  22. double dimeValue = .10;
  23. double nickelValue = .05;
  24.  
  25. String sideUp;
  26.  
  27. Coin quarter = new Coin();
  28. Coin dime = new Coin();
  29. Coin nickel = new Coin();
  30.  
  31. System.out.println("Your current balance is $" + balance + ". Let's begin.");
  32.  
  33. do {
  34.  
  35. if (quarter.face == 0){
  36. sideUp = "Heads";
  37. balance = quarterValue + balance;
  38. System.out.println("The quarter landed " + sideUp + ", and " + quarterValue + " was added. The balance is now $" + balance + ".");
  39. } else {
  40. sideUp = "Tails";
  41. System.out.println("The quarter landed " + sideUp + ". The current balance remains at $" + balance + ".");
  42. }
  43.  
  44. if (dime.face == 0){
  45. sideUp = "Heads";
  46. balance = dimeValue + balance;
  47. } else {
  48. sideUp = "Tails";
  49. }
  50.  
  51. if (nickel.face == 0){
  52. sideUp = "Heads";
  53. balance = nickelValue + balance;
  54. } else {
  55. sideUp = "Tails";
  56. }
  57. } while(balance < 1);
  58.  
  59. if (balance == 1){
  60. System.out.println("Your balance is $" + balance + ". Congratulations, you win!");
  61. } else if (balance > 1){
  62. System.out.println("Your balance is $" + balance + ". So sorry, but you lose!");
  63. }
  64. }
  65.  
  66. }
  67.  
  68. AND THEN THIS IS THE COIN CLASS
  69.  
  70. /*
  71. * To change this template, choose Tools | Templates
  72. * and open the template in the editor.
  73. */
  74. package a1main;
  75.  
  76. /**
  77. *
  78. * @author Tony
  79. */
  80. class Coin {
  81. public final int HEADS = 0;
  82.  
  83. public static int face;
  84.  
  85. public static void flip() {
  86. face = (int) (Math.random() * 2);
  87. }
  88.  
  89. public String sideUp() {
  90. String sideUp;
  91. if (face == HEADS) {
  92. sideUp = "Heads";
  93. } else {
  94. sideUp = "Tails";
  95. }
  96. return sideUp;
  97. }
  98.  
  99. public static void main(String[] args) {
  100. System.out.println("Outcomes:");
  101. int countH = 0;
  102. do {
  103. countH++;
  104. flip();
  105. System.out.println(new Coin().toString());
  106. } while (countH != 1);
  107. }
  108. }
Add Comment
Please, Sign In to add comment