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
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
Java Question where in chapter 7 Arrays. Ive done the code but im still having trouble...
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 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 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 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 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...
Please post screenshots only File Tools View CMSC 140 Common Projects Spring 2019(1) E - 3 x Project Description The Powerball game consists of 5 white balls and a red Powerball. The white balls represent a number in the range of 1 to 69. The red Powerball represents a number in the range of 1 to 26. To play the game, you need to pick a number for each ball in the range mentioned earlier. The prize of winning the...
11.9 Week 11 Lab: 2D Arrays For this lab, you only need to write a single user-defined function that analyzes a 2D array of chars. You do NOT need to write any of the code in main0 that calls your function. Make sure to use the template and only add code to the user-defined function. Write a function win0 with the following definition (i.e. prototype): int win(char board17)15), char player) The function win0 should return a 1 if the character...
Java code COCONUT KELAPA4 4A. Input Standard input Output Standard output Topic Array & Array Processing Problem Description Ali Wali owns a coconut plantation and a number of monkeys for bringing down coconuts. Every day, Ali would record the number of coconuts brought down by his monkeys. At the end of a certain time period, he would determine from the data recorded, the lowest and the highest number of coconuts as well as their number of occurrences. Write a program...
In python, write the following program, high school question, please keep simple. When I submitted the solution, I get an error as 'wrong answer'. Please note below the question and then the solution with compiler errors. 7.2 Code Practice: Question 2 Instructions Write a program to generate passwords. The program should ask the user for a phrase and number, and then create the password based on our special algorithm. The algorithm to create the password is as follows: If the...
Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges two arrays of positive integers and removes any duplicate entries. Your program will first ask for a valid length which must be an integer which is 10 or greater. The program should continue to ask until a valid length is entered. The program will then create two arrays of the length entered, fill these with random integers between 1 and 100 inclusive, and print...