Question

JAVA Lab -Lottery Calculator IMPORTANT: This lab is best implemented using a loop structure. If you...

JAVA

Lab -Lottery Calculator

IMPORTANT: This lab is best implemented using a loop structure. If you implement this without a loop, you would need to run your program once for each test item.

Create a java program that will test for winning numbers on a lottery game.
Each lottery ticket will have 5 integer numbers.
Valid numbers must be integer numbers between 1 and 55
Assume that the winning Lottery ticket is 1 9 15 33 40

Your program is to input numbers at the console (use of Scanner is recommended)
The program will continue to check tickets and report winnings until the user enters
some stop code to exit.

Sample of a possible program output:

Enter the numbers on your ticket // Program prompt
2 18 20 32 51 // User inputs numbers
Sorry, you have no matches // Result

Enter the numbers on your ticket // Program Continues
1 9 18 33 40 // User inputs numbers
You matched 5 numbers! You win $5000 // Results

Enter the numbers on your ticket
2 4 6 8 85 // Valid Check invalid number (85)

Select how many tickets your are scanning
or enter some sort of response to indicate
you are finished with the program (Your choice on this)
// Check for more tickets
// Input signals to end the program
Exit with "Thanks for Using the Lottery Calculator" //

TEST DATA
Use the following ticket values to test your program
Winning Lottery Numbers 1 9 15 33 40
1 10 16 35 30
3 9 15 47 49
1 9 18 33 40
2 4 6 8 85
3 9 15 47 49
1 10 16 35 30

Your program is to determine how many matches each tickets have with the winning number. You will print results matches and prize won after entering each ticket won.

Matching results:
If no matches of the winning drawing. No prize
If the ticket matches 5 out of 5 matches a prize of $5000 is earned
If 2-3 matches the ticket wins $10.
If the ticket matches one number ticket wins $1.
If there are no number matches, indicate "No Matches".
Use the winning Drawing of 1 9 15 33 40 for this Lab

Scanner setup tip:
import java.util.*;
Scanner input = new Scanner(System.in);
int number;
number = scan.nextInt();

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Lottery Calculator:-

program:-

import java.util.*;
class Lab_Lottery{
   public static void main(String[] args) {
       int win[] = {1,9,15,33,40};
       int tic[] = new int[5];               //to store user lottery numbers
       int i,j,noOfMatchedNumbers;
       int flag;     //for checking Invalid numbers
       Scanner sc = new Scanner(System.in);
       char ch = 'Y';
       while(ch != 'N'){
           flag=0;
           System.out.println("Enter the numbers on your ticket");
           for(i=0;i<5;i++){
               tic[i] = sc.nextInt();
           }
           for(i=0;i<5;i++){
               if(tic[i]<1 || tic[i]>55){
                   System.out.println("Invalid number:"+tic[i]);
                   flag = 1;
               }
           }
           noOfMatchedNumbers=0;
           if(flag == 1)
               System.out.println("Numbers must be in between 1 and 55");
           else{
               for(i=0;i<5;i++){
                   for(j=0;j<5;j++){
                       if(tic[j]==win[i]){
                           noOfMatchedNumbers++;
                       }
                   }
               }
               switch (noOfMatchedNumbers){
                   case 1:
                       System.out.println("Ticket Matches one number Ticket wins $1");
                       break;
                   case 2:
                       System.out.println("Ticket Matches two numbers Ticket wins $10");
                       break;
                   case 3:
                       System.out.println("Ticket Matches three numbers Ticket wins $10");
                       break;
                   case 4:
                       System.out.println("Ticket Matches four numbers Ticket wins $500");
                       break;
                   case 5:
                       System.out.println("Yahooooo!!!Your ticket matches 5 of 5 numbers Ticket wins $5000");
                       break;
                   default:
                       System.out.println("Sorrry,No matches...No prize...Better luck next time");
                       break;
               }
           }
           System.out.println("Do you want to continue(Y/N)");
           ch = sc.next().charAt(0); //To read char from user
       }
       System.out.println("Thanks for using the lottery calculator.");  
   }
}

Output:-


Code Screenshots:-

