I am having serious trouble and i don't know what exactly I'm doing wrong can someone please help. Here is the question ?

In this assignment you will 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.

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.

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.

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;
 }
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

 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");

}
}

Did you copy the code form a handout? If so you definitely copied it wrong. look at lines 45-58. Thats pseudo code. Thats what your prof wants you to implement. You have shown squat for effort.

I agree I have worked on it more. Here goes a better look

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");

}
}

When i compile the MegaBallTest I have four errors which said the operator cannot be applied.

In your MegaBallTest.java, n1 is NOT double, it is a MEGABALL. So you cannot compare it to 0 or 56.

This article has been dead for over six months. Start a new discussion instead.