This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
    Bookmark Topic Watch Topic
  • New Topic

Help Please I need help on a program!

 
Rob Samberg
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi - This is my first semester - I'm taking intro to Java and I'm supposed to write a program that sets a price for a toaster and then another toaster at 5% less and I'm supposed to test it.
Can someone just push me in the right direction please?
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Report post to moderator
Ok. Do you have an IDE? Have you installed Java? Do you need help with the code or all the way down to setting up the development environment?
 
Rob Samberg
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi, I need help with the code.
I have no I idea where to begin.
All I have is:

public class Product

Here, I'll just write what the assignment says.
Implement a class Product. A product has a name and a price, for example new Product("Toaster" , 29.95). Supply methods getName, getPrice, and setPrice. Write a program that makes twor products, prints the name and price, reduces their prices by $5.00, and then prints them again.

Anyway, that's what it says in the book.
Then my teacher wants me to:
Exercise P3.8 on page-99 of the text. Produce a neat self-explanatory output as
desired by the problem description. When you decrease the price of a product, first
use the getPrice() method to get its price, and then setPrice method to set its
price to a new value.

Organize the two java classes (testProduct and Product) in two different files.

Can you help please? I have no idea where to even begin!
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Report post to moderator

is a good start. Now you should write a constructor and some appropriate getX() and setX() methods (i.e. getPrice(), setPrice()). No one here will do the work for you, especially homework, but they will help you along the way if you get stuck. Are you familiar with writing constructors and methods?
 
Rob Samberg
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Report post to moderator
I'm working on it. I'll add some stuff and see what you guys think. Thanks.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Continue this discussion here.
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic