Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

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

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    For an assignment, my mission was to write a program that can calculate the capacity of a shipping container in 3 ways, using scanner. I need to compute the total number of boxes (of a user-given size) that will fit inside, how many boxes will fit in each dimension, and the total percentage-full the container will be. I'm relatively sure my math is correct, but the program won't compile and I'm just not seeing where the error is. Here's my source code:

    import java.util.Scanner;
    public class intermodal
    {
    public static void main(String [] args)
    {
    Scanner source = new Scanner (System.in);

    //Calculate capacity of shipping container
    int contLength = 5900;
    int contWidth = 2350;
    int contHeight = 2393;
    int contVolume = (contLength*contWidth*contHeight);

    //User enters box dimensions
    int boxLength;
    int boxWidth;
    int boxHeight;
    int boxVolume = (boxWidth*boxLength*boxHeight);

    //Max number of boxes that will fit inside the container
    int maxBoxes = contVolume/boxVolume;

    //Calculate how many boxes fit in each dimension
    int fitLength = 5900/boxLength;
    int fitWidth = 2350/boxWidth;
    int fitHeight = 2393/boxHeight;

    //Calculate percentage-full container will be
    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.");
    }
    }

    I can't find my boo-boo and I've been staring at it for hours. Suggestions are more than welcome before I go crazy.
    Last edited by RockDoc; January 29th, 2012 at 01:04 AM. Reason: Explained myself a little better


  2. #2
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

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

    Okay, first note that it is usually quite hard to find someone's errors without first posting your omelette ompile time errors, and sometimes people will not even look at your ode unless you have posted the errors or atleast tried to. Two, you should highlight your code with [code=Java][/code] tags. third you have to calculate information based on user input after you have gotten the user input. note that you can't use a variable you have not initialized (given a value to) yet.

    Alsoyou might want to look into basic String conc, and the other information provided at the link below.

    Lesson: Language Basics (The Java™ Tutorials > Learning the Java Language)
    Last edited by Tjstretch; January 29th, 2012 at 02:11 AM.

Similar Threads

  1. Error while compile
    By when im gone in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 7th, 2012, 10:53 AM
  2. Remaining compile errors: no suitable method found for & cannot find symbol
    By ChuckLep in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 12th, 2011, 03:33 PM
  3. Compile Error, tried everything please help
    By cdub0 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 17th, 2011, 03:31 AM
  4. What's wrong. Compile Ok but error when execute.
    By hantuapi in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 1st, 2011, 05:33 AM
  5. [SOLVED] Picture won't go with the .jar (Wrong code or compile error?)
    By Fermen in forum Object Oriented Programming
    Replies: 3
    Last Post: March 15th, 2011, 05:22 PM