Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA instrument Create a class public abstract class Instrument. The class should have the following fields and methods: Fields private String musicianName: the name of

JAVA

instrument

Create a class public abstract class Instrument. The class should have the following fields and methods:

Fields

private String musicianName: the name of the musician who plays the instrument

Methods

public Instrument(String musicianName): the constructor. Initialize all instance variables.

public String getMusicianName: should return the variable musicianName.

public abstract void play(String song)

WoodwindInstrument

Create a class public abstract class WoodwindInstrument. This class should extend Instrument. It does not implement the abstract methods of Instrument, so it is still an abstract class. It should include the following fields and methods:

Fields

private WoodwindType type: WoodwindType is an enum given to you below. You should include this file with your homework files.

WoodwindType.java

public enum WoodwindType { FLUTE, REED } 

Methods

public WoodwindInstrument(String musicianName, WoodwindType type): the constructor. Should instantiate all instance variables, including those in the superclass. Hint: Remember the super() constructor?

public String getType(): Return the String value of type. If type is WoodwindType.FLUTE, return FLUTE. If type is WoodwindType.REED, return REED.

StringInstrument

Create a class public abstract class StringInstrument. It should extend Instrument. As this class will not implement the abstract methods of Instrument, it is still an abstract class. It should contain the following fields and methods:

Fields

private int numStrings: the number of strings a stringed instrument has.

Methods

public StringInstrument(String musicianName, int numStrings): the constructor. Should instantiate all instance variables, including those in the superclass. Hint: Remember the super() constructor?

public int getNumStrings: returns the value of numStrings.

Flute

Create a class public class Flute which extends WoodwindInstrument. Flute will implement the abstract method of Instrument, so it is a concrete class. It should have the following methods:

public Flute(String musicianName): the constructor. It should instantiate all instance variables, including those of its superclasses. A parameter for the type field of WoodwindInstrument is not provided as all objects of type Flute have the type WoodwindType.FLUTE, so this can be passed to the super constructor instead of a user-defined argument.

public void play(String song): provides the implementation for the abstract method of Instrument. It prints details about the flute to stdout, followed by a newline. If, in my main method, I do the following:

public static void main(String[] args) { Instrument flute = new Flute("Tori Shurman"); flute.play("Flute Song"); } 

I should see the following printed to the console:

Tori Shurman is playing Flute Song on a flute, a FLUTE type woodwind. 

Saxophone

Create a class public class Saxophone which extends WoodwindInstrument. Saxophone will implement the abstract method of Instrument, so it is a concrete class. It should have the following methods:

public Saxophone(String musicianName): the constructor. It should instantiate all instance variables, including those of its superclasses. A parameter for the type field of WoodwindInstrument is not provided as all objects of type Saxophone have the type WoodwindType.REED, so this can be passed to the super constructor instead of a user-defined argument.

public void play(String song): provides the implementation for the abstract method of Instrument. It prints details about the saxophone to stdout, followed by a newline. If, in my main method, I do the following:

public static void main(String[] args) { Instrument saxophone = new Saxophone("Sahil Pujari"); saxophone.play("Saxophone Song"); } 

I should see the following printed to the console:

Sahil Pujari is playing Saxophone Song on a saxophone, a REED type woodwind. 

Violin

Create a class public class Violin which extends StringInstrument. Violin will implement the abstract method of Instrument, so it is a concrete class. It should have the following methods:

public Violin(String musicianName): the constructor. It should instantiate all instance variables, including those of its superclasses. A parameter for the numStrings field of StringInstrument is not provided as all objects of type Violin 4 strings, so this can be passed to the super constructor instead of a user-defined argument.

public void play(String song): provides the implementation for the abstract method of Instrument. It prints details about the violin to stdout, followed by a newline. If, in my main method, I do the following:

public static void main(String[] args) { Instrument violin = new Violin("Tori Shurman"); violin.play("Violin Song"); } 

I should see the following printed to the console:

Tori Shurman is playing Violin Song on a 4 string violin. 

Piano

Create a class public class Piano which extends StringInstrument. Piano will implement the abstract method of Instrument, so it is a concrete class. It should have the following fields and methods:

Fields

private String key: contains the key that the musician prefers to play the piano in as a String.

Methods

public Piano(String musicianName, int numStrings, String key): the constructor. It should instantiate all instance variables, including those of its superclasses.

public String getKey: returns the value of the field key

public void play(String song): provides the implementation for the abstract method of Instrument. It prints details about the piano to stdout, followed by a newline. If, in my main method, I do the following:

public static void main(String[] args) { Instrument piano = new Piano("Sahil Pujari", 280, "C"); piano.play("Piano Sonata"); } 

I should see the following printed to the console:

Sahil Pujari is playing Piano Sonata on a 280 string piano in the key of C. 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

If the error of estimation (e) is negative, then

Answered: 1 week ago

Question

How could assessment be used in an employee development program?

Answered: 1 week ago