Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3450912
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:05:42+00:00 2026-05-18T09:05:42+00:00

I am having problems with my java assignment. I have been working on it

  • 0

I am having problems with my java assignment. I have been working on it for 2 weeks and could really use some help.

Here is the problem:

  1. Create a console (standalone) application. This program will allow
    you to select MegaBall lottery
    numbers. For the first 5 numbers you
    will be requested to enter a number
    that is greater than zero and less
    than or equal to 56. However, there’s
    a catch! Each number must be
    different.

  2. When any of the first five numbers is less than 0 or greater than 56 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 less than 1 is entered and a
    different message if a number greater
    than 56 is entered.

    If the
    number is the same as any number
    entered before it (with the exception
    of the megaball number) the user will
    receive a message to this effect and
    asked to reenter the number. This is
    the same for the second through fifth
    numbers. I typed in the same number a
    couple of times so you will see what
    occurs when I do.

  3. When entering the megaball number, if the number entered IS NOT between 1
    and 46 then the user will receive a
    message to this effect and asked to
    reenter the number. One message will
    display if the number is less than 1,
    and a different if the number is
    greater than 46.

The following MUST be included in the
program:

  • You must have multiple classes. One that contains the accessor and mutator
    methods, a readInput() method and a
    writeOutput() method. You will not use
    the mutator methods but include them
    anyway to show that you know how to
    write them. Name this first program
    “Megaball.java”.
  • The second program is to be named “MegaballTest.java” and will be
    responsible for creating a Megaball
    object and calling the writeOutput()
    and readInput() methods from the
    Megaball class.

Here is my solutions:

import java.util.Scanner;

public class Megaball
{
 Scanner scan = new Scanner(System.in);
 double n1, n2, n3, n4, n5, n6;
 double Num;
 String readInput;
 String writeOutput;

 public Megaball()
 {
  n1 = 0;
  n2 = 0;
  n3 = 0;
  n4 = 0;
  n5 = 0;
  n6 = 0;
 }

 public Megaball(double n1, double n2, double n3, double n4, double n5, double n6)
 {
  this.n1 = n1;
  this.n2 = n2;
  this.n3 = n3;
  this.n4 = n4;
  this.n5 = n5;
  this.n6 = n6;
 }

 public double getNum()
 {
  return Num;
 }

 public void setNum(double n1, double n2, double n3, double n4, double n5, double n6)
 {
  this.Num = Num;
 }

 public String readInput()
 {
  return readInput;
 }

 public String writeOutput()
 {
  return writeOutput;
 }

}




public class MegaballTest
{
 public static void main(String[] args)
 {
  Megaball n1 = new Megaball(0,0,0,0,0,0);
  Megaball n2 = new Megaball(0,0,0,0,0,0);
  Megaball n3 = new Megaball(0,0,0,0,0,0);
  Megaball n4 = new Megaball(0,0,0,0,0,0);
  Megaball n5 = new Megaball(0,0,0,0,0,0);
  Megaball n6 = new Megaball(0,0,0,0,0,0);

 do
 {
 System.out.println("Please enter your 1st number which is between 0 and 56");
 if (n1 < 0 || n1 > 56)
 System.out.println("Number must be between 0 and 56");
 }while (n1 < 0 || n1 > 56);
 System.out.println("Please enter your 2nd number which is between 0 and 56");

}
}

On the test… I wanted to make sure the first number worked before I did the rest. Here is the error I keep getting:

G:\MegaballTest.java:15: operator < cannot be applied to Megaball,int
 if (n1 < 0 || n1 > 56)
        ^
G:\MegaballTest.java:15: operator > cannot be applied to Megaball,int
 if (n1 < 0 || n1 > 56)
                  ^
G:\MegaballTest.java:17: operator < cannot be applied to Megaball,int
 }while (n1 < 0 || n1 > 56);
            ^
G:\MegaballTest.java:17: operator > cannot be applied to Megaball,int
 }while (n1 < 0 || n1 > 56);
                      ^
