In: Computer Science
Implement a Lucky Draw game in which the user has to input an integer ‘input’ and multiply it with a random integer to get the product ‘p’. Depending upon the value of ‘p’ display the prize amount. Use a suitable Java Collection object to store the prize amount for each value of ‘p’.
Design a generic stack data structure (not a Collection object) which can handle integer, double, character and any user-defined objects. Write a menu-driven Java program to test it.
CODE
import java.util.Scanner;
public class Member {
public static void main(String[] args) {
// TODO automatic generation method stub
Scanner input=new Scanner(System.in);
String continueChoice="n"; / / define a negative, used to jump out of the program
String userNamer=""; / / define a username variable
String password="";//Define a password variable
Int cardNumber=0000;//Define a four-digit card number
Int max=9999; / / maximum random number
Int min=1000;//minimum random number
Boolean isRegister=false; / / judgment, if it is false, return
Boolean isLogin=false; / / judgment, if it is false, return
/ / The entire program loop, with do while loop, first loop and then judge
do {
//Main menu option
System.out.println("*****Welcome to the Award Winner System*****");
System.out.println(" 1.Register");
System.out.println(" 2. Login");
System.out.println(" 3. Draw");
System.out.println("****************************");
System.out.println("Please enter options");
int menChoice=input.nextInt();
/ / Algorithm used in the option
switch (menChoice) {
case 1:
System.out.println("Renaissance Rich System > Registration");
System.out.println("Please fill in the personal registration information");
System.out.println("username:");
userNamer=input.next();
System.out.println("Password:");
password=input.next();
System.out.println(" ");
cardNumber=(int)(Math.random()*(max-min))+min;
System.out.println("Registration is successful, please remember your membership card number");
System.out.println("username\t"+"password\t"+"member card number\t");
System.out.println(userNamer+"\t"+password+"\t"+cardNumber);
isRegister=true;
break;
case 2:
System.out.println("Renaissance Rich System>Login");
/ / Judge, if it is false, loop three times user login program
if (isRegister) {
for (int i = 1; i <= 3; i++) {
System.out.println("Please enter username:");
String inputUserNamer=input.next();
System.out.println("Please enter password:");
String inputPassWord=input.next();
/ / Determine the user name and password entered above are correct, the actual login is successful
if (userNamer.equals(inputUserNamer)&&password.equals(inputPassWord)) {
System.out.println("Welcome: "+inputUserNamer);
/ / Returns true, the algorithm to end this case
isLogin=true;
break;
}
//If you make a mistake, judge it three times or less and prompt the user to have several chances.
else if (i<3) {
System.out.println("Username or password is incorrect, and there are "+(3-i)+"opportunity"+"\n");
} else {
System.out.println("You entered the error three times");
}
}
}
break;
case 3:
System.out.println("Renaissance Rich System > Lucky Draw");
/ / Randomly extract four-digit numbers
if(isLogin){
int[] luckyNums = new int[10];
for(int i=0;i<luckyNums.length;i++){
luckyNums[i] = (int)(Math.random()*(max-min))+min;
}
/ / Enter the card number
System.out.print("Please enter your card number:");
int youCard = input.nextInt();
int i = 0;
System.out.print("\n today's lucky number is:");
/ / Determine whether the card number entered by the user is consistent with the randomly generated random number
for(i=0;i<luckyNums.length;i++){
System.out.print(luckyNums[i]+" ");
}
for(i=0;i<luckyNums.length;i++){
if(luckyNums[i]==youCard){
System.out.println("\n Congratulations! You are a lucky member of the day!");
break;
}
}
if(i==luckyNums.length){
System.out.println("\n sorry! You are not a lucky member of today!");
}
}else{
System.out.println("Please login first, then draw!");
System.out.println("Continue?(y/n)");
continueChoice = input.next();
}
break;
default:
System.out.println("Your input is incorrect");
break;
}
System.out.print("Continue?(y/n):");
continueChoice = input.next();
}while("y".equals(continueChoice));//If the user enters y, it will continue to loop large loop body
/ / If the user enters n, then exit the program
if("n".equals(continueChoice)){
System.out.println("System exit, thank you for using!");
}
}
}
OUTPUT