For example here's your program reposted with code tags wrapped around it (and with removal of some of your excess white-space). See how much easier it is to read?
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Formatter;
public class Violin {
// Class Violin constructor
public Violin() {
tunedViolin = false;
playViolin = false;
}
// Class Violin methods
public boolean setTuneViolin() {
tunedViolin = true;
return tunedViolin;
}
public boolean setViolin() {
playViolin = true;
return playViolin;
}
public void playViolin(int choice) throws IOException // throw exception to
// append file
{
// true = append file
FileWriter writeFile = new FileWriter("myText.text", true);
PrintWriter outputFile = new PrintWriter(writeFile);
// set array limit
int limit = stringArray.length;
switch (choice) {
case 1:
// output violin number in console and external file
String tuned1 = "Violin 1 is Tuned.";
String play1 = "Playing Violin 1 strings:";
System.out.println(tuned1);
System.out.println(play1);
outputFile.println(tuned1);
outputFile.println(play1);
// loop through array
for (int index = 0; index < limit; index++) {
System.out.println(stringArray[index]);
outputFile.println(stringArray[index]);
}
break;
case 2:
// output violin number in console and external file
String tuned2 = "Violin 2 is Tuned.";
String play2 = "Playing Violin 2 strings:";
System.out.println(tuned2);
System.out.println(play2);
outputFile.println(tuned2);
outputFile.println(play2);
// loop through array
for (int index = 3; index >= 0; index--) {
System.out.println(stringArray[index]);
outputFile.println(stringArray[index]);
}
break;
case 3:
// output violin number in console and external file
String tuned3 = "Violin 3 is Tuned.";
String play3 = "Playing Violin 3 strings:";
System.out.println(tuned3);
System.out.println(play3);
outputFile.println(tuned3);
outputFile.println(play3);
// loop through array
for (int index = 0; index < limit; index += 2) {
System.out.println(stringArray[index]);
outputFile.println(stringArray[index]);
}
break;
case 4:
// output violin number in console and external file
String tuned4 = "Violin 4 is Tuned.";
String play4 = "Playing Violin 4 strings:";
System.out.println(tuned4);
System.out.println(play4);
outputFile.println(tuned4);
outputFile.println(play4);
// access array
System.out.println(stringArray[0]);
outputFile.println(stringArray[0]);
System.out.println(stringArray[3]);
outputFile.println(stringArray[3]);
System.out.println(stringArray[1]);
outputFile.println(stringArray[1]);
System.out.println(stringArray[2]);
outputFile.println(stringArray[2]);
break;
case 5:
// output violin number in console and external file
String tuned5 = "Violin 5 is Tuned.";
String play5 = "Playing Violin 5 strings:";
System.out.println(tuned5);
System.out.println(play5);
outputFile.println(tuned5);
outputFile.println(play5);
// access array
System.out.println(stringArray[3]);
outputFile.println(stringArray[3]);
System.out.println(stringArray[0]);
outputFile.println(stringArray[0]);
System.out.println(stringArray[2]);
outputFile.println(stringArray[2]);
break;
case 6:
// output violin number in console and external file
String tuned6 = "Violin 6 is Tuned.";
String play6 = "Playing Violin 6 strings:";
System.out.println(tuned6);
System.out.println(play6);
outputFile.println(tuned6);
outputFile.println(play6);
// access array
System.out.println(stringArray[0]);
outputFile.println(stringArray[0]);
break;
case 7:
// output violin number in console and external file
String tuned7 = "Violin 7 is Tuned.";
String play7 = "Playing Violin 7 strings:";
System.out.println(tuned7);
System.out.println(play7);
outputFile.println(tuned7);
outputFile.println(play7);
// loop through array
for (int index = 0; index < limit; index++) {
// loop through array
for (int index1 = 0; index1 < limit; index1++) {
System.out.println(stringArray[index1]);
outputFile.println(stringArray[index1]);
}
}
break;
case 8:
// output violin number in console and external file
String tuned8 = "Violin 8 is Tuned.";
String play8 = "Playing Violin 8 strings:";
System.out.println(tuned8);
System.out.println(play8);
outputFile.println(tuned8);
outputFile.println(play8);
// access array
System.out.println(stringArray[0]);
outputFile.println(stringArray[0]);
System.out.println(stringArray[0]);
outputFile.println(stringArray[0]);
System.out.println(stringArray[1]);
outputFile.println(stringArray[1]);
System.out.println(stringArray[3]);
outputFile.println(stringArray[3]);
break;
case 9:
// output violin number in console and external file
String tuned9 = "Violin 9 is Tuned.";
String play9 = "Playing Violin 9 strings:";
System.out.println(tuned9);
System.out.println(play9);
outputFile.println(tuned9);
outputFile.println(play9);
// access array
System.out.println(stringArray[0]);
outputFile.println(stringArray[0]);
break;
case 10:
// output violin number in console and external file
String tuned10 = "Violin 10 is Tuned.";
String play10 = "Playing Violin 10 strings:";
System.out.println(tuned10);
System.out.println(play10);
outputFile.println(tuned10);
outputFile.println(play10);
// access array
System.out.println(stringArray[3]);
outputFile.println(stringArray[3]);
break;
}
// close file
outputFile.close();
// loop through array
}
public boolean stopViolinPlay() {
playViolin = false;
return playViolin;
}
// Class Violin attributes
private int strings;
private boolean tunedViolin;
private boolean playViolin;
private String stringArray[] = { "E", "A", "D", "G" };// Violin array
private Formatter x; // variable use to create file
}