Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Assignment1_Sbrocco {
- public static void main(String[] args){
- Scanner input = new Scanner (System.in);
- while(true) {
- System.out.println("Which part would you like to go to (1-3): ");
- int part = input.nextInt();
- if(part == 1){
- System.out.println("Part 1: Double or nothing");
- int counter = 0;
- System.out.println("How much is your total debt?");
- float totalDebt = input.nextFloat();
- System.out.println("How much do you have on hand now?");
- float inHand = input.nextFloat();
- /* This while statement multiplies the inHand value by 2
- and repeats until inHand value is greater than
- the totalDebt value
- */
- while (inHand < totalDebt){
- inHand = inHand * 2;
- System.out.println("After bet(s), total in hand is " + inHand);
- counter++;
- }
- System.out.println("Total number of bets: " + counter);
- System.out.println("Total amount in hand: " + inHand);
- System.out.println(" ");
- if(part == 2){
- System.out.println("Part 2: Pattern");
- int n;
- int m;
- System.out.println("Enter the value for N:");
- n = input.nextInt();
- System.out.println("Enter the value for M");
- m = input.nextInt();
- /* This for loop takes the input and repeates the pattern based
- on what variables n and m equal
- */
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- if (i % 2 != 0) {
- System.out.print(".*");
- } else {
- System.out.print("*.");
- }
- }
- System.out.println();
- }
- }
- if(part == 3){
- System.out.println("Part 3: baby Simulator");
- int boy = 0;
- int girl = 0;
- /* This while statement sets the girl and boy variables to equal
- a random number then is put through an if staement determining if
- the number is less than .5 and adds either a girl or boy
- */
- while (boy == 0 || girl == 0) {
- double birth = (Math.random());
- if (birth < .5) {
- boy++;
- } else {
- girl++;
- }
- }
- System.out.println("Congragulations! You have " + boy + " boy(s) and " + girl + " girl(s).");
- }else{
- System.out.println("Wrong");
- }
- }
- System.out.println("Do you want to continue? Y/N");
- char answer = input.next().charAt(0);
- if (answer == 'Y'){
- continue;
- } else {
- System.out.println("Goodbye!");
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement