Question: A Java question. Implement a subclass of Product called Painting . A Painting has a String instance variable, artist, in addition to description and price.

A Java question. Implement a subclass of Product called Painting. A Painting has a String instance variable, artist, in addition to description and price. These paintings are framed prints not originals.

Provide the instance variable and methods

1. public String getArtist() 2. public boolean sameAuthor( Painting other) returns true if the paintings have the same author. Otherwise false (You will have to use sameAuthor even though that does not make good sense for a painting.) 3. public String getDescription() returns the description of the Painting then a space and the Artist's name

Use @Override for the overridden getDescription method

plz just show me the answer of Painting.java , Thank you!

------------------------------------------------------------------------------------------------------------------------

The PaintingTester and the Product have be given as follow:

PaintingTester.java

public class PaintingTester { public static void main(String[] args) { //be sure Painting is a subclass of Product Product product = new Painting("The Starry Night", 95.0, "Van Gogh"); //instantiate some Paintings Painting lilies = new Painting("The Water Lily Pond", 85.0, "Monet"); Painting bridge = new Painting("The Japanese Footbridge", 120.0, "Monet"); Painting girl = new Painting("Girl with a Hoop", 100, "Renoir"); Painting child = new Painting("Child with a Dove", 150.0, "Picasso"); Painting starry = (Painting)product; //Get a Painting reference to the Painting System.out.println(lilies.sameAuthor(bridge)); System.out.println("Expected: true"); System.out.println(girl.sameAuthor(child)); System.out.println("Expected: false"); System.out.println(starry.getDescription()); System.out.println("Expected: The Starry Night Van Gogh"); System.out.println(girl.getDescription()); System.out.println("Expected: Girl with a Hoop Renoir"); System.out.println(lilies.getPrice()); System.out.println("Expected: 85.0"); System.out.println("Artist: " + starry.getArtist()); System.out.println("Expected: Van Gogh"); } } 

Product.java

/** * Models a Product that can increase and decrease in price */ public class Product { private double price; private String description; /** * Constructs a Product with a price and a description * @param thePrice the price of this Product * @param theDescription - the description of this product */ public Product(String theDescription, double thePrice) { price = thePrice; description = theDescription; } /** * Gets the price * @return the price of this Product object */ public double getPrice() { return price; } /** * Gets the description * @return the description of the Product object */ public String getDescription() { return description; } /** * Reduces the price of this product by the give percentage * @param percent the percentage to reduce the priice by */ public void reducePrice(double percent) { double reduction = price * percent / 100; price = price - reduction; } /** * Increases the price by the given percent * @param percent the percent to increase the price by */ public void increasePrice(double percent) { double increase = price * percent / 100; price = price + increase; } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!