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

this is an instrument playing cod in java. Can someone help me fix my code where

ID: 3647596 • Letter: T

Question

this is an instrument playing cod in java. Can someone help me fix my code where the user can select a certain string to play the instrument?


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package music;

import java.io.FileNotFoundException;
import java.util.Scanner;

/**
*
* @author Owner
*/
public class Music {

/**
* @param args the command line arguments
*/


public static void main(String[] args) throws FileNotFoundException {
java.io.File file = new java.io.File(".txt");
Scanner input = new Scanner(System.in);
//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);

//declare cello object
Cello Cello1 = new Cello();

//write test results to file
output.println(Cello1.playCello());
output.println(Cello1.stopPlaying());
output.println(Cello1.tuneCello());
}
}

class Cello
{

private static class input {

public input() {
}
}
boolean isTuned;
boolean isPlaying;


char [] CelloStrings = {'E','A','D','G'};


public Cello()
{
isTuned = false;
isPlaying = false;
System.out.println("please enter a string");
String aChoice = "";

System.out.println("Please enter: 1 to E, 2 A, 3 D, 4 G ");

int aLetter = input.nextInt();

switch (aLetter) {

case 1: aChoice = "E";
break;

case 2: aChoice = "A";
break;

case 3: aChoice = "D";
break;

case 4: aChoice = "G";
break;

default:
System.out.println("The selection is not acceptable. ");
} // end switch aLetter

if (aLetter > 0 && aLetter < 5)


System.out.println("The Cello is not playing, and it is not tuned.");
}

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

public boolean playCello()
{
System.out.println("The Cello is playing!");
return isPlaying = true;
}

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

public boolean tuneCello()
{
System.out.println("The Cello is being tuned!");
return isTuned = true;
}

}

Explanation / Answer

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package music; import java.io.FileNotFoundException; import java.util.Scanner; /** * * @author Owner */ public class Music { /** * @param args the command line arguments */ public static void main(String[] args) throws FileNotFoundException { java.io.File file = new java.io.File(".txt"); Scanner input = new Scanner(System.in); //check to see if file already exists if (file.exists()) { System.out.println("File already exists"); System.exit(0); } package je3.sound; /** * Play a sound file from the network using the java.applet.Applet API. */ public class PlaySound { public static void main(String[ ] args) throws java.net.MalformedURLException { java.applet.AudioClip clip = java.applet.Applet.newAudioClip(new java.net.URL(args[0])); clip.play( ); } } //create a file java.io.PrintWriter output = new java.io.PrintWriter(file); //declare cello object Cello Cello1 = new Cello(); //write test results to file output.println(Cello1.playCello()); output.println(Cello1.stopPlaying()); output.println(Cello1.tuneCello()); } } class Cello { private static class input { public input() { } } boolean isTuned; boolean isPlaying; char [] CelloStrings = {'E','A','D','G'}; public Cello() { isTuned = false; isPlaying = false; System.out.println("please enter a string"); String aChoice = ""; System.out.println("Please enter: 1 to E, 2 A, 3 D, 4 G "); int aLetter = input.nextInt(); switch (aLetter) { case 1: aChoice = "E"; break; case 2: aChoice = "A"; break; case 3: aChoice = "D"; break; case 4: aChoice = "G"; break; default: System.out.println("The selection is not acceptable. "); } // end switch aLetter if (aLetter > 0 && aLetter < 5) System.out.println("The Cello is not playing, and it is not tuned."); } public Cello(boolean T, boolean P) { isTuned = T; isPlaying = P; } public boolean playCello() { System.out.println("The Cello is playing!"); return isPlaying = true; } public boolean stopPlaying() { System.out.println("The Cello has stopped playing."); return isPlaying = false; } public boolean tuneCello() { System.out.println("The Cello is being tuned!"); return isTuned = true; } }