Question

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 (int winner = 0; winner < 5; winner++)
            {
                if (mynum[subscript] == lottery[winner])
                {
                    count++;
                }
            }
        }
        System.out.println("All set. The winning numbers were: 8 13 27 53 54");
        if(count == 5)
        {
            System.out.println("WOW! Grand prize winner!");
        }
        else {
            System.out.println("Well, you didn't win. You got " + count + " matching number(s)");
        }
    }
}

Here the problem

Write a program that checks to see if the user won the lottery. Assume the winning lottery numbers are 8, 13, 27, 53, and 54. Ask the user for five numbers and compare those numbers to the winning numbers to determine how many matches the user got. In a lottery, the order of the numbers doesn't matter.

Here are the required output

Test Case 1

Standard Input                
10ENTER
20ENTER
30ENTER
40ENTER
50ENTER
Check your lottery numbers here!\n
Enter number 1:\n
Enter number 2:\n
Enter number 3:\n
Enter number 4:\n
Enter number 5:\n
All set. The winning numbers were: 8 13 27 53 54\n
Well, you didn't win. You got 0 matching number(s)\n

Test Case 2

Standard Input                
10ENTER
20ENTER
30ENTER
40ENTER
8ENTER
ENTER
Check your lottery numbers here!\n
Enter number 1:\n
Enter number 2:\n
Enter number 3:\n
Enter number 4:\n
Enter number 5:\n
All set. The winning numbers were: 8 13 27 53 54\n
Well, you didn't win. You got 1 matching number(s)\n

Test Case 3

Standard Input                
10ENTER
53ENTER
30ENTER
40ENTER
8ENTER
Check your lottery numbers here!\n
Enter number 1:\n
Enter number 2:\n
Enter number 3:\n
Enter number 4:\n
Enter number 5:\n
All set. The winning numbers were: 8 13 27 53 54\n
Well, you didn't win. You got 2 matching number(s)\n

Test Case 4

Standard Input                
13ENTER
53ENTER
30ENTER
40ENTER
8ENTER
Check your lottery numbers here!\n
Enter number 1:\n
Enter number 2:\n
Enter number 3:\n
Enter number 4:\n
Enter number 5:\n
All set. The winning numbers were: 8 13 27 53 54\n
Well, you didn't win. You got 3 matching number(s)\n

Test Case 5

Standard Input                
13ENTER
53ENTER
30ENTER
27ENTER
8ENTER
Check your lottery numbers here!\n
Enter number 1:\n
Enter number 2:\n
Enter number 3:\n
Enter number 4:\n
Enter number 5:\n
All set. The winning numbers were: 8 13 27 53 54\n
Well, you didn't win. You got 4 matching number(s)\n

Test Case 6

Standard Input                
13ENTER
53ENTER
54ENTER
27ENTER
8ENTER
Check your lottery numbers here!\n
Enter number 1:\n
Enter number 2:\n
Enter number 3:\n
Enter number 4:\n
Enter number 5:\n
All set. The winning numbers were: 8 13 27 53 54\n
WOW! Grand prize winner!\n

Test Case 7

Standard Input                
13ENTER
53ENTER
540ENTER
54ENTER
27ENTER
89ENTER
8ENTER
ENTER
Check your lottery numbers here!\n
Enter number 1:\n
Enter number 2:\n
Enter number 3:\n
Must be between 1 and 99\n
Enter number 3:\n
Enter number 4:\n
Enter number 5:\n
All set. The winning numbers were: 8 13 27 53 54\n
Well, you didn't win. You got 4 matching number(s)\n

Test Case 8

Standard Input                
100ENTER
1000ENTER
-1ENTER
0ENTER
-56ENTER
10ENTER
20ENTER
13ENTER
53ENTER
54ENTER
Check your lottery numbers here!\n
Enter number 1:\n
Must be between 1 and 99\n
Enter number 1:\n
Must be between 1 and 99\n
Enter number 1:\n
Must be between 1 and 99\n
Enter number 1:\n
Must be between 1 and 99\n
Enter number 1:\n
Must be between 1 and 99\n
Enter number 1:\n
Enter number 2:\n
Enter number 3:\n
Enter number 4:\n
Enter number 5:\n
All set. The winning numbers were: 8 13 27 53 54\n
Well, you didn't win. You got 3 matching number(s)\n

Test Case 9

Standard Input                
53ENTER
54ENTER
100ENTER
1000ENTER
-1ENTER
0ENTER
-56ENTER
10ENTER
-47ENTER
20ENTER
13ENTER
Check your lottery numbers here!\n
Enter number 1:\n
Enter number 2:\n
Enter number 3:\n
Must be between 1 and 99\n
Enter number 3:\n
Must be between 1 and 99\n
Enter number 3:\n
Must be between 1 and 99\n
Enter number 3:\n
Must be between 1 and 99\n
Enter number 3:\n
Must be between 1 and 99\n
Enter number 3:\n
Enter number 4:\n
Must be between 1 and 99\n
Enter number 4:\n
Enter number 5:\n
All set. The winning numbers were: 8 13 27 53 54\n
Well, you didn't win. You got 3 matching number(s)\n

Test Case 10

To prevent hardcoding, this test case is hidden. To pass this case, be sure that all the programming requirements are met.

Test Case 11

Standard Input                
13ENTER
54ENTER
53ENTER
27ENTER
8ENTER
Check your lottery numbers here!\n
Enter number 1:\n
Enter number 2:\n
Enter number 3:\n
Enter number 4:\n
Enter number 5:\n
All set. The winning numbers were: 8 13 27 53 54\n
WOW! Grand prize winner!\n

