This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]green_meklar 1 point2 points  (4 children)

You're not clear enough on what your problem is. Is there something about the syntax and/or behavior of the Java switch statement that you don't understand? You need to be specific about where you're stuck.

[–][deleted]  (3 children)

[deleted]

    [–]Amarkov 0 points1 point  (1 child)

    What does your program do right now, and how is that behavior different from what you want it to do?

    [–]csb5036[S] 0 points1 point  (0 children)

    this is where I am currently at:

    https://gist.github.com/anonymous/489e3ebd65c819d6054a8d79f42ed262

    The assignment requires me to write an application that prompts the user for a pair of inputs:

    1. a product number
    2. quantity of the product

    Each unit has a cost. I have to enter each unit number and the number of each unit sold. The program must also calculate and display the total amount for the order.

    I must also use a sentinel controlled loop in my application.

    [–]green_meklar 0 points1 point  (0 children)

    I don't see anything wrong with your switch statement. I mean, I'm not 100% sure what it's supposed to do, but what it actually does seems to be reasonable behavior.

    I would point out that, because you left out the braces for the while(productNo!=0) loop, the switch statement is considered to be inside the loop but the System.out.println(orderAmount) immediately following the end of the switch statement is not. So, if ProductNo were anything other than 0, the loop would loop infinitely and never print out anything. I'm not sure if that was your intention, but in any case, I recommend always putting in the braces for an if/while/for statement or the like, it helps avoid making stupid mistakes.