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

Please help with adding the number of strings to my code. I am unable to figure

ID: 3559876 • Letter: P

Question

Please help with adding the number of strings to my code. I am unable to figure out where to put this part.

Also requesting assistance with the diagram per the assignment instructions. PLEASE HELP ASAP. I've attached my code and it's nears done. Just need help with those two.

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 a UML class diagram using a diagram tool (e.g. PPT, Visio) of your choice. Prepare the diagrams and place them in a word document along with a brief description of each of your classes.

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!) Your programs should compile and run without errors. Be sure to test your program carefully.

Provide a list of comprehensive test cases used to validate your application and include these test cases in your word document containing your UML diagrams and descriptions.

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

Create a UML class diagram using a diagram tool (e.g. PPT, Visio) of your choice. Prepare the diagrams and place them in a word document along with a brief description of each of your classes.

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!)

Your programs should compile and run without errors.

Be sure to test your program carefully. Provide a list of comprehensive test cases used to validate your application and include these test cases in your word document containing your UML diagrams and descriptions.

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package finalproject;

import java.util.ArrayList;
import java.util.List;

/**
*

*/
public class Finalproject {

    /**
     * @param args the command line arguments
     */
         public static void main(String[] args) throws Exception {

        java.io.File file = new java.io.File("test.txt");

        //check to see if file already exists
        if (file.exists())
        {
            System.out.println("File already exists");
            System.exit(0);
        }

        //create a file
        java.io.PrintWriter output = new java.io.PrintWriter(file);

        List violinList = new ArrayList();
      
        //Creating 10 violins
        for(int i=0; i<10; i++){
            violinList.add(new Violin(i));
        }
      
        //Tuning the violins
        for(int i=0; i<10; i++){
            violinList.get(i).tuneViolin();
        }
      
        //Playing the violins and calling the unique method and stopping them
        for(int i=0; i<10; i++){
            violinList.get(i).playViolin();
            //Have to call the unique method here
            violinList.get(i).myUniqueFunction();
            violinList.get(i).stopPlaying();
        }
        //declare violin object
        /*Violin violin1 = new Violin();

        //write test results to file
        output.println(violin1.playViolin());
        output.println(violin1.stopPlaying());
        output.println(violin1.tuneViolin());*/
}

private static Violin newViolin() {
        return null;
}

static class Violin
{
    boolean isTuned; //Violin starts off not tuned
    boolean isPlaying; //Violin is not playing at start

//array for Violin strings
    char [] violinStrings = {'E','A','D','G'};
    int index = 0;

public Violin(int index){
    isTuned = false;
    isPlaying = false;
    this.index = index;
    System.out.println("The violin " + index + " is not playing, and it is not tuned.");
}

//default Violin object
public Violin()
{
    isTuned = false;
    isPlaying = false;
    System.out.println("The violin " + index + " is not playing, and it is not tuned.");
}

public Violin(boolean T, boolean P)
{
    isTuned = T;
    isPlaying = P;
}

public boolean playViolin()
{
    System.out.println("The violin" + index + " is playing!");
    return isPlaying = true;
}

public boolean stopPlaying()
{
    System.out.println("The violin" + index + " has stopped playing.");
    return isPlaying = false;
}

public boolean tuneViolin()
{
    System.out.println("The violin " + index + " is being tuned!");
    return isTuned = true;
}

public void myUniqueFunction(){
    System.out.println("I am violin: " + index);
}
}
}
   

Explanation / Answer

I also created a Violin class, basically a copy guitar class

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