Jump to content

Code won't compile, but can't find the error....

- - - - -

  • Please log in to reply
3 replies to this topic

#1
RockDoc

RockDoc

    Newbie

  • Members
  • Pip
  • 2 posts
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.");
}
}

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
What are your error messages?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
RockDoc

RockDoc

    Newbie

  • Members
  • Pip
  • 2 posts
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.

#4
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
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