Question

In: Computer Science

Java code TIA I need this: Your program makes accommodations for repeating digits. For example if...

Java code

TIA

I need this: Your program makes accommodations for repeating digits. For example if the random numbers generated were 141 in that order. Then the user entered 271 in that order, be sure that the last one does not count a match to the first and third numbers of the random numbers. They only matched one number in this case. Now if the random numbers are 141 in that order and the user enters 113, then they did match 2 numbers. If they enter 114 then they match 3 numbers but not in order.

public class lotteryGame {
//declaring varibales
static int a,b,c,n1,n2,n3,matchCount=0;
static Scanner input = new Scanner (System.in);
public static void matchNumbers(int a,int b,int c) {
Random random=new Random();
//generating three random numbers (between 0 to 10) and storing it in n1,n2 and n3
n1= random.nextInt(10);
n2= random.nextInt(10);
n3= random.nextInt(10);
//comapring three random numbers with user entered numbers
if(n1==a)
matchCount++;
if(n2==b)
matchCount++;
if(n3==c)
matchCount++;
//checking how many numbers matched
if(matchCount==1){
System.out.println("\nYou guessed 1 number correctly");
System.out.println("\n***Congratulations you have won $10000***");
}
else if(matchCount==2){
System.out.println("\nGOOD!!,You guessed 2 numbers correctly");
System.out.println("\nCongratulations you have won $100000");
}

else if(matchCount==3){
System.out.println("\nAmazing!!,You guessed all 3 numbers correctly");
System.out.println("\n***Congratulations you have won $1000000***");
}
else
{
System.out.println("\nYou guessed all 3 numbers in-correctly");
System.out.println("-1");
}
}   
public static void main(String args[])
{
//printing welcome message and also the amount for correct guesses
System.out.println("********WELCOME TO LOTTERY GAME********");
System.out.println("GAME PRICES: ");
System.out.println("FOR ALL THREE CORRECT MATCHES: $1000000");
System.out.println("FOR TWO CORRECT MATCHES: $100000");
System.out.println("FOR ONLY ONE CORRECT MATCHES: $10000");
System.out.println("FOR ALL THREE IN-CORRECT MATCHES: it will show -1");
//reading three numbers from users
System.out.println("\nEnter three numbers(0<=numbers<10): ");
a=input.nextInt();
b=input.nextInt();
c=input.nextInt();
//calling method matchNumbers() by passing three parameters
matchNumbers(a,b,c);

}
  
}

Solutions

Expert Solution

//Changes made according to the requirement.


import java.util.*;
public class lotteryGame {
//declaring varibales
static int a,b,c,n1,n2,n3,matchCount=0;
static Scanner input = new Scanner (System.in);
public static void matchNumbers(int a,int b,int c) {
Random random=new Random();
//generating three random numbers (between 0 to 10) and storing it in n1,n2 and n3
n1= random.nextInt(10);
n2= random.nextInt(10);
n3= random.nextInt(10);
//comapring three random numbers with user entered numbers

//Modified
if(n1==a)
{
matchCount++;
n1=99;   //changed it to a number above 10 so that it do not match again and again.
}
else if(n1==b)
{
 matchCount++;
n1=99;   
}
else if(n1==c)
{
matchCount++;
n1=99;
}
if(n2==a)
{
matchCount++;
n2=99;
}
else if(n2==b)
{
 matchCount++;
n2=99;   
}
else if(n2==c)
{
matchCount++;
n2=99;
}
if(n3==a)
{
matchCount++;
n3=99;
}
else if(n3==b)
{
 matchCount++;
n3=99;   
}
else if(n3==c)
{
matchCount++;
n3=99;
}
//checking how many numbers matched
if(matchCount==1){
System.out.println("\nYou guessed 1 number correctly");
System.out.println("\n***Congratulations you have won $10000***");
}
else if(matchCount==2){
System.out.println("\nGOOD!!,You guessed 2 numbers correctly");
System.out.println("\nCongratulations you have won $100000");
}

else if(matchCount==3){
System.out.println("\nAmazing!!,You guessed all 3 numbers correctly");
System.out.println("\n***Congratulations you have won $1000000***");
}
else
{
System.out.println("\nYou guessed all 3 numbers in-correctly");
System.out.println("-1");
}
}   
public static void main(String args[])
{
//printing welcome message and also the amount for correct guesses
System.out.println("********WELCOME TO LOTTERY GAME********");
System.out.println("GAME PRICES: ");
System.out.println("FOR ALL THREE CORRECT MATCHES: $1000000");
System.out.println("FOR TWO CORRECT MATCHES: $100000");
System.out.println("FOR ONLY ONE CORRECT MATCHES: $10000");
System.out.println("FOR ALL THREE IN-CORRECT MATCHES: it will show -1");
//reading three numbers from users
System.out.println("\nEnter three numbers(0<=numbers<10): ");
a=input.nextInt();
b=input.nextInt();
c=input.nextInt();
//calling method matchNumbers() by passing three parameters
matchNumbers(a,b,c);

}
  
}

Related Solutions

I need to make this into a Java Code: Write a program that prompts the user...
I need to make this into a Java Code: Write a program that prompts the user for a double value representing a radius. You will use the radius to calculate: circleCircumference = 2πr circleArea = πr2 sphereArea = 4πr2 sphereVolume = 43πr3 You must use π as defined in the java.lang.Math class. Your prompt to the user to enter the number of days must be: Enter radius: Your output must be of the format: Circle Circumference = circleCircumference Circle Area...
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
I need the Java Code and Flowchart for the following program: Suppose you are given a...
I need the Java Code and Flowchart for the following program: Suppose you are given a 6-by-6 matrix filled with 0s and 1s. All rows and all columns have an even number of 1s. Let the user flip one cell (i.e., flip from 1 to 0 or from 0 to 1) and write a program to find which cell was flipped. Your program should prompt the user to enter a 6-by-6 array with 0s and 1s and find the first...
I need original java code that completes this program and gets it to print out results...
I need original java code that completes this program and gets it to print out results just like in the example. Also please upload answer in a word document format only. Implement both linear search and binary search, and see which one performs better given an array 1,000 randomly generated whole numbers (between 0-999), a number picked to search that array at random, and conducting these tests 20 times. Each time the search is conducted the number of checks (IE...
I need a full java code. And I need it in GUI With the mathematics you...
I need a full java code. And I need it in GUI With the mathematics you have studied so far in your education you have worked with polynomials. Polynomials are used to describe curves of various types; people use them in the real world to graph curves. For example, roller coaster designers may use polynomials to describe the curves in their rides. Polynomials appear in many areas of mathematics and science. Write a program which finds an approximate solution to...
I am struggling with this java code Objectives: Your program will be graded according to the...
I am struggling with this java code Objectives: Your program will be graded according to the rubric below. Please review each objective before submitting your work so you don’t lose points. 1. Create a new project and class in Eclipse and add the main method. (10 points) 2. Construct a Scanner to read input from the keyboard. (10 points) 3. Use the Scanner to read the name, number of balls, and yards per ball of a yarn type specified by...
JAVA JAVA JAVA Hey i need to find a java code for my homework, this is...
JAVA JAVA JAVA Hey i need to find a java code for my homework, this is my first java homework so for you i don't think it will be hard for you. (basic stuff) the problem: Write a complete Java program The transport Company in which you are the engineer responsible of operations for the optimization of the autonomous transport of liquid bulk goods, got a design contract for an automated intelligent transport management system that are autonomous trucks which...
Make a java program of Mickey I have the starter program but I need to add...
Make a java program of Mickey I have the starter program but I need to add eyes and a smile to it. import java.awt.Canvas; import java.awt.Color; import java.awt.Graphics; import java.awt.Rectangle; import javax.swing.JFrame; public class Mickey extends Canvas { public static void main(String[] args) { JFrame frame = new JFrame("Mickey Mouse"); Canvas canvas = new Mickey(); canvas.setSize(400, 400); canvas.setBackground(Color.white); frame.add(canvas); frame.pack(); frame.setVisible(true); } public void paint(Graphics g) { Rectangle bb = new Rectangle(100, 100, 200, 200); mickey(g, bb); } public void...
JAVA JAVA JAVA . I need to convert a string input to int array, for example...
JAVA JAVA JAVA . I need to convert a string input to int array, for example if user enters 12 / 27 / 2020 , I want to store each value in a separate array and add them afterwards.
Java homework problem: I need the code to be able to have a message if I...
Java homework problem: I need the code to be able to have a message if I type in a letter instead of a number. For example, " Please input only numbers". Then, I should be able to go back and type a number. import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class LoginGui {    static JFrame frame = new JFrame("JFrame Example");    public static void main(String s[]) {        JPanel panel...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT