I'm trying to write a simple program that can calculate how many boxes of a given size can fit inside a shipping container in four ways; total number of boxes that will fit inside, and how many will fit by length/width/height, and then calculate the percentage-full the container is. DrJava is giving me error messages and refuses to compile the program, but I've been staring at it for hours and can't see the problem. Suggestions are welcome!
import java.util.Scanner;
public class SedlacekShawndaA1Q2test
{
public static void main(String [] args)
{
Scanner source = new Scanner (System.in);
int contLength = 5900;
int contWidth = 2350;
int contHeight = 2393;
int contVolume = (contLength*contWidth*contHeight);
int boxLength;
int boxWidth;
int boxHeight;
int boxVolume = (boxWidth*boxLength*boxHeight);
int maxBoxes = contVolume/boxVolume;
int fitLength = 5900/boxLength;
int fitWidth = 2350/boxWidth;
int fitHeight = 2393/boxHeight;
int capacity = (boxVolume*maxBoxes)/contVolume*100;
System.out.println("What is the length of your shipping box (in mm)?");
boxLength = keyboard.nextInt();
System.out.println("What is the width of your shipping box (in mm)");
boxWidth = keyboard.nextInt();
System.out.println("What is the height of your shipping box (in mm)?");
boxHeight = keyboard.nextInt();
System.out.println("If your box is" +boxLength "long x" +boxWidth "wide x" +boxHeight "high, you can fit:");
System.out.println(+fitLength "box(es) lengthwise" n\+fitWidth "box(es) across the width" n\+fitHeight "box(es) high");
System.out.println("for a total of" +maxBoxes "box(es) in a standard freight container.");
System.out.println("The container will be" +capacity "full.");
}
}
3 replies to this topic
#1
Posted 28 January 2012 - 09:48 PM
|
|
|
#2
Posted 28 January 2012 - 10:09 PM
What are your error messages?
#3
Posted 28 January 2012 - 10:19 PM
The errors are on lines 28 to 31, so the very end of the program.
28: ')' expected
28: not a statement
28: ';' expected
29: illegal character: \92
30: illegal start of expression
Basically, several of the above errors for each of lines 28 to 31. I'm just not seeing why I'm getting these errors because it doesn't seem that I should be.
28: ')' expected
28: not a statement
28: ';' expected
29: illegal character: \92
30: illegal start of expression
Basically, several of the above errors for each of lines 28 to 31. I'm just not seeing why I'm getting these errors because it doesn't seem that I should be.
#4
Posted 01 February 2012 - 05:04 PM
System.out.println("If your box is" +boxLength [b][COLOR="#FF0000"]+[/COLOR][/b]"long x" +boxWidth [b][COLOR="#FF0000"]+[/COLOR][/b] "wide x" +boxHeight [b][COLOR="#FF0000"]+[/COLOR][/b] "high, you can fit:");
It looks like you're missing several +'s throughout the rest of your program aswell.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









