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

Design and implement a stringed musical instrument class using the following gui

ID: 3569071 • Letter: D

Question

Design and implement a stringed musical instrument class using the following guidelines:

Data fields for your instrument should include number of strings, an array of string names representing string names (e.g. E,A,D,G), and boolean fields to determine if the instrument is tuned, and if the instrument is currently playing. You are welcome to add additional data fields if you like.

A constructor method that set the tuned and currently playing fields to false.

Other methods 1) to tune the instrument, 2) to start the instrument playing, and 3) to stop the instrument from playing.

Other methods as you see fit (Add at least one unique method).

Create Java classes for your instruments. Be sure that your code matches your design specifications and some minimal functionality is included. For example, if you called the violin.play() method, you should at least print that the violin is playing. Similar functionality should be supplied when you stop playing, tune or call any of your methods. For example:

     public void playviolin() {
         System.out.println("The violin is now playing.");
     }

Write the output from your Instrument class methods to a text file that a user entered from the command line arguments (e.g. java Mynamep3tst myfilename.txt). This allows your program to accept filenames from the user via a command line argument.

Finally, create a Java test class that simulates using your instrument class. In your test class be you should at a minimum: a) Construct 10 instances of your instrument, b) tune your instruments, c) Start playing your instrument, d) Call your unique method, and e) Stop playing your instruments.   (Hint: Arrays and Loops will make your job easier and result in more efficient code!)

Explanation / Answer

import java.util.Arrays;

class Violin {

private int number;

private String[] Names = { "A", "B", "C", "D", "E" };

private boolean isTuned;

private boolean isCurrentlyPlaying;

public Violin() {

  super();

  this.isTuned = false;

  this.isCurrentlyPlaying = false;

  this.number = Names.length;

}

public void tuneViolin() {

  isTuned = true;

  System.out.println("The violin is now tuning......");

}

public void playViolin() {

  isCurrentlyPlaying = true;

  System.out.println("The violin is now playing......");

}

public void stopViolin() {

  System.out.println("The violin is now stopped.");

  isCurrentlyPlaying = false;

  isTuned = false;

}

public int getNumber() {

  return number;

}

public String[] getNames() {

  return Names;

}

public String toString() {

  return "The String numbers is :" + getNumber()
    + " with String names are " + Arrays.toString(getNames());

}

}

public class ViolinTester
{
public static void main(String arg[])
{
  Violin ob[] = new Violin[10];
  for(int i=0;i<10;i++)
  {
   ob[i].playViolin();
   ob[i].tuneViolin();
  }
  
  for(int i=0;i<10;i++)   
  {
   System.out.println(ob[i].toString());
  }
  
  for(int i=0;i<10;i++)
   ob[i].stopViolin();
}
}

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