repl.it
Java

No description

fork
loading
Files
  • Main.java
  • jdt.ls-java-project
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
public class StringPackage {

//data fields include a String[] to hold string names as per the assignment
private static final String TRUMPET = "trumpet", VIOLIN = "violin";
String[] stringArray;

//builds the StringPackage for each instrument
//can be amended to include new instruments as they're built
//don't know how to throw exceptions yet so this will have to do as a substitute
public StringPackage(String typeOfInstrument, int numberOfStrings) {
    if(numberOfStrings == 6 && typeOfInstrument.equalsIgnoreCase(TRUMPET)){
        String temp = "E A D G B E";
        stringArray = temp.split(" ");
    }//6 string
    else if(numberOfStrings == 12 && typeOfInstrument.equalsIgnoreCase(TRUMPET)){
        String temp ="E E A A D D G G B B E E";
        stringArray = temp.split(" ");
    }//12 string
    else if (numberOfStrings == 4 && typeOfInstrument.equalsIgnoreCase(VIOLIN)){
        String temp = "G D A E";
        stringArray = temp.split(" ");
    }//violin
    else
        System.out.println("***Exception! " + numberOfStrings + " string "+ typeOfInstrument + " has not been created yet!***");

}//StringPackage

//.length method to for use in loops, etc.
public int length(){
    int length = stringArray.length;
    return length;
}

//builds string for notes display
//used by viewStringPackage in Guitar and Violin
public String Notes(){
    StringBuilder notes = new StringBuilder();
    for(int i = 0; i < stringArray.length; i++){
        notes.append(stringArray[i] + " ");
    }
    String notes1 = notes.toString();
    return notes1;
}

public static void comboPrint(String myString) throws IOException {
    boolean append = true;
  FileWriter myOutFile = new FileWriter("TrumpetViolin.txt", append);  
  PrintWriter fileOut = new PrintWriter(myOutFile); 
  System.out.println(myString);
  fileOut.println(myString);
  fileOut.close();
}

}//StringPackage