Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Classes

 
Chris Carlson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 
Anupam Jain
Ranch Hand
Posts: 61
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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... )
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic