Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 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. System.out.println(" ");
  43.  
  44. if(part == 2){
  45.  
  46. System.out.println("Part 2: Pattern");
  47.  
  48. int n;
  49. int m;
  50.  
  51. System.out.println("Enter the value for N:");
  52. n = input.nextInt();
  53.  
  54. System.out.println("Enter the value for M");
  55. m = input.nextInt();
  56.  
  57. /* This for loop takes the input and repeates the pattern based
  58. on what variables n and m equal
  59. */
  60. for (int i = 0; i < n; i++) {
  61. for (int j = 0; j < m; j++) {
  62. if (i % 2 != 0) {
  63. System.out.print(".*");
  64. } else {
  65. System.out.print("*.");
  66. }
  67.  
  68. }
  69. System.out.println();
  70.  
  71. }
  72.  
  73. }
  74.  
  75.  
  76. if(part == 3){
  77.  
  78. System.out.println("Part 3: baby Simulator");
  79.  
  80. int boy = 0;
  81. int girl = 0;
  82.  
  83. /* This while statement sets the girl and boy variables to equal
  84. a random number then is put through an if staement determining if
  85. the number is less than .5 and adds either a girl or boy
  86. */
  87.  
  88. while (boy == 0 || girl == 0) {
  89.  
  90. double birth = (Math.random());
  91. if (birth < .5) {
  92. boy++;
  93. } else {
  94. girl++;
  95. }
  96. }
  97.  
  98. System.out.println("Congragulations! You have " + boy + " boy(s) and " + girl + " girl(s).");
  99.  
  100. }else{
  101.  
  102. System.out.println("Wrong");
  103.  
  104.  
  105. }
  106.  
  107. }
  108.  
  109. System.out.println("Do you want to continue? Y/N");
  110. char answer = input.next().charAt(0);
  111.  
  112.  
  113. if (answer == 'Y'){
  114.  
  115. continue;
  116.  
  117. } else {
  118.  
  119. System.out.println("Goodbye!");
  120. break;
  121.  
  122. }
  123.  
  124. }
  125.  
  126.  
  127. }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement