In this assignment you will create a console standalone appl

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 between 1-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 enteredis 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 number.

- 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 numberl which should be 0 and less than 76 Number must be greater than zero Please enter numberl which should be 0 and less than 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 number2 which should be 0 and less than 76 Number 2 must be less than 76 Please enter number2 which should be 0 and less than 76 Number2 must be different from number1 Please enter number2 which should be 0 and less than 76

Solution

Using the below Program you can be able to acquire the required output. As mentioned in the instructions, i have used MegaMillionTest only to create the object and call the methods. The main login resides with the Program MegaMillion.java

/********************************************/
/*FILE NAME       :MegaMillionTest.java           */
/********************************************/
public class MegaMillionTest {

   /**
   * @param args
   */
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       MegaMillion mm=new MegaMillion();
       mm.readInput();
       mm.writeOutput();
   }

}

/********************************************/
/*FILE NAME       :MegaMillion.java           */
/********************************************/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class MegaMillion {

   /**
   * @param args
   */
   BufferedReader br=null;
   int[] mega_million_array=null;
   int lucky_number=0;
  
   public MegaMillion()
   {
       br = new BufferedReader(new InputStreamReader(System.in));
       mega_million_array=new int[5];
   }

   public int readConsoleInput()
   {
       int input = 0;
       try
       {
           input=Integer.parseInt(br.readLine());
       }
       catch (NumberFormatException e)
       {
           e.printStackTrace();
           //System.out.println(\"Please enter numbers only\");
       }
       catch (IOException e)
       {
           e.printStackTrace();
       }
       return input;
   }
  
   public void readInput()
   {
       boolean array_loading=true;
       boolean lucky_loading=true;
      
       int i=0;
      
       for(int j=0;j<5;j++)
           mega_million_array[i]=0;
      
       while(array_loading)
       {
           System.out.println(\"Please enter number\"+(i+1)+\" which should be > 0 and less than 76\");
          
           int temp_input=readConsoleInput();
          
           String cmp_prsnt_list=\"\";
           for(int j=0;j<5;j++)
           {
               if(temp_input==mega_million_array[j])
               {
                   cmp_prsnt_list+=j+\"-\";
               }
           }
          
           if(temp_input<=0)
           {
               System.out.println(\"Number\"+(i+1)+\" should be greater than 0\ \");
           }
           else if(temp_input>=76)
           {
               System.out.println(\"Number\"+(i+1)+\" should be less than 76\ \");
           }
           else if(!cmp_prsnt_list.equals(\"\"))
           {
               String[] numberlist=cmp_prsnt_list.split(\"-\");
              
               String tempvalue=\"\";
              
               for(int k=0;k<numberlist.length;k++)
               {
                   tempvalue+=\"number\"+numberlist[k]+\" and \";
               }
              
               if (tempvalue.endsWith(\"and \"))
               {
                   tempvalue = tempvalue.substring(0, tempvalue.length() - 4);
               }
               System.out.print(\"Number\"+(i+1)+\" must be different from \"+tempvalue+\"\ \ \");
              
           }
           else
           {
               mega_million_array[i]=temp_input;
               if(i==4)
                   array_loading=false;
               i++;
           }
       }
      
       while(lucky_loading)
       {
           System.out.println(\"Please enter a number that is > 0 and less than 16 for your lucky mega number\");
          
           int temp_input_lucky=readConsoleInput();
          
           if(temp_input_lucky<=0)
           {
               System.out.println(\"The Mega number must be greater than 0\ \");
           }
           else if(temp_input_lucky>=16)
           {
               System.out.println(\"The power ball number must be less than 16\ \");
           }
           else
           {
               lucky_loading=false;
               lucky_number=temp_input_lucky;
           }
       }
   }
  
   public void writeOutput()
   {
       System.out.print(\"Your Mega million Numbers are \");
       for(int i=0;i<5;i++)
           System.out.print(mega_million_array[i]+\" \");
       System.out.print(\"and the mega ball number is \"+lucky_number+\"\ \");
   }

}

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 wi
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 wi
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 wi
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 wi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site