Sei sulla pagina 1di 4

import java.util.Random; import java.util.Scanner; public class Lottery { public Lottery() { System.out.println("Welcome to the Wudtke Lottery!

") number1 = 0; number2 = 0; number3 = 0; number4 = 0; number5 = 0; number6 = 0; match1 = 0; match2 = 0; match3 = 0; match4 = 0; match5 = 0; match6 = 0; winnings = 0; rWinnings = 0; cost = 0; } public void inputNumbers() { System.out.println("Please input six numbers between 1-40. \n PL EASE DO NOT REPEAT NUMBERS!!!!") Scanner mouse = new Scanner(System.in); int x = 1; while(x<=6) { System.out.print("Please pick a number: ") int y = mouse.nextInt() if(y >= 1 && y <= 40) { if(x == 1) number1 = y; if(x == 2 && y != number1) number2 = y; if(x == 3 && y != number1 && y != numbe r2) number3 = y; if(x == 4 && y != number1 && y != numbe r2 && y != number3) number4 =y; if(x == 5 && y != number1 && y != numbe r2 && y != number3 && y != number4) number5 = y; if(x == 6 && y != number1 && y != numbe

r2 && y != number3 && y != number4 && y != number5) number6 = y; } x++; } } public void getNumbers() { Random x = new Random(); for(int number = 1; number >= 6; number++;) { int y = x.nextInt(41); if (number == 1) { while (y == 0) y = x.nextInt (41); match1 = y; } if (number == 2 && y != number1) match2 = y; else if (number == 2) { while (y == 0 || y == number1) y = x.nextInt (41); match2 = y; } if (number == 3 && y != match1 && y != match2) match3 = y; else if (number == 3) { while (y == 0 || y == match1 || y == match2) y = x.nextInt (41); match3 = y; } if (number == 4 && y != match1 && y != match2 && y!= match3) match4 = y; else if (number == 4) { while (y == 0 || y == match1 || y == match2 || y == matc h3) y = x.nextInt (41); match4 = y; } if (number == 5 && y != match1 && y != match2 && y!= match3 && y != match4) match5 = y; else if (number == 5) { while (y == 0 || y == match1 || y == match2 || y == matc h3 || y == match4) y = x.nextInt (41); match5 = y; } if (number == 6 && y != match1 && y != match2 && y!= match3 && y != match4 && y != match5) match6 = y;

else if (number == 6) { while (y == 0 || y == match1 || y == match2 || y == matc h3 || y == match4 || y == match5) y = x.nextInt (41); match6 = y; } } } public void compareNumbers () { || || || || || || rWinnings = 0; if (number1 == match1 || number1 == match2 || number1 number1 == match4 || number1 == match5 || number1 == match6) { if (number2 == match1 || number2 == match2 || number2 number2 == match4 || number2 == match5 || number2 == match6) { if (number3 == match1 || number3 == match2 || number3 number3 == match4 || number3 == match5 || number3 == match6) { if (number4 == match1 || number4 == match2 || number4 number4 == match4 || number4 == match5 || number4 == match6) { if (number5 == match1 || number5 == match2 || number5 number5 == match4 || number5 == match5 || number5 == match6) { if (number6 == match1 || number6 == match2 || number6 number6 == match4 || number6 == match5 || number6 == 6) rWinnings += 300000000; else rWinnings += 1000000; } else rWinnings += 100000; } else rWinnings += 5000; } else rWinnings += 500; } else rWinnings += 100; } winnings += rWinnings; System.out.println ("You've won $" + rWinnings); } public void playLotto () { Scanner in = new Scanner (System.in); do { this.inputNumbers (); this.getNumbers (); this.compareNumbers (); == match3 == match3 == match3 == match3 == match3 == match3

System.out.print ("Would you like to continue? (Y/N)"); playAgain =in.next (); } while (playAgain.equalsIgnoreCase ("Y")); if (playAgain.equalsIgnoreCase ("N")) { if (cost > winnings) { balance = cost - winnings; System.out.println ("You owe $" + balance); } else if (winnings >= cost) { balance = winnings - cost; System.out.println ("You've won $" + balance); } } } }

//Instance Field private int number1; private int number2; private int number3; private int number4; private int number5; private int number6; private int match1; private int match2; private int match3; private int match4; private int match5; private int match6; private double winnings; private double cost; private double rWinnings; private double balance; private String playAgain; } -------------------------------------------------------------------------------------------------------------------public class LotteryTester { public static void main (String [] args) { Lottery x = new Lottery (); x.playLotto (); } }

Potrebbero piacerti anche