Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design and implement a musical instrument class along with 4 subclasses using th

ID: 3638941 • Letter: D

Question

Design and implement a musical instrument class along with 4 subclasses using the following guidelines:

a. Create a class named MusicalInstrument and its four subclasses named Woodwind, Brass, String and Percussion.

b. The MusicalInstrument has a name, isPlaying, and isTuned data fields. It also has methods for setting and getting the values of each of the fields along with a method to display how the instrument is played. A constructor that sets the isTuned and isPlaying fields to false is also included in the MusicalInstrument class. You are welcome to add additional data fields and methods if you like.

c. When you create your Woodwind, Brass, String and Percussion classes set the name and how to play the instrument as follows

Class Name Method to Play

Woodwind Woodwind Reeds

Brass Brass Mouth piece

String String Pluck and bow

Percussion Percussion Hit




2. Finally, create a Java test class that simulates using your MusicalInstrument class. In your test class you should at a minimum: a) Construct 4 instances of your instrument, b) tune your instruments, c) print the name of your instrument d) print how you play your instrument

3. Your programs should compile and run without errors.

Explanation / Answer

public class CMusicalInstrument { private String name; private boolean isPlaying; private boolean isTuned; public CMusicalInstrument(){ isPlaying = false; isTuned = false; } public CMusicalInstrument(String name){ this.name = name; } public void setName(String value){ name = value; } public String getName(){ return name; } public void play(){ isPlaying = true; } public void pause(){ isPlaying = false; } public void tune(){ isTuned = !isTuned; } } public class CWoodwind extends CMusicalInstrument { private String playSound; public CWoodwind(String name,String play){ super(name); playSound = play; } public void howToPlay(){ System.out.println("" + super.getName() + " is playing " +playSound ); } } public class CBrass extends CMusicalInstrument { private String playSound; public CBrass(String name,String play){ super(name); playSound = play; } public void howToPlay(){ System.out.println("" + super.getName() + " is playing " +playSound ); } } public class CString extends CMusicalInstrument { private String playSound; public CString(String name,String play){ super(name); playSound = play; } public void howToPlay(){ System.out.println("" + super.getName() + " is playing " +playSound ); } } public class CPercurssion extends CMusicalInstrument { private String playSound; public CPercurssion(String name,String play){ super(name); playSound = play; } public void howToPlay(){ System.out.println("" + super.getName() + " is playing " +playSound ); } } public class Main { public static void main(String args[]){ CWoodwind wood = new CWoodwind("Woodwind","Reeds"); CBrass brass = new CBrass("Brass","Piece"); CString str = new CString("String","Pluck and Bow"); CPercurssion per = new CPercurssion("Percurssion","Percursion Hit"); wood.howToPlay(); brass.howToPlay(); str.howToPlay(); per.howToPlay(); } } Output: run: Woodwind is playing Reeds Brass is playing Piece String is playing Pluck and Bow Percurssion is playing Percursion Hit BUILD SUCCESSFUL (total time: 0 seconds)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote