Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE READ ALL OF THE INSTRUCTIONS BEFORE ANSWERING! In this assignment you wil

ID: 3571299 • Letter: P

Question

PLEASE READ ALL OF THE INSTRUCTIONS BEFORE ANSWERING!

In this assignment you will create a console (standalone) application. This program will allow you to select Mega Million 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. The following figure shows a sample screenshot:

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 use Eclipse to create this assignment.

? 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 “MegaMillionTest.java” and will be responsible for creating a MegaMillion 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

Please enter number1 which should be 0 and less than 76 Number 1 must be greater than zero Please enter number 1 which should be 0 and lesa than 76 76 Numberl must be less than 76 Please enter numberl which should be 0 and less than 76 Please enter number2 which should be 0 and less than 76 Number 2 must be greater than zero Please enter number which should be 0 and leas than 76 76 Number2 st be less than 76 Please enter number which should be 0 and less than 76 Number must be different from numberl Please enter number2 which should be 0 and less than 76

Explanation / Answer

import java.util.Scanner;

public class MegaMillion {
private int[] megaMillion;
private int megaBallNum;

public MegaMillion() {

megaMillion = new int[5];

}

  
public int[] getMegaMillion() {
return megaMillion;
}

  
public void setMegaMillion(int[] megaMillion) {
this.megaMillion = megaMillion;
}


public int getMegaBallNum() {
return megaBallNum;
}


public void setMegaBallNum(int megaBallNum) {
this.megaBallNum = megaBallNum;
}


public void readInput() {

int count = 0;
Scanner scanner = new Scanner(System.in);

for (int i = 0; i < megaMillion.length;) {
System.out.println("please enter number" + (i + 1)
+ " which would be > 0 and less than 76");
int n = scanner.nextInt();

if (n <= 0)
System.out.println("Number" + (i + 1)
+ " must be greater than zero");
else if (n >= 76)
System.out
.println("Number" + (i + 1) + " must be less than 76");
else if (i != 0) {
if (isValidNum(n, i))
megaMillion[i++] = n;

} else {
megaMillion[i++] = n;
}
}
boolean flag = true;
do {

System.out
.println("please enter a number which would be > 0 and less than 16 for lucky metga number");
int n = scanner.nextInt();
if (n <= 0)
System.out.println("The mega number must be greater than zero");
else if (n >= 16)
System.out.println("The mega number must be less than 16");
else {

for (int i = 0; i < megaMillion.length; i++) {
if (n == megaMillion[i]) {
megaBallNum = n;
flag = false;
break;
}
}

}
} while (flag);

}

public void writeOutput() {
System.out.println(" Your mega million numbers are ");
for (int i = 0; i < megaMillion.length; i++) {
System.out.print(" " + megaMillion[i]);
}
System.out.println(" and the mega ball number is " + megaBallNum);

}

  
private boolean isValidNum(int number, int count) {

for (int i = 0; i < count; i++) {
if (number == megaMillion[i])
return false;
}
return true;

}

}

public class MegaMillionTest {

  
public static void main(String[] args) {

MegaMillion megaMillion = new MegaMillion();
megaMillion.readInput();
megaMillion.writeOutput();
}

}

SAMPLE OUTPUT:

please enter number1 which would be > 0 and less than 76
0
Number1 must be greater than zero
please enter number1 which would be > 0 and less than 76
1
please enter number2 which would be > 0 and less than 76
76
Number2 must be less than 76
please enter number2 which would be > 0 and less than 76
2
please enter number3 which would be > 0 and less than 76
3
please enter number4 which would be > 0 and less than 76
4
please enter number5 which would be > 0 and less than 76
5
please enter a number which would be > 0 and less than 16 for lucky metga number
0
The mega number must be greater than zero
please enter a number which would be > 0 and less than 16 for lucky metga number
16
The mega number must be less than 16
please enter a number which would be > 0 and less than 16 for lucky metga number
2

Your mega million numbers are
1 2 3 4 5 and the mega ball number is 2

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote