Question

For Java please.Artwork. javaimport java.util.Scanner;public class ArtworkLabel {public static void main(String[] args)...


 Given main(). define the Artist class (in file Artist java) with constructors to initialize an artist's information, get methods, and a printlnfo()

 method. 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.

 Define the Artwork class (in file Artwork.java) with constructors to initialize an artwork's information, get methods, and a printinfo()

 method. The constructor should by default initialize the title to "None", the year created to 0. Declare a private field of type Artist in the

 Artwork class.


 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

Artwork. java

import java.util.Scanner;

public class ArtworkLabel {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);

String userTitle, userArtistName;
int yearCreated, userBirthYear, userDeathYear;

userArtistName = scnr.nextLine();
userBirthYear = scnr.nextInt();
scnr.nextLine();
userDeathYear = scnr.nextInt();
scnr.nextLine();
userTitle = scnr.nextLine();
yearCreated = scnr.nextInt();

Artist userArtist = new Artist(userArtistName, userBirthYear, userDeathYear);

Artwork newArtwork = new Artwork(userTitle, yearCreated, userArtist);

newArtwork.printInfo();
}
}

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

Artist.java

public class Artist {
// TODO: Declare private fields - artistName, birthYear, deathYear

// TODO: Define default constructor

// TODO: Define second constructor to initialize
// private fields (artistName, birthYear, deathYear)

// TODO: Define get methods: getName(), getBirthYear(), getDeathYear()

// TODO: Define printInfo() method
// If deathYear is entered as -1, only print birthYear

}

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

Artwork.java

public class Artwork {
// TODO: Declare private fields - title, yearCreated
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());
  
}

}
}


0 0
Add a comment Improve this question Transcribed image text
Answer #1
// File: Artist.java
public class Artist {

    private String artistName;
    private int birthYear;
    private int deathYear;

    public Artist() {
        artistName = "None";
        birthYear = 0;
        deathYear = 0;
    }

    public Artist(String artistName, int birthYear, int deathYear) {
        this.artistName = artistName;
        this.birthYear = birthYear;
        this.deathYear = deathYear;
    }

    public String getName() {
        return artistName;
    }

    public int getBirthYear() {
        return birthYear;
    }

    public int getDeathYear() {
        return deathYear;
    }

    public void printInfo() {
        System.out.print("Artist: ");
        System.out.print(artistName);
        if (deathYear == -1) {
            System.out.println(", born " + birthYear);
        } else {
            System.out.println(" (" + birthYear + "-" + deathYear + ")");
        }
    }
}
// File: Artwork.java
public class Artwork {

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

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

    public String getTitle() {
        return title;
    }

    public int getYearCreated() {
        return yearCreated;
    }

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

