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

Design a Java class named Guitar that contains: A private int data field named n

ID: 3885028 • Letter: D

Question

Design a Java class named Guitar that contains: A private int data field named numStrings that defines the number of strings on the guitar. The default value should be 6. A private double data field named guitarLength that defines the length of the guitar in inches. The default value should be 28.2 A private String data field named guitarManufacturer that defines the manufacturer of the guitar. The default value should be "Gibson". A private Color data field named guitarColor that defines the color of the guitar. The default value should be Color.Red. A no argument constructor that creates a Guitar using the default number of strings, length, manufacturer and color. A constructor that creates a Guitar using a specified number of strings, length, manufacturer and color. Getter methods for all data fields. A playGuitar() method that returns a string representation of 16 randomly selected musical notes of random duration. For example, the first part of the string returned might look like this: [A (2), G (3), B (0.5), C (1), C (1), D (0.25), ...]. You can assume one octave in the key of C where valid notes include A, B, C, D, E, F and G and duration values are .25, .5, 1, 2, and 4 representing sixteenth notes, eighth notes, quarter notes, half notes and whole notes, respectively. A toString() method that displays the number of strings, length, manufacturer and color in String format

Explanation / Answer

class StringInstrument {//begin class //declare variables boolean isTuned; boolean isPlaying; boolean band; public String nameOfInstrument; int numberOfStrings; String nameofStringsInInstrument[] = {"E", "A", "D", "G", "B"}; //an array of string names public StringInstrument() {//begin contructor numberOfStrings = 5; isTuned = false; isPlaying = false; band = false; }//end constructor public int NumberOfStrings(int stringNumber){//begin method System.out.println("The number of strings for the " + nameOfInstrument + " is " + stringNumber ); return this.numberOfStrings = stringNumber; }//end method public String InstrumentNameGet() {//begin method return nameOfInstrument; }//end method public void SetInstrumentName (String instrumentName) {//begin getter method nameOfInstrument = instrumentName; }//end method public String InstrumentNameDisplay() {//begin method System.out.println("Your instrument is the " + nameOfInstrument); return nameOfInstrument; }//end method public boolean PlayInstrument(){//begin method System.out.println("You are playing your " + nameOfInstrument); return isPlaying = true; }//end method public boolean TuneInstrument(){//begin method System.out.println("Tune " + nameOfInstrument); return isTuned = true; }//end method public boolean stopTuneInstrument() {//begin method System.out.println("The" + nameOfInstrument + " is out of tune."); return isTuned = false; }//end method public boolean StopPlayInstrument() {//begin method System.out.println("The " + nameOfInstrument + " has stopped playing"); return isTuned = false; }//end method public boolean PlayInstrumentBand() {//begin method System.out.println("The " + nameOfInstrument + " is playing in a band"); return band = true; }//end method public boolean StopPlayInstrumentBand() {//begin method System.out.println("The " + nameOfInstrument + " has stoped playing with the band"); System.out.println(" "); return band = false; }//end method