I'm taking a beginner course for Java programming. The current assignment I'm on is giving me some issues and I've been trying all day to figure out how to go about completing the assignment.
Here is the outline of the assignment:
Create a public class named PaintingHarness and a class below it in the same file named Painting. Programmers use the term "harness" to refer to a class that tests the functionality of another class. In this case, our harness class will have a main method in it where we can write code to test the Painting class. Structure your file the way it appears below:
public class PaintingHarness
{
public static void main(String[] args)
{
// put code here
}
}
class Painting
{
// put code here
}
And these are the instructions:
Continue to design the Painting class as follows:
Create fields for a painting's title, artist, medium (such as water color), and price.
Create four accessor methods (get) and four mutator methods (set), one pair for each of the fields.
Create a field to hold the gallery commission. This field cannot be set from outside the class. It is computed as 20% of the price, and should be set whenever the price is set. Put the code to calculate and set the commission in the setPrice() method.
Create a method called describe() that returns a String that contains the title, artist, medium, price, and commission of the painting in a presentable format. Each attribute should be clearly labeled, and the price and commission values should be displayed appropriately.
Back in the PaintingHarness class, write the code to accomplish the following tasks:
Create an instance of the Painting class and choose an appropriate variable name.
Ask the user for a painting's title, artist, medium, and price, calling the appropriate methods in the Painting object to set each attribute.
Call the Painting object's describe() method and display the String it returns out to the screen.
When the program runs, the user should see all of the data they entered reflected back to them as the Painting object "describes itself" on the screen. The gallery commission should also appear and be 20% of the price. Verify that everything is accurately described.
I'm really stumped. I've been trying to figure out how to continue but, I'm hitting a wall. If anyone can help me I'd greatly appreciate it.
Here is as far as I've gotten.
import java.util.Scanner; public class PaintingHarness { public static void main(String [] args) { Scanner input = new Scanner(System.in); System.out.println("Enter the title of the painting >>"); System.out.println("Enter the artist of the painting >>"); System.out.println("Enter the medium of the painting >>"); System.out.println("Enter the price of the painting >>"); } } class Painting { public String paintingTitle; public String paintingArtist; public String paintingMedium; public int paintingPrice; int commision; int commRate; commRate = .20 commision = paintingPrice * commRate; } public String getPaintingTitle() { return paintingTitle; } public void setPaintingTitle(String title) { paintingTitle = title; } public String getPaintingArtist() { return paintingArtist; } public void setPaintingArtist(String artist) { paintingArtist = artist; } public String getPaintingMedium() { return paintingMedium; } public void setPaintingMedium(String medium) { paintingMedium = medium; } public getPaintingPrice() { return paintingPrice; } public void setPaintingPrice(int price) { paintingPrice = price; } }