4 errors

Tool completed with exit code 1

Thanks so much!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:05:42+00:00Added an answer on May 18, 2026 at 9:05 am
    1. Create a console (standalone) application. This program will allow
      you to select MegaBall lottery
      numbers. For the first 5 numbers you
      will be requested to enter a number
      that is greater than zero and less
      than or equal to 56. However, there’s
      a catch! Each number must be
      different.

    There is a sequence here and the values are integers. Consider the use an array (int[]) or a List (ArrayList<Integer>).

    1. When any of the first five numbers is less than 0 or greater than 56 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 less than 1 is entered and a
      different message if a number greater
      than 56 is entered.

      If the
      number is the same as any number
      entered before it (with the exception
      of the megaball number) the user will
      receive a message to this effect and
      asked to reenter the number. This is
      the same for the second through fifth
      numbers. I typed in the same number a
      couple of times so you will see what
      occurs when I do.

    Consider the following member variable:

    ArrayList<Integer> numbers; (using an ArrayList is simpler to “grow”).

    Then consider the functions int readNumber(): Perform the above logic (reading from input and displaying the messages). Returns -1 if an invalid number is selected, else returns the number in the appropriate range. Inside readNumber, make sure the number does not currently exist in the numbers list (remember, numbers is a member variable).

    1. When entering the megaball number, if the number entered IS NOT between 1
      and 46 then the user will receive a
      message to this effect and asked to
      reenter the number. One message will
      display if the number is less than 1,
      and a different if the number is
      greater than 46.

    The mega-ball is different in that it can be a repeat and the range is different.

    So, consider the function int readPowerballNumber(): Perform the above logic (reading from input and displaying the messages). Returns -1 if an invalid number is selected, else returns the number in the appropriate range.

    Now, having those two, the following pseduo-code can be employed:
    This might be the code in the readInput() member. Remember that numbers is a member variable. Also note that it farms out the work to the “helper” methods which employ the logic for reading and displaying the warning, etc.

    set numbers = an empty list
    
    while have less than 5 numbers:
      number = readNumber()
      if number is not -1:
        append number to numbers     
    
    while have less than 6 numbers:
      number = readPowerballNumber()
      if number is not -1:
        append number to numbers
    
    // at this point, all 6 numbers are valid and loaded
    // you may then call `writeOutput()` to write all the numbers
    

    The following MUST be included in the
    program:

    • You must have multiple classes. One that contains the accessor and mutator
      methods, a readInput() method and a
      writeOutput() method. You will not use
      the mutator methods but include them
      anyway to show that you know how to
      write them. Name this first program
      “Megaball.java”.

    I have no idea why this “requirement” is here. Do what your teacher wants.
    However, note that readInput() and writeOutput() are methods and not Strings (as you currently have in code).

    • The second program is to be named “MegaballTest.java” and will be
      responsible for creating a Megaball
      object and calling the writeOutput()
      and readInput() methods from the
      Megaball class.

    Happy coding.

    Note: The above merely describes how to “load” a Megaball number sequence into an ArrayList<Integer>. I would make a constructor which turns the number sequence (after you “build it”) into a Megaball object itself (and thus have a Megaball be immutable. However, make sure to adjust for your teachers grading habits. Perhaps the above methods could be in a MegaballBuilder, if it earns some bonus points 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a small problem in Java. I have an interface called Modifiable. Objects
I'm having a problem using the java.text.MessageFormat object. I'm trying to create SQL insert
I have recently started having problems with TortoiseCVS, or more specifically with plink, the
Im having problems displaying records to my view when passing viewdata to a user
Im having problems building a query with the linq to sql data query expression
I'm having problems using textures that are larger than the OpenGL window or the
I'm having problems deciding on what is the best way is to handle and
I am having problems getting text within a table to appear centered in IE.
I am having problems manually looping through xml data that is received via an
I am having problems converting a string in the format yyyy-MM-ddZ using VB.net. For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.