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

This is my instrument code for java, and i am need to add and interactive method

ID: 3647600 • Letter: T

Question

This is my instrument code for java, and i am need to add and interactive method to change some attributes.
Can someone help me?



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

import java.io.FileNotFoundException;

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

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

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

//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
{
boolean isTuned;
boolean isPlaying;


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


public Cello()
{
isTuned = false;
isPlaying = false;
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

please rate - thanks

hope this is what you're looking for


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

package myinstrument;
import java.util.*;
import java.io.FileNotFoundException;

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

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

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

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

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

Scanner in=new Scanner(System.in);
int option;
boolean notDone=true;
while(notDone)
{System.out.println(" What would you like to do? ");
System.out.println("1-tune the cello");
System.out.println("2-play the cello");
System.out.println("3-stop playing the cello");
System.out.println("4-stop the program");
option=in.nextInt();
if(option==1)
   Cello1.tuneCello();
else if(option==2)
    Cello1.playCello();
else if(option==3)
    Cello1.stopPlaying();
else if(option==4)   
    notDone=false;
else
    System.out.println("Invalid option");
}
}
}
class Cello
{
boolean isTuned;
boolean isPlaying;


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


public Cello()
{
isTuned = false;
isPlaying = false;
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;
}

}

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