aspose file tools*
The moose likes Beginning Java and the fly likes java programing homework help! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java programing homework help!" Watch "java programing homework help!" New topic
Author

java programing homework help!

todd stolz-schroeder
Greenhorn

Joined: Feb 08, 2010
Posts: 7
i really need help with my homework


this is what i have to do

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:

ITEM
COST
QUANTITY

Apple
$0.25/each
3

Cheese
$3.99/lb
0.5 lb

Bread
$1.19/loaf
1



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!


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39788
    
  28
Welcome to JavaRanch

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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39788
    
  28
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.
todd stolz-schroeder
Greenhorn

Joined: Feb 08, 2010
Posts: 7
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?

this is the code i have so far


Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18978
    
  40

todd stolz-schroeder wrote: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?


Well, do you have the budget value stored somewhere? Is it a number? And if not can you convert it to a number? And finally, have you looked at the java comparison operators?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Greg Stevens
Ranch Hand

Joined: Jul 23, 2009
Posts: 41
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?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39788
    
  28
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java programing homework help!