Question

In: Computer Science

In Java Please!! 6.21 LAB: Artwork label (modules) Define the Artist class in Artist.py with a...

In Java Please!!

6.21 LAB: Artwork label (modules) Define the Artist class in Artist.py with a constructor to initialize an artist's information. The constructor should by default initialize the artist's name to "None" and the years of birth and death to 0. Define the Artwork class in Artwork.py with a constructor to initialize an artwork's information. The constructor should by default initialize the title to "None", the year created to 0, and the artist to use the Artist default constructor parameter values. Add an import statement to import the Artist class. Add import statements to main.py to import the Artist and Artwork classes. Ex: If the input is: Pablo Picasso 1881 1973 Three Musicians 1921 the output is: Artist: Pablo Picasso (1881-1973) Title: Three Musicians, 1921 If the input is: Brice Marden 1938 -1 Distant Muses 2000 the output is: Artist: Brice Marden, born 1938 Title: Distant Muses, 2000

Solutions

Expert Solution

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change. 

If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.

Thank You!
===========================================================================

public class Artist {

    private String artistName;
    private int yearOfBirth;
    private int yearOfDeath;

    public Artist(String artistName, int yearOfBirth, int yearOfDeath) {
        this.artistName = artistName;
        this.yearOfBirth = yearOfBirth;
        this.yearOfDeath = yearOfDeath;
    }

    public Artist() {
        artistName = "None";
        yearOfBirth = 0;
        yearOfDeath = 0;
    }

    public String getArtistName() {
        return artistName;
    }

    public int getYearOfBirth() {
        return yearOfBirth;
    }

    public int getYearOfDeath() {
        return yearOfDeath;
    }

    public void printInfo() {
        if (yearOfDeath == -1) {
            System.out.println("Artist: " + getArtistName() + ", born " + getYearOfBirth());
        } else {
            System.out.println("Artist: " + getArtistName() + " (" + getYearOfBirth() +
                    "-" + getYearOfDeath() + ")");
        }
    }
}

============================================================

public class Artwork {

    private Artist artist;
    private String title;
    private int yearCreated;

    public Artwork(Artist artist, String title, int yearCreated) {
        this.artist = artist;
        this.title = title;
        this.yearCreated = yearCreated;
    }

    public Artwork(String title, int yearCreated) {
        this.title = title;
        this.yearCreated = yearCreated;
        artist = new Artist();
    }

    public Artwork() {
        title = "None";
        yearCreated = 0;
        artist = new Artist();
    }

    public String getTitle() {
        return title;
    }

    public int getYearCreated() {
        return yearCreated;
    }

    public Artist getArtist() {
        return artist;
    }

    public void printInfo() {
        artist.printInfo();
        System.out.println("Title: " + getTitle() + ", " + getYearCreated());
    }
}

============================================================

public class TestArtwork {

    public static void main(String[] args) {


        Artist picaso = new Artist("Pablo Picaso",1881,1973);
        Artwork musicians = new Artwork(picaso,"Three Musicians",1921);

        musicians.printInfo();


        Artist brice = new Artist("Brice Marden",1938,-1);
        Artwork muses = new Artwork(brice,"Distant Muses",2000);

        muses.printInfo();

    }
}

============================================================


Related Solutions

