JAVA Create your own Java class that represents your favorite musical instrument
ID: 3676456 • Letter: J
Question
JAVA
Create your own Java class that represents your favorite musical instrument. Your musical instrument class should have at least 3 constants, 5 private data fields, a toString() method, and three additional methods of your choice. Insert into the class a method that interactively requests and constructs at least 5 of your musical instrument objects. For each of the objects constructed demonstrate the use of each of the methods. Be sure to use your IDE to accomplish this assignment. You can pick any instrument you want. When designing your class, think about what would make sense to describe and use the instrument. For example, if you selected a trumpet, you might need to provide the number of valves, the manufacturer, if the instrument is using a mute, the volume or even notes the trumpet is playing. Make this your own creation and have fun with it.
Explanation / Answer
public class GitFiddle { //Initalize class variables. private String guitarMake; private String guitarModel; private int numOfStrings; private String notes; private int jumboFrets; private String neckType; private String fingerBoard; private String humPickUps; private boolean tuned; //A constructor that has specific variables assigned to it. public GitFiddle (String guitarMake, String guitarModel, int numOfStrings, String notes, int jumboFrets, String neckType, String fingerBoard, String humPickUps, boolean tuned) { this.guitarMake = guitarMake; this.guitarModel = guitarModel; this.numOfStrings = numOfStrings; this.notes = notes; this.jumboFrets = jumboFrets; this.neckType = neckType; this.fingerBoard = fingerBoard; this.humPickUps = humPickUps; this.tuned = tuned; } //Created the output that will be displayed to the user. public String output() { return "My guitar is an " + guitarMake + "," + " " + guitarModel + " which is a " + numOfStrings + "-string, electric guitar." + " The standard tuning for this guitar is as follows(from low to high): " + notes + "." + " It has " + jumboFrets + " jumbo frets on a " + neckType + ", a " + fingerBoard + " fingerboard and pearl, dot inlays." + " It also has dual " + humPickUps + " humbucker pickups which is perfect for some sweet metal action!" + " Is this 7-string beauty tuned up and ready to play?: " + tuned + " Are you ready?"; } public static void main(String args[]) { //Create an instance of household item method. GitFiddle guitar = new GitFiddle ("Ibanez", "S-7 320 EX", 7, "B E A D G B E", 22, "Wizard, W-7 II neck", "rosewood", "EMG 81 85", true); //Output the status of the household item. System.out.println(guitar.output()); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.