Question

Java: Create a Product object: “Laptop”, $799.99 • Create a Product object: “Printer”, $219.99 • Print...

Java:

Create a Product object: “Laptop”, $799.99
• Create a Product object: “Printer”, $219.99
• Print the information about the products
• Change the price of the laptop to $999
• Change the price of the printer to $329.99
• Print the information about the products

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Product.java

public class Product{

private String item;

private double cost;

public Product(String item, double cost) {

super();

this.item = item;

this.cost = cost;

}

public String getItem() {

return item;

}

public void setItem(String item) {

this.item = item;

}

public double getCost() {

return cost;

}

public void setCost(double cost) {

this.cost = cost;

}

@Override

public String toString() {

return "Product [item=" + item + ", cost=" + cost + "]";

}

}

Driver.java

public class Driver {

public static void main(String[] args){

Product p1 = new Product("Laptop", 799.99);

Product p2 = new Product("Printer", 219.99);

System.out.println(p1);

System.out.println(p2);

p1.setCost(999);

p2.setCost(329.99);

System.out.println(p1);

System.out.println(p2);

}

}

**Comment for any further queries.?

Add a comment
Know the answer?
Add Answer to:
Java: Create a Product object: “Laptop”, $799.99 • Create a Product object: “Printer”, $219.99 • Print...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT