Answered step by step
Verified Expert Solution
Question
1 Approved Answer
version2: import java.util.Scanner; public class Lottery2 { public static boolean isvalid(int x) { if(x >=1 && x public static void main(String[] args) { int []
version2:
import java.util.Scanner;
public class Lottery2 { public static boolean isvalid(int x) { if(x >=1 && x
public static void main(String[] args) { int [] array = new int[6]; int i = 0; Scanner scanner = new Scanner(System.in); while(i Please select from 1-54:"); } } System.out.println("Playing the following 6 numbers" ); i = 0; while(i
java programming
For version 3, you will also prevent a duplicate entry (a number that has already been entered). You must use a new method other than main to validate that the number entered is unique. Also use the Arrays.sort method to sort the contents of the array. Make a copy of version 2 of your program and make the following changes: Name the class Lottery3 Continue to use the main method to manage the loops and main flow control. .Use the library class Arrays and its "sort" method to sort the array after all lottery numbers are selected Create a method called isUnique which accepts two parameters, an int containing the number that was entered, and an array of ints containing all the values previously entered. The method should return a boolean indicating whether or not the number passed unique. If false is returned, display a message from the main method indicating that the user must try again. Continue to loop and allow repeated attempts until a valid value is captured. public static boolean isUnique (int theNumber, int[] allNumbers) SAMPLE OUTPUT: java Lottery3 Enter a number from 1-54 (pick #1): 15 Enter a number from 1-54 (pick #2): 2 Enter a number from 1-54 (pick #3): 15 ERROR=> Duplicate number. Try again Enter a number from 1-54 (pick #3): 2 ERROR=> Duplicate number. Try again Enter a number from 1-54 (pick #3): 3 Enter a number from 1-54 (pick #4): 4 Enter a number from 1-54 (pick #5): 55 ERROR=> Please select from 1-54 Enter a number from 1-54 (pick #5): 4 ERROR=> Duplicate number. Try again Enter a number from 1-54 (pick #5): 5 Enter a number from 1-54 (pick #6): 6 Playing the following six numbers 23456 15
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started