Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 2 : Guitar 3 7 Class In the second part of the assignment, you are going to build on the GuitarString class to write

Part 2: Guitar37 Class
In the second part of the assignment, you are going to build on the GuitarString class to write a class that keeps
track of a musical instrument with multiple strings. There could be many possible guitar objects with different
kinds of strings. As a result, we introduce an interface known as Guitar that each guitar object implements.
The Guitar interface is defined as follows:
public interface Guitar {
public void playNote(int pitch);
public boolean hasString(char key);
public void pluck(char key);
public double sample();
public void tic();
public int time();
}
The interface allows a client to specify what to play in one of two ways. A client can specify exactly which
note to play by calling the playNote method passing it a pitch. Pitch is specified as an integer where the value 0
represents concert-A and all other notes are specified relative to concert-A using what is known as a chromatic
scale. Not every value of pitch can be played by any given guitar. If it cant be played, it is ignored.
A client can also specify a character that indicates which note to play by calling the pluck method. Different
guitar objects will have different mappings from characters to notes. The interface includes a method called
hasString that is paired with pluck that lets a client verify that a particular character has a corresponding string
for this guitar. The pluck method has a precondition that the key is legal for this guitar.
The Guitar interface also has methods for getting the current sound sample (the sum of all samples from the
strings of the guitar), to advance the time forward one tic, and an optional method for determining the current
time (the number of times tic has been called). If the time method is not implemented, it returns -1.
You are being provided with a sample class called GuitarLite that implements the Guitar interface. Once you
have verified that your GuitarString class passes the testing program, you can play the GuitarLite instrument. It
has only two strings: a and c. Keep in mind that GuitarLite does not have a main method. There is a separate
class called GuitarHero that has main (the initial version constructs a GuitarLite object).

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

Recommended Textbook for

More Books

Students also viewed these Databases questions