    public void printInfo() {
        artist.printInfo();
        System.out.println("Title: " + title + ", " + yearCreated);
    }
}
Add a comment
Know the answer?
Add Answer to:
For Java please.Artwork. javaimport java.util.Scanner;public class ArtworkLabel {public static void main(String[] args)...
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
  • 21.8 LAB: Artwork label (modules) python Define the Artist class in Artist.py with a constructor to...

    21.8 LAB: Artwork label (modules) python 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....

  • LAB: Book information (overriding member methods)

    10.15 LAB: Book information (overriding member methods)Given main() and a base Book class, define a derived class called Encyclopedia. Within the derived Encyclopedia class, define a printInfo() method that overrides the Book class' printInfo() method by printing not only the title, author, publisher, and publication date, but also the edition and number of volumes.Ex. If the input is:The Hobbit J. R. R. Tolkien George Allen & Unwin 21 September 1937 The Illustrated Encyclopedia of the Universe James W. Guthrie Watson-Guptill 2001 2nd 1the output is:Book Information:     Book Title: The Hobbit    Author: J. R. R. Tolkien    Publisher: George Allen & Unwin    Publication Date: 21 September 1937 Book Information:     Book Title: The Illustrated Encyclopedia of the Universe    Author: James W. Guthrie    Publisher: Watson-Guptill    Publication Date: 2001    Edition: 2nd    Number of Volumes: 1Note: Indentations use 3 spaces.BookInformation.javaimport java.util.Scanner; public class BookInformation {    public static void main(String[] args) {       Scanner scnr = new Scanner(System.in);       Book myBook = new Book();...

  • JAVA PROGRAMMING Given main(), complete the SongNode class to include the printSongInfo() method. Then write the...

    JAVA PROGRAMMING Given main(), complete the SongNode class to include the printSongInfo() method. Then write the Playlist class' printPlaylist() method to print all songs in the playlist. DO NOT print the dummy head node. Ex: If the input is: Stomp! 380 The Brothers Johnson The Dude 337 Quincy Jones You Don't Own Me 151 Lesley Gore -1 the output is: LIST OF SONGS ------------- Title: Stomp! Length: 380 Artist: The Brothers Johnson Title: The Dude Length: 337 Artist: Quincy Jones...

  • import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        //...

    import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        // TODO Auto-generated method stub        System.out.println("Welcome to the Triangle Maker! Enter the size of the triangle.");        Scanner keyboard = new Scanner(System.in);    int size = keyboard.nextInt();    for (int i = 1; i <= size; i++)    {    for (int j = 0; j < i; j++)    {    System.out.print("*");    }    System.out.println();    }    for (int...

  • THE ENTIRE CODE SHOULD BE IN JAVA Playlist (output linked list) Given main(), complete the SongNode...

    THE ENTIRE CODE SHOULD BE IN JAVA Playlist (output linked list) Given main(), complete the SongNode class to include the printSongInfo() method. Then write the Playlist class' printPlaylist() method to print all songs in the playlist. DO NOT print the dummy head node. Ex: If the input is: Stomp! 380 The Brothers Johnson The Dude 337 Quincy Jones You Don't Own Me 151 Lesley Gore -1 the output is: LIST OF SONGS ------------- Title: Stomp! Length: 380 Artist: The Brothers...

  • import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {   ...

    import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {        Student s1 = new Student();         Student s2 = new Student("Smith", "123-45-6789", 3.2);         Student s3 = new Student("Jones", "987-65-4321", 3.7);         System.out.println("The name of student #1 is ");         System.out.println("The social security number of student #1 is " + s1.toString());         System.out.println("Student #2 is " + s2);         System.out.println("the name of student #3 is " + s3.getName());         System.out.println("The social security number...

  • LAB: Instrument information (derived classes)

    10.14 LAB: Instrument information (derived classes)Given main() and the Instrument class, define a derived class, StringInstrument, for string instruments.Ex. If the input is:Drums Zildjian 2015 2500 Guitar Gibson 2002 1200 6 19the output is:Instrument Information:     Name: Drums    Manufacturer: Zildjian    Year built: 2015    Cost: 2500 Instrument Information:     Name: Guitar    Manufacturer: Gibson    Year built: 2002    Cost: 1200    Number of strings: 6    Number of frets: 19InstrumentInformation.javaimport java.util.Scanner; public class InstrumentInformation {    public static void main(String[] args) {       Scanner scnr = new Scanner(System.in);       Instrument myInstrument = new Instrument();       StringInstrument myStringInstrument = new StringInstrument();       String instrumentName, manufacturerName, stringInstrumentName, stringManufacturer;       int yearBuilt, cost, stringYearBuilt, stringCost, numStrings, numFrets;       instrumentName = scnr.nextLine();       manufacturerName = scnr.nextLine();       yearBuilt = scnr.nextInt();       scnr.nextLine();       cost = scnr.nextInt();       scnr.nextLine();       stringInstrumentName = scnr.nextLine();       stringManufacturer = scnr.nextLine();       stringYearBuilt = scnr.nextInt();       stringCost = scnr.nextInt();       numStrings = scnr.nextInt();       numFrets = scnr.nextInt();       myInstrument.setName(instrumentName);       myInstrument.setManufacturer(manufacturerName);       myInstrument.setYearBuilt(yearBuilt);       myInstrument.setCost(cost);       myInstrument.printInfo();       myStringInstrument.setName(stringInstrumentName);       myStringInstrument.setManufacturer(stringManufacturer);       myStringInstrument.setYearBuilt(stringYearBuilt);       myStringInstrument.setCost(stringCost);       myStringInstrument.setNumOfStrings(numStrings);       myStringInstrument.setNumOfFrets(numFrets);       myStringInstrument.printInfo();       System.out.println("   Number of strings: " + myStringInstrument.getNumOfStrings());       System.out.println("   Number of frets: " + myStringInstrument.getNumOfFrets());    } }Instrument.javapublic class Instrument {     protected String instrumentName;     protected String instrumentManufacturer;     protected int yearBuilt, cost;     public void setName(String userName) {...

  • Explain this java code, please. import java.util.Scanner; public class Program11 { public static void main(String[] args)...

    Explain this java code, please. import java.util.Scanner; public class Program11 { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); final int maxSize = 128; String[] titles = new String[maxSize]; int[] lengths = new int[maxSize]; int numDVDs = 0; String op; op = menu(stdIn); System.out.println(); while (!op.equalsIgnoreCase("q")) { if (op.equalsIgnoreCase("a")) { if (numDVDs < maxSize) numDVDs = addDVD(titles, lengths, numDVDs, stdIn); } else if (op.equalsIgnoreCase("t")) searchByTitle(titles, lengths, numDVDs, stdIn);    else if (op.equalsIgnoreCase("l")) searchByLength(titles, lengths, numDVDs, stdIn); System.out.println('\n');...

  • Java Here is the template public class ShiftNumbers { public static void main(String[] args) { // TODO:...

    Java Here is the template public class ShiftNumbers { public static void main(String[] args) { // TODO: Declare matrix shell size // TODO: Create first row // TODO: Generate remaining rows // TODO: Display matrix } /** * firstRow * * This will generate the first row of the matrix, given the size n. The * elements of this row will be the values from 1 to n * * @param size int Desired size of the array * @return...

  • import java.util.Scanner; public class Lab6d { public static void main(String[] args) {    Scanner scnr =...

    import java.util.Scanner; public class Lab6d { public static void main(String[] args) {    Scanner scnr = new Scanner(System.in); // TODO: get user choice    // TODO: call printTable method passing choice as the parameter    } public static void printTable(int stop) { // TODO: print header    // TODO: loop to print table rows up to stop value    } Write a Java program where the main () method prompts the user to select an integer value between 1 and...

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