In this assignment you will create a console (standalone) application. This prog
ID: 3697519 • Letter: I
Question
In this assignment you will create a console (standalone) application. This program will allow you to select MegaMillion numbers. For the first 5 numbers you will be requested to enter a number that is greater than zero and less than 76 since the first 5 numbers on the MegaMillion lottery must be between1-75. However, there’s a catch! Each of these five numbers must be different.
When any of the first five numbers entered is less than 0 or greater 75 the user will receive a message to this effect and will be asked to reenter the number. You will create the code that will display one message when a number that is less than 1 is entered and a different message will display when the number entered is greater than 75. For example, if the user enters zero you might display the message: “The number must be greater than zero. Please reenter the number.” If the number is the same as any number entered before it (with the exception of the MegaBall number, which is the last number entered) the user will receive a message to this effect and will be requested to reenter the number. This is the same for the second through fifth numbers.
When entering the MegaBall number, if the number entered IS NOT between 0 and 15, the user will receive a message to this effect and asked to reenter the number. One message will display if the number entered is less than 1, and a different message if the number entered is greater than 15.
The following MUST be included in the program:
You must have multiple classes. One class must include the accessor/mutator methods, a readInput() method and a writeOutput() method. Name this first program “MegaMillion.java”.
The values of the first five numbers must be saved within an array. The first element of the array will equal the first number entered, the second element of the array will equal the second number entered, etc. However, the number entered is not to be added to the array unless it is both unique from the other numbers entered, and it also falls within the correct range of numbers.
The second program is to be named “MegaMillion Test.java” and will be responsible for creating a Powerball object and invoking the readInput() and writeOutput() methods located in the MegaMillion class. You are NOT to include anything else in this testing class. Only have it create a MegaMillion object and call the readInput() and writeOutput() method for this object. Points will be deducted if you include anything else in this class.
Explanation / Answer
import java.util.*;
public class MegaMillion
{
public int a[]=new int[5];
public void readInput()
{
int j,i=0,n;
Scanner scan = new Scanner(System.in);
while(true)
{
System.out.println("Enter number");
n=scan.nextInt();
if(n>0)
{
if(n<76)
{
for(j=0;j<=i;j++)
{
if(a[j]==n)
{
System.out.println("Pl. reenter the number");
}
else
{
a[i]=n;
}
}
}
else
{
System.out.println("Number should be less than 76");
}
}
else
{
System.out.println("Number should be Greater than 0");
}
i++;
if(i>4)
{
break;
}
}
}
public void writeOutput()
{
System.out.println("Numbers are:");
for(int i=0;i<5;i++)
{
System.out.println(a[i]);
}
}
}
class MeghaMillionTest
{
public static void main(String args[])
{
MegaMillion o= new MegaMillion();
o.readInput();
o.writeOutput();
}
}