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
- 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. Be sure your code compiles.
Write a Java test program, named TestGuitar, to create 3 different Guitars representing each representing a unique test case and call each all of the getter methods along with the toString and playGuitar() methods and document the output. For example for a Guitar with 7 strings, length of 30.2, manufactured by Fender with a color of Black, the output may look similar to this:
***Output*** toString(): (numStrings=7, Length=30.2, manufacturer=Fender, color=Black)
getNumStrings(): 7
getGuitarLength(): 30.2
getGuitarManufacturer(): Fender
getGuitarColor(): Black playGuitar(): [A(2), G(3), B(0.5), C(1), C(1), D(0.25), E(2), F(2), G(0.25), C(4), C(1), F(0.25),A(1), C(2), D(4),C(4)]
Document your test cases in the form of table with columns indicating the input values, expected output, actual output and if the test case passed or failed. This table should contain 4 columns with appropriate labels and a row for each test case. An example template is shown below. Note that the actual output should be the actual results you receive when running your program and applying the input for the test record
Step by Step Solution
3.43 Rating (153 Votes )
There are 3 Steps involved in it
Lets break this task into multiple parts for clarity and implementation Part 1 Design the Guitar Class 1 Define Data Fields numStrings Integer default value 6 guitarLength Double default value 282 gui... View full answer
Get step-by-step solutions from verified subject matter experts
Document Format (2 attachments)
60953e9cdbc46_25676.pdf
180 KBs PDF File
60953e9cdbc46_25676.docx
120 KBs Word File
