You are buying a picnic lunch to share with friends in the park. Write, compile, and test a Java class that will 1) ask for a budget amount 2) display the cost of each item for a lunch for three and 3) calculate and display the total price of all the items and determine and display whether you have exceeded your budget.
Lunch items will consist of apples, cheese, and bread. Use six class variables of the appropriate data type to hold the price (cost) and amount (quantity) of each item as indicated in the following table:
You will need additional class variables to hold the budget and total amounts.
Your program will ask the user for the budget amount through an input dialog box and then display the results in message dialog boxes. Hint: it might be easier to first create a String variable to hold all or part of the second parameter to the JOptionPane.showMessageDialog() method.
Your output should resemble the pictures below:
this is what i have so far, i need a little help with it. thanks!
Please use the Code button; it makes your code that much easier to read. Since you are new I shall edit your post with the Code button.
You will doubtless have realised we don't do other people's homework.
You seem to have made a start, so I suggest you write down with pencil and paper exactly how you are going to change the entry "5.32" into a number, and how you intend to change the number of apples into a price, etc. You want it in very simple terms, not using any long words. Once you have got that written down, you can call it pseudocode and that is easy to turn into real code.
Joined: Oct 13, 2005
You need some way of entering and recording how many apples and how much cheese you plan to eat. Don't hard-code 3 or 0.5 or 1 for 3 apples ½lb cheese and 1 loaf.
Joined: Feb 08, 2010
I figured out most of it, i just need help with a boolean to tell if the budget is over 3.94 for true and if its under its false.
Can someone send me in the right direction on how to write a boolean variable?
Do you know how to get a numeric value from a String representation? What kind of numeric value are you
expecting the user to input?
Also, I think lunch is a confusing name for your variable. I read it and I think it should contain a menu item or
or some type of food. I don't think this is your intention. What input exactly are you expecting from the user?
Joined: Oct 13, 2005
todd stolz-schroeder wrote: . . . tell if the budget is over 3.94 for true and if its under its false. . . .
Believe it or not, that will come out very simply if you use the very high-tech equipment I recommended yesterday. You may find something helpful in the Java™ Tutorials, too.
I also think you need some way to enter how many apples and how much cheese you intend to buy. You would use a very similar technique to entering your budget.
Another thing: why have you got all your code in the main method?