Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. import java.util.*;
  2. public class Assignment1_Sbrocco {
  3. public static void main(String[] args){
  4. Scanner input = new Scanner (System.in);
  5.  
  6.  
  7. while(true) {
  8.  
  9. System.out.println("Which part would you like to go to (1-3): ");
  10. int part = input.nextInt();
  11.  
  12.  
  13. if(part == 1){
  14.  
  15.  
  16.  
  17. System.out.println("Part 1: Double or nothing");
  18.  
  19. int counter = 0;
  20.  
  21. System.out.println("How much is your total debt?");
  22. float totalDebt = input.nextFloat();
  23.  
  24. System.out.println("How much do you have on hand now?");
  25. float inHand = input.nextFloat();
  26.  
  27. /* This while statement multiplies the inHand value by 2
  28. and repeats until inHand value is greater than
  29. the totalDebt value
  30. */
  31.  
  32. while (inHand < totalDebt){
  33.  
  34. inHand = inHand * 2;
  35. System.out.println("After bet(s), total in hand is " + inHand);
  36. counter++;
  37.  
  38. }
  39.  
  40. System.out.println("Total number of bets: " + counter);
  41. System.out.println("Total amount in hand: " + inHand);
  42.  
  43. System.out.println("Do you want to continue? Y/N");
  44. char answer = input.next().charAt(0);
  45.  
  46. if (answer == 'Y' || 'y'){
  47.  
  48. continue;
  49.  
  50. } else {
  51.  
  52. System.out.println("Goodbye!");
  53. break;
  54.  
  55. }
  56.  
  57. }
  58.  
  59.  
  60. else if(part == 2){
  61.  
  62. System.out.println("Part 2: Pattern");
  63.  
  64. int n;
  65. int m;
  66.  
  67. System.out.println("Enter the value for N:");
  68. n = input.nextInt();
  69.  
  70. System.out.println("Enter the value for M");
  71. m = input.nextInt();
  72.  
  73. /* This for loop takes the input and repeates the pattern based
  74. on what variables n and m equal
  75. */
  76. for (int i = 0; i < n; i++) {
  77. for (int j = 0; j < m; j++) {
  78. if (i % 2 != 0) {
  79. System.out.print(".*");
  80. } else {
  81. System.out.print("*.");
  82. }
  83.  
  84. }
  85. System.out.println();
  86.  
  87. }
  88.  
  89. }
  90.  
  91.  
  92. else if(part == 3){
  93.  
  94. System.out.println("Part 3: baby Simulator");
  95.  
  96. int boy = 0;
  97. int girl = 0;
  98.  
  99. /* This while statement sets the girl and boy variables to equal
  100. a random number then is put through an if staement determining if
  101. the number is less than .5 and adds either a girl or boy
  102. */
  103.  
  104. while (boy == 0 || girl == 0) {
  105.  
  106. double birth = (Math.random());
  107. if (birth < .5) {
  108. boy++;
  109. } else {
  110. girl++;
  111. }
  112. }
  113.  
  114. System.out.println("Congragulations! You have " + boy + " boy(s) and " + girl + " girl(s).");
  115.  
  116. }else{
  117.  
  118. System.out.println("Wrong");
  119.  
  120.  
  121. }
  122.  
  123. }
  124.  
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement