Question

In: Computer Science

Implement a Lucky Draw game in which the user has to input an integer ‘input’ and...

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.

Solutions

Expert Solution

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


Related Solutions

IN C++ Implement in C++ a game called “Your Lucky Number”. The lucky number is calculated...
IN C++ Implement in C++ a game called “Your Lucky Number”. The lucky number is calculated based on an individual’s birth month, day, and year. The algorithm assigns any person a number between 1 and 9. Many people believe that a group of people with the same lucky number share common features. The lucky number is calculated as the sum of digits of the birth month, day, and year numbers. If this sum is not a single-digit then you need...
Implement in C++ a game called “Your Lucky Number”. The lucky number is calculated based on...
Implement in C++ a game called “Your Lucky Number”. The lucky number is calculated based on an individual’s birth month, day, and year. The algorithm assigns any person a number between 1 and 9. Many people believe that a group of people with the same lucky number share common features. The lucky number is calculated as the sum of digits of the birth month, day, and year numbers. If this sum is not a single digit then you need to...
Prompt the user to input their lucky number. Upon getting the users input, validate that the...
Prompt the user to input their lucky number. Upon getting the users input, validate that the input is a valid number using Int32.TryParse (more info can be found at https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/types/how-to-convert-a-string-to-a-number (Links to an external site.)). If the input is not a valid number, output a message to the user stating that you are sorry but you are unable to run the FizzBuzz process due to the input not being a valid number. If the input is valid, you are clear...
In Java:Implement a program that repeatedly asks the user to input apositive integer and...
In Java:Implement a program that repeatedly asks the user to input a positive integer and outputs the factorial of that input integer. Do not use recursion, solution should use stack.
1.Prompts the user for a positive integer >= 0 2.Validates the user input to ensure it...
1.Prompts the user for a positive integer >= 0 2.Validates the user input to ensure it is a positive integer >= 0 3.Allocate (dynamically) an array big enough for the data. 4.Load the array with random numbers ranging in value from1 to 100 5.Display the elements of the array (unsorted) 6.Display the elements of the array (sorted) 7. Display the average 8.Display the median 9.Display the mode, if none, display appropriate message #include <iostream> #include <stdlib.h> /* srand, rand */...
The goal of the game (program) is let a user input a random number in the...
The goal of the game (program) is let a user input a random number in the range of 0-10, and then give the user feedback as to whether this number is the same, bigger or smaller than the one the computer generated. Given this, the second task is to refine the program we just created so that the program compares the user's input with the secret number to If the user's input is equal to the number, print out the...
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream>, switch and if-else statements only and do not use string storing for the conversion in words. Thank you.** **Our class is still discussing on the basics of programming. Please focus only on the basics. Thank you.** Example outputs: Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four...
In this assignment we will be working with both text strings and a user input integer...
In this assignment we will be working with both text strings and a user input integer array from the data segment. The goal of the assignment is to have the user choose the number of items that they want to have in an array (we will keep it a small number for now, 1-10) and then enter those values which we will store into our array. We then want to allow them to search for a specific item in the...
IN JAVA Write a MAIN METHOD that asks for user input of a positive integer and...
IN JAVA Write a MAIN METHOD that asks for user input of a positive integer and a negative integer validates the inputs using a loop and then calls the METHOD from Question 3 and prints the result. The MAIN should have two variables (appropriately typed), get the input from the user and store them in the variables after validating them, then call the method from question 3 (sending parameters, if necessary) and print the returned value with an appropriate descriptive...
Design a program that will ask the user to input two integer numbers and then perform...
Design a program that will ask the user to input two integer numbers and then perform the basic arithmetic operations such as addition and subtraction. Each calculation is done by a separate function. The main function gets the input from the user, then calls the addition function and the subtraction function one at a time to perform the calculations. Each calculation function (addition or subtraction function) performs an arithmetic operation and then returns the calculation results back to where it...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT