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

This must be done in Java . In this assignment you will create a console (standa

ID: 3824216 • Letter: T

Question

This must be done in Java.

In this assignment you will create a console (standalone) application. This program will allow you to select numbers for the "Lucky ForLife" Lottery game For the first 5 numbers you will be requested to enter a number that is greater than zero and less than 49 since the first 5 numbers on the "Lucky For Life" lottery must be between 1-48. However, there's a catch! Each of these five numbers must be different. The following figure shows a sample screenshot for the first 3 numbers

Explanation / Answer

LuckyBallForLife.java:

import java.util.*;
class LuckyForLife
{
    boolean[] l = new boolean[49];
    int powerball;
    // Print the data to Console
    public void WriteOutput()
    {
       System.out.println("Your power ball numbers are ");
       for (int i = 0; i < 49; i++)
       {
          if (l[i] == true)
              System.out.println((i+1)+" ");
       }
       System.out.println(" and the Powerball number is "+powerball);
      
    }
    // Taking Input from Console
    public void ReadInput()
    {
       Scanner sc = new Scanner(System.in);
       for (int i = 0; i < 49; i++)
           l[i] = false;
       int j = 1;
       while (true)
       {
          System.out.print("Please enter number " + j + " which should be > 0 and less than 49: ");
          int n = sc.nextInt();
          // if number is invalid
          if (n <= 0 || n >= 49)
          {
             if (n <= 0)
                 System.out.println("Number " + j + " must be greater than zero");
             else
                 System.out.println("Number " + j + " must be less than 49");
          }
          // the number is already repeated
          else if (l[n-1] == true)
              System.out.println("Number " + j +" must be different from previous numbers");
          else
          {
             l[n-1] = true;
             j += 1;
          }
          // if we have entered 5 numbers
          if (j == 6)
              break;
       }
       while (true)
       {
          System.out.println("Please enter a number that is > 0 and less than 18 for your lucky Powerball number");
          // read a value between 0 and 18
          int p_ball = sc.nextInt();
          if (p_ball <= 0 || p_ball >= 18)
          {
             if (p_ball <= 0)
                 System.out.println("The Powerball must be greater than zero");
             else
                 System.out.println("The Powerball must be less than 18");
          }
          else
          {
             powerball = p_ball;
             break;
          }
       }
    }
}

LuckyBallForLifeDemo.java:

class LuckyForLifeDemo
{
    public static void main(String[] args)
    {
       LuckyForLife powerball = new LuckyForLife();
       powerball.ReadInput();
       powerball.WriteOutput();
    }
}

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