7.27 LAB: Artwork label (classes/constructors) Given main(), complete the Artist class (in files Artist.h and Artist.cpp)...
7.27 LAB: Artwork label (classes/constructors) Given main(), complete the Artist class (in files Artist.h and Artist.cpp) with constructors to initialize an artist's information, get member functions, and a PrintInfo() member function. The default constructor should initialize the artist's name to "None" and the years of birth and death to 0. PrintInfo() should display Artist Name, born XXXX if the year of death is -1 or Artist Name (XXXX-YYYY) otherwise. Complete the Artwork class (in files Artwork.h and Artwork.cpp) with constructors...
Lab to be performed in Java. Lab: 1.) Write a class named TestScores. The class constructor...
Lab to be performed in Java. Lab: 1.) Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Write a driver class to test that demonstrates that an exception happens for these scenarios 2.) Write a class named InvalidTestScore...
Define a JAVA class ISP. The class consists of the name of the subscription plan and...
Define a JAVA class ISP. The class consists of the name of the subscription plan and a method that display the plan. Derive a class DPlan from ISP. The DPlan will charge RM10 per Mbps subscribe and RM0.20 per GB used. Derive a class MPlan from ISP. The MPlan will charge RM5 per Mbps subscribe and RM0.80 per GB used. Display the plan and select the best plan.
Several modules of the GoHRM system were introduced in the class. Please choose one of the...
Several modules of the GoHRM system were introduced in the class. Please choose one of the following (or any others if you wish) to describe what you have learned. Then, please evaluate their functions in terms of areas such as the advantages and disadvantages, change of role of HR due to this function, comprehensiveness of this function, reporting, etc. Altogether, the answers should be not more than 100 words. 1 – Recruitment 2 – Leave management 3 – Payroll and...
For My Programming Lab - Java: Write a Temperature class that will hold a temperature in...
For My Programming Lab - Java: Write a Temperature class that will hold a temperature in Fahrenheit and provide methods to get the temperature in Fahrenheit, Celsius, and Kelvin. The class should have the following field: • ftemp: a double that holds a Fahrenheit temperature. The class should have the following methods : • Constructor : The constructor accepts a Fahrenheit temperature (as a double ) and stores it in the ftemp field. • setFahrenheit: The set Fahrenheit method accepts...
Define empty methods in Queue class using LinkedList class in Java ------------------------------------------------------------------------------- //Queue class public class...
Define empty methods in Queue class using LinkedList class in Java ------------------------------------------------------------------------------- //Queue class public class Queue{ public Queue(){ // use the linked list } public void enqueue(int item){ // add item to end of queue } public int dequeue(){ // remove & return item from the front of the queue } public int peek(){ // return item from front of queue without removing it } public boolean isEmpty(){ // return true if the Queue is empty, otherwise false }...
Define empty methods in Stack class using LinkedList class in Java ------------------------------------------------------------------------------- //Stack class public class...
Define empty methods in Stack class using LinkedList class in Java ------------------------------------------------------------------------------- //Stack class public class Stack{ public Stack(){ // use LinkedList class } public void push(int item){ // push item to stack } public int pop(){ // remove & return top item in Stack } public int peek(){ // return top item in Stack without removing it } public boolean isEmpty(){ // return true if the Stack is empty, otherwise false } public int getElementCount(){ // return current number...
In JAVA please... Define a class named Payment that contains an instance variable "paymentAmount" (non-static member...
In JAVA please... Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type double that stores the amount of the payment and appropriate accessor (getPaymentAmount() ) and mutator methods. Also create a method named paymentDetails that outputs an English sentence to describe the amount of the payment. Override toString() method to call the paymentDetails() method to print the contents of payment amount and any other details not included in paymentDetails(). Define a class named...
I need this done in JAVA. Define a class named Cash. The class contains the following...
I need this done in JAVA. Define a class named Cash. The class contains the following public elements: A Double stored property that contains the amount of money (dollars and cents) described by an object of the class. A read-only, computed property. It calculates and returns the minimum number of U.S. bills and coins that add up to the amount in the stored property.  The return value is an Int array of length 9 that contains (beginning with index 0 of...
We started creating a Java class for Car. In this lab we are going to complete...
We started creating a Java class for Car. In this lab we are going to complete it in the following steps: 1- First create the Car class with some required instance variables, such make, model, year, price, speed, maxSpeed, isOn, isMoving, and any other properties you like to add. 2- Provide couple of constructors for initializing different set of important properties, such as make, model, year, and price. Make sure that you do not repeat initialization of instance variables in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT