This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Java Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Classes" Watch "Java Classes" New topic
Author

Java Classes

Chris Carlson
Greenhorn

Joined: Feb 11, 2010
Posts: 5
The question states:

Write a program that uses the Purchase Class to set the following prices:

Oranges: 10 for $2.99
Eggs: 12 for $1.69
.
.
.
Then calculate the cost of each of the following five items and the total bill:

2 dozen oranges
3 dozen eggs
.
.
.
If I have the completed class and I have written the main program to ask the user to enter the fixed amount and price for the item and then asks to enter how many you purchased and then calculates the total cost is this what it is asking or does it want me to set the initial amount and cost in the program? If so, how do you make set items such as Oranges: 10 for $2.99 in the main program? Any ideas?
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
Chris:

Please post your source code (and where you got it from). It's hard to diagnose problems without having code to look at. Also, a more helpful subject line is needed: this question really isn't a general question about classes in Java.

John.
Chris Carlson
Greenhorn

Joined: Feb 11, 2010
Posts: 5

Anupam Jain
Ranch Hand

Joined: Mar 16, 2010
Posts: 61

Chris Carlson wrote:
If I have the completed class and I have written the main program to ask the user to enter the fixed amount and price for the item and then asks to enter how many you purchased and then calculates the total cost is this what it is asking or does it want me to set the initial amount and cost in the program? If so, how do you make set items such as Oranges: 10 for $2.99 in the main program? Any ideas?


The question that you've asked Chris, is about the approach one should take to solve the question. (Am I right..? )

As far as I understand from the question.... it says use class to set price... so it should use a separate class and set price to/ from it.

The code implementation that you've posted looks absolutely correct to me as far as the approach is concerned.. (that means without considering any programming errors... )


SCJP-6.0 OCPJWCD-5.0
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Classes