Add a comment
Know the answer?
Add Answer to:
JAVA Lab -Lottery Calculator IMPORTANT: This lab is best implemented using a loop structure. If you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 4.26 In a lottery game, three winning numbers are chosen uniformly at random from (1, ,100), samp...

    4.26 In a lottery game, three winning numbers are chosen uniformly at random from (1, ,100), sampling without replacement. Lottery tickets cost $1 and allow a player to pick three numbers. If a player matches the three winning numbers they win the jackpot prize of $1,000. For matching exactly two numbers, they win $15. For matching exactly one number they win $3 d) Hoppe shows that the probability that a single parlayed ticket will ulti- mately win the jackpot is...

  • Using C++ create a lotto program Lottery Design a program that simulates a lottery. Requirements:  The program...

    Using C++ create a lotto program Lottery Design a program that simulates a lottery. Requirements:  The program should have an array of 5 integers named lottery and should generate a random number in the range of 1 through 99 for each element of the array. The user should enter five digits, which should be stored in an integer array named user. The program is to compare the corresponding elements in the two arrays and keep a count of the digits that...

  • A school carnival offers a lottery and other games of chance. All people attending the carnival a...

    A school carnival offers a lottery and other games of chance. All people attending the carnival are entered into the lottery when they pay the admission fee. The numbered lottery tickets are placed in a bowl, mixed, and removed one at a time from the bowl ("drawn") by a disinterested person. The person holding the ticket with the chosen number wins a prize. The lottery numbers chosen are not returned to the bowl until the final drawing (see Table 1-1...

  • Need help with assignment This assignment involves simulating a lottery drawing. In this type of lottery...

    Need help with assignment This assignment involves simulating a lottery drawing. In this type of lottery game, the player picks a set of numbers. A random drawing of numbers is then made, and the player wins if his/her chosen numbers match the drawn numbers (disregarding the order of the numbers). More specifically, a player picks k distinct numbers between 1 and n (inclusive), as well as one bonus number between 1 and m (inclusive). "Distinct" means that none of the...

  • We have a lottery with three prizes. Two of them are $30 and the grand is...

    We have a lottery with three prizes. Two of them are $30 and the grand is $200. The total number of tickets is 70 and one for each person. No one can win more than a prize. When the tickets are pulled, the first two prizes of $30 are awarded, then the grand prize. a) how many ways we can award the prizes? b) Suppose a person has one ticket, what's the probability of winning any prize? c) If a...

  • To win a state's lottery jackpot you have to successfully match 6 numbers chosen from the...

    To win a state's lottery jackpot you have to successfully match 6 numbers chosen from the numbers 1 through 39. The lottery also pays smaller prizes if you match only 3.4 or 5 of the numbers a) What's the probability that your choices match 3 of the 6 winning numbers? b) What's the probability your ticket wins some prize? a) The probability that your choices match 3 of the winning numbers is (Round to three decimal places as needed) b)...

  • Devlop a python program as simple as possible: Make sure the program run properly and Incude...

    Devlop a python program as simple as possible: Make sure the program run properly and Incude the ouput with the program.Thanks. Write a program to help determine the likelihood of winning the lottery. People pick six integers from 1 to 59, inclusive. Six lottery numbers are selected at random from the same range. If a person's six numbers match the lottery-selected numbers, the person wins a large cash prize. If the user matches any five of the six lottery-selected numbers,...

  • Java Question where in chapter 7 Arrays. Ive done the code but im still having trouble...

    Java Question where in chapter 7 Arrays. Ive done the code but im still having trouble with the inequality Here my code import java.util.Scanner; public class PS10_5 { public static void main(String args[]) { int[] mynum = new int[5]; int count = 0; int[] lottery = {8,13,27,53,54}; Scanner keyboard = new Scanner(System.in); System.out.println("Check your lottery numbers here!"); for(int subscript=0; subscript<5; subscript++) { System.out.println("Enter number " + (subscript +1) + ":"); mynum[subscript] = keyboard.nextInt(); } for(int subscript=0; subscript<5; subscript++) { for...

  • In a lottery, you pick 2 digits (from 0-9) in order, but the digits may not...

    In a lottery, you pick 2 digits (from 0-9) in order, but the digits may not be repeated. A lottery ticket costs $1, and you win $40 if your ticket matches the winning numbers. What is the expected value of playing the lottery? Show your work.

  • Q4 (10 points) In the pick-6 lottery involving the numbers 1-40 which we considered in the...

    Q4 (10 points) In the pick-6 lottery involving the numbers 1-40 which we considered in the examples of counting questions in class, you win the Match-4 prize if exactly four of your six numbers appear on the winning ticket. In a given lottery drawing, how many different tickets would win the Match-4 prize?

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT