new
double weight = -1; //change up at the top
while(weight < 0)
{
if(weight < 0)
{
System.out.println("Please enter a positive number.");
weight= JLiveRead.readLineDouble();
}
if(wieght >= 0)
break;
}
I got 2 and 3 but the above does not work, it gets to if(weight >= 0) and it says weight is undefined.
public class ConsoleIOTest {
public static void main(String[] args){
System.out.println("This program is designed to calaculate how many boxes of Oaties breakfast");
System.out.println("cereal are contained in one metric ton and the weight of one box of Oaties in");
System.out.println("metric tons. It will also calculate the number of whole cases and extra boxes");
System.out.println("of Oaties in one metric ton.");
System.out.println();
System.out.println("All of this will be done using the weight you supply for one box of Oaties.");
System.out.println();
System.out.println();
double x;
x= 35273.92;
double weight=-1 ;
System.out.println("Please enter the weight of one box of Oaties ceral in ounces.");
System.out.println("eg.(2, 5.05, 67.2, etc):");
System.out.println();
weight= JLiveRead.readLineDouble();
System.out.println();
while(weight < 0)
{
if(weight < 0)
{
System.out.println("Please enter a positive number.");
weight= JLiveRead.readLineDouble();
}
if(wieght >= 0)
break;
}
System.out.println("You said there are " + weight + " ounces in one box of Oaties");
System.out.println();
double boxesy= x/weight;
int boxesz= (int) boxesy;
System.out.println("There are " + boxesz+1 + " boxes of Oaties in one metric ton.");
System.out.println();
System.out.println("One box of Oaties weighs " + weight/x + " metric tons.");
System.out.println();
System.out.println("Please enter the number of Oaties boxes in a case.");
System.out.println("eg.(2, 5, 67, etc):");
System.out.println();
double y= JLiveRead.readLineDouble();
System.out.println("You said there are " + y + " boxes of Oaties in one case.");
System.out.println();
double caseweight= weight*y;
double cases1= x/caseweight;
int cases2= (int) cases1;
double boxes1= x-(cases2*caseweight);
double boxes2= boxes1/weight;
int boxes3= (int) boxes2;
int boxes4= (boxes3+1);
System.out.println();
System.out.println("There are " + cases2 + " cases and " + boxes4 + " boxes of Oaties in one metric ton.");
System.out.println();
System.out.println("Thank You for using this program. =)");
}
}