Question
[Java] I'm totally lost help me please Here's the problem: Implement a subclass of Product called Painting. A Painting has a String instance variable, artist,
[Java] I'm totally lost help me please
Here's the problem:
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
public String getArtist()
public boolean sameAuthor( Painting other) returns true if the paintings have the same author. Otherwise false (updated Apr 1. You will have to use sameAuthor even though that does not make good sense for a painting. I make a mistake in the implementation)
public String getDescription() returns the description of the Painting then a space and the Artist's name
Provide Javadoc. Use @Override for the overridden getDescription method
Use the following files:
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; } }
Here's my code;
import java.util.Arrays; public class Painting extends Product { private String artist; public Painting(String description, double price, String theArtist) { super(description, price); artist = theArtist; } public String getArtist() { return artist; } public boolean sameAuthor() { if(getArtist().equals(Product product)) { } } @Override public String getDescription() { String str = super.getDescription(); return str + " " + artist; } }
I'm not sure how to implement the sameAuthor method.
Please check your code using the link below. It has to exact same as the tester.
http://www.codecheck.it/files/16112801582mmmnphfjxw6xc3wokqnhiuhm
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started