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.


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

Results 1 to 2 of 2

Thread: Beginner question.

  1. #1
    Junior Member
    Join Date
    Jan 2020
    Thanked 0 Times in 0 Posts

    Default Beginner question.

    Hello all. First of all I wish to say that I'm an absolute newbie in Java and i Just started.
    So now I learn and have an issue that I cannot fix by my self and I cannot find solution in the Internet.
    So what is the issue.
    We have a task to calculate free space in a room and how many boxes can be puted in the room. It have to calculate the volume of the room, the volume of the boxes and check if there is enought space. The program work fine and make the calculations and if the space finish it give you messege with error for not enought space.
    So were is the issue. We have a case where if you write "Done" in the commant instead of number of boxes it shoud end the program, but it give me an error for the var type.
    As you will see in the code I have an int value in the while cycle that takes the number of boxes but i cannot make it to read the "Done" correct. I tried to convert it as string but it doesn't work. Also String input = scanner.nextLine(); before while for me looks somehow useless, because it want me give some input before start enter number of boxes.

    I'm open for more questions and hope to explain it well.

    --- Update ---

    here is the code: Here ait the code: https://www.codepile.net/pile/1KD4d6KX

  2. #2
    Junior Member
    Join Date
    Jan 2020
    Thanked 0 Times in 0 Posts

    Default Re: Beginner question.

    So, a little update:
    I found an answer, but i really don't like it, because I make Done check 2 times. I'm sure there is some better way.
    Here is the while cycle:

    String input ="";

    while (!input.equals("Done")) {
    System.out.print("Enter number of boxes ");
    input = scanner.nextLine();
    if (!input.equals("Done")) {
    int numberOfBoxes = Integer.parseInt(input);
    //1 box = 1 cubic meeter
    totalUsedSpace = totalUsedSpace + numberOfBoxes;

    if (houseVolume <= totalUsedSpace) {
    int spaceNeeded = totalUsedSpace - houseVolume;
    System.out.println("No more free space! You need " + spaceNeeded + " Cubic meters more");
    notEnoughtSpace = true;

Similar Threads

  1. Beginner's question about inheritance
    By waltforme in forum Object Oriented Programming
    Replies: 5
    Last Post: July 8th, 2014, 10:08 AM
  2. [SOLVED] Beginner question
    By jwillett29 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: June 24th, 2014, 05:01 PM
  3. [SOLVED] Beginner question about setHorisontalAlignment!
    By oskar.svard in forum AWT / Java Swing
    Replies: 6
    Last Post: November 27th, 2012, 08:04 PM
  4. Beginner Question
    By jrt224 in forum Loops & Control Statements
    Replies: 1
    Last Post: March 10th, 2011, 12:56 PM
  5. beginner's question
    By bardd in forum Java Theory & Questions
    Replies: 5
    Last Post: September 14th, 2010, 04:02 PM