Answer to Question #196590 in Java | JSP | JSF for rupa

Question #196590

Create a class named MusicalComposition that contains fields for title, composer, and year written. Include a constructor that requires all three values and an appropriate display function. The child class NationalAnthem contains an additional field that holds the name of the anthem’s nation. The child class constructor requires a value for this additional field. The child class also contains a display function. Write a main() function in class MusicDemo that instantiates objects of each class and demonstrates that the functions work correctly.


1
Expert's answer
2021-05-21T10:52:33-0400


public class MusicalComposition {
	private String title;
	private String composer;
	private int yearWritten;


	public MusicalComposition(String title, String composer, int yearWritten) {
		this.title = title;
		this.composer = composer;
		this.yearWritten = yearWritten;
	}


	
	public String getTitle() {
		return title;
	}


	public void setTitle(String title) {
		this.title = title;
	}


	public String getComposer() {
		return composer;
	}


	public void setComposer(String composer) {
		this.composer = composer;
	}


	public int getYearWritten() {
		return yearWritten;
	}


	public void setYearWritten(int yearWritten) {
		this.yearWritten = yearWritten;
	}


	@Override
	public String toString() {
		return "MusicalComposition [title=" + title + ", composer=" + composer + ", yearWritten=" + yearWritten + "]";
	}


}

public class NationalAnthem extends MusicalComposition{
	private String nameOfTheAnthemsNation;


	public NationalAnthem(String title, String composer, int yearWritten, String nameOfTheAnthemsNation) {
		super(title, composer, yearWritten);
		this.nameOfTheAnthemsNation = nameOfTheAnthemsNation;
	}


	public String getNameOfTheAnthemsNation() {
		return nameOfTheAnthemsNation;
	}


	public void setNameOfTheAnthemsNation(String nameOfTheAnthemsNation) {
		this.nameOfTheAnthemsNation = nameOfTheAnthemsNation;
	}


	@Override
	public String toString() {
		return "NationalAnthem [nameOfTheAnthemsNation=" + nameOfTheAnthemsNation + "]";
	}
}

public class MusicDemo {


	public static void main(String[] args) {
		 MusicalComposition  musicalComposition=new  MusicalComposition("The Star-Spangled Banner","Francis Scott Key",1814);
		 System.out.println(musicalComposition);
		 NationalAnthem nationalAnthem=new NationalAnthem("The Star-Spangled Banner","Francis Scott Key",1814,"USA");
		 System.out.println(nationalAnthem);
	}


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS