Code:
public class JamesKinneyp3
{
public static void main(String[] args) throws Exception
{
java.io.File file = new java.io.File("JamesKinneyp3tst.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 violin object
Violin violin1 = new Violin();
//write test results to file
output.println(violin1.playViolin());
output.println(violin1.stopPlaying());
output.println(violin1.tuneViolin());
}
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'};
//default Violin object
public Violin()
{
isTuned = false;
isPlaying = false;
System.out.println("The violin 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 is playing!");
return isPlaying = true;
}
public boolean stopPlaying()
{
System.out.println("The violin has stopped playing.");
return isPlaying = false;
}
public boolean tuneViolin()
{
System.out.println("The violin is being tuned!");
return isTuned = true;
}
}
}