Test Case 12

Standard Input                
54ENTER
27ENTER
8ENTER
13ENTER
53ENTER
Check your lottery numbers here!\n
Enter number 1:\n
Enter number 2:\n
Enter number 3:\n
Enter number 4:\n
Enter number 5:\n
All set. The winning numbers were: 8 13 27 53 54\n
WOW! Grand prize winner!\n
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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;)

{

System.out.println("Enter number " + (subscript +1) + ":");

mynum[subscript] = keyboard.nextInt();

if(!(mynum[subscript] >=1 && mynum[subscript] <=99)) {

System.out.println("Must be between 1 and 99");

}else {

++subscript;

}

}

for(int subscript=0; subscript<5; subscript++)

{

for (int winner = 0; winner < 5; winner++)

{

if (mynum[subscript] == lottery[winner])

{

count++;

}

}

}

System.out.println("All set. The winning numbers were: 8 13 27 53 54");

if(count == 5)

{

System.out.println("WOW! Grand prize winner!");

}

else {

System.out.println("Well, you didn't win. You got " + count + " matching number(s)");

}

}

}
=================================================
SEE OUTPUT, Please Let me know if you face any trouble


PLEASE COMMENT

Add a comment
Know the answer?
Add Answer to:
Java Question where in chapter 7 Arrays. Ive done the code but im still having trouble...
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
  • In Java chapter 7 Arrays. Ask the user for five names. Output those names. Put an...

    In Java chapter 7 Arrays. Ask the user for five names. Output those names. Put an integer before each name to indicate the ordering Here are the required output Test Case 1 Standard Input                 BillENTER SteveENTER MarkENTER ElonENTER Henry Enter five names\n Enter friend 1\n Enter friend 2\n Enter friend 3\n Enter friend 4\n Enter friend 5\n Here are all of those names\n Friend 1 is Bill\n Friend 2 is Steve\n Friend 3 is Mark\n Friend 4 is Elon\n...

  • 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...

  • Write a program in Java. Ask the user how many integers that he/she wants to enter....

    Write a program in Java. Ask the user how many integers that he/she wants to enter. Using a for loop, ask the user for that many integers. Then, display all those integers. view required output Standard Input                 20ENTER 500ENTER 400ENTER 300ENTER 550ENTER 600ENTER 700ENTER -3ENTER 0ENTER 50ENTER 60ENTER 40ENTER 13ENTER 14ENTER 80ENTER 90ENTER 100ENTER 777ENTER 1024ENTER 20ENTER 22 How many integers do you have? (Max 20)\n Enter element for subscript 0\n Enter element for subscript 1\n Enter element for...

  • This needs to be done using c++ No vectors or arrays can be used since we...

    This needs to be done using c++ No vectors or arrays can be used since we haven't learned them yet! Write a program that simulates a slot machine. The slot machine should have the following characteristics: - 3 view windows to display items on a wheel. Typically, these are cherries, bars, etc. - each wheel will randomly select a number 1-7. - the user will be charged 5 tokens to spin the wheels Winning combinations will be as follows: -...

  • Code in Java Using Arrays ( input should end with 0 to terminate the program) Bulls...

    Code in Java Using Arrays ( input should end with 0 to terminate the program) Bulls and Cows is an old code-breaking mind or paper and pencil game for two or more players, predating the similar commercially marketed board game Mastermind. The game is usually played with 4 digits, but can also be played with 3 or any other number of digits. The players must try to guess the secret number created by the codemaker. On a sheet of paper,...

  • Java Project Name: IC19_WinningTheLottery n this assignment, we're going to attempt to win the lottery! (**If...

    Java Project Name: IC19_WinningTheLottery n this assignment, we're going to attempt to win the lottery! (**If you do actually win the lottery, please be sure to give back to your alma mater, Orange Coast College. We will be happy to put your name on the building!**) Ok, time to get real. The Fantasy 5 (TM) lottery is a game in which 5 numbers from 1 to 36 are randomly drawn by the State of California. If you correctly guess all...

  • 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...

  • 7-10 There is a new lottery game where twelve numbers are chosen from the set of numbers from 1 to 24, with no repeats. One of the ways to win is to match ZERO numbers, the other way to win is to...

    7-10 There is a new lottery game where twelve numbers are chosen from the set of numbers from 1 to 24, with no repeats. One of the ways to win is to match ZERO numbers, the other way to win is to match ALL the numbers. Order does not matter. 7. Calculate the probability of getting all the numbers correct. Show the setup of the numbers, in case calculations go silly and also to show that you didn't just Google...

  • Code with Java using arrays and Scanner only ( input should end with 0 to terminate...

    Code with Java using arrays and Scanner only ( input should end with 0 to terminate the program) Everyone loves to be celebrated on their birthdays. Birthday celebration can encourage positive social interaction among co-workers, foster friendship among classmates or even strengthen bond between families. Birthday graph can be display in many forms. It can a creative drawing consists of cupcakes, balloons, candles with names, or it can be in the form of simple bar chart to indicate the birthday...

  • Can someone do 2,6,8,12 34 Exercises 187 EXAMPLE 7 GETTING FIVE HEARTS Find the probability of being dealt five bearts...

    Can someone do 2,6,8,12 34 Exercises 187 EXAMPLE 7 GETTING FIVE HEARTS Find the probability of being dealt five bearts SOLUTION The sample is the same as in Example 5. The event consists of all pos- hands that include five hearts and no non-hearts This involves cltegories (hearts and non-hearts), so we will use the Fundamental Count- hinciple and multiply the number of ways of getting five hearts and the sible number of ways of getting no non-hearts There are...

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