I have the following task which is that:
There may be up to ten teams. Parallel Arrays are used to store the team Names, as well as to keep track of the number of Wins, Overtime Losses, and Points. After the result for the last team is entered, the program outputs a summary of each team's record in the opposite order to which they were entered.
Note: "W" is worth 2 points, "L" is worth 0 points, "O" is worth 1 point
Sample input:
3 //Option number
Toronto //phrase
W //letters that loop in a while loop
W
L
O
W
O
W
N //To close the while loop, "N" is entered
Montreal
L
L
O
L
L
W
L
L
N // To close the while loop, "N" is entered
Vancouver
W
W
O
O
L
N //To close the while loop, "N" is entered
Winnipeg
L
L
L
W
O
O
W
W
W
W
W
W
W
Q //To close the while loop and get all the results, "Q" is entered
Sample output (It outputs the results in the opposite order):
Team W O L P //States that first, Team and then Wins, Overtime, Losses, and then points. "W" is 2 points, "O" is 1 point, and "L" is 0 point
Winnipeg 8 2 3 18
Vancouver 2 2 1 6
Montreal 1 1 6 3
Toronto 4 2 1 10
I did a similar task with options 2, that requires no use of arrays, now this is options 3, which requires the use of Parallel Arrays Only
Options 2 Code:
else if (option == 2){
int pointsW = 0;
int pointsL = 0;
int pointsO = 0;
int counter = 0;
int totalpoints = 0;
String phrase = keyboard.next();
while(go){
String letter = keyboard.next();
if (letter.equals("W")){
pointsW+=2;
}
else if (letter.equals("L")){
pointsL+=0;
}
else if (letter.equals("O")){
pointsO+=1;
}
counter++;
if (letter.equals("N")){
totalpoints = pointsW + pointsL + pointsO;
counter--;
go = false;
}
}
int counter2 = 0;
int totalpoints2 = 0;
int pointsW2 = 0;
int pointsL2 = 0;
int pointsO2 = 0;
String phrase2 = keyboard.next();
while (go2){
String letter = keyboard.next();
if (letter.equals("W")){
pointsW2+=2;
}
else if (letter.equals("L")){
pointsL2+=0;
}
else if (letter.equals("O")){
pointsO2+=1;
}
counter2++;
if (letter.equals("Q")){
counter2--;
totalpoints2 = pointsW2 + pointsL2 + pointsO2;
go2 = false;
}
}
System.out.println(phrase + " has played "+counter+" games and has earned "+totalpoints+" points");
System.out.println(phrase2 + " has played "+counter2+" games and has earned "+totalpoints2+" points");
if (totalpoints > totalpoints2){
int wins = totalpoints - totalpoints2;
System.out.println(phrase + " is in first place by "+ wins + " points");
}else{
int wins2 = totalpoints2 - totalpoints;
System.out.println(phrase2 + " is in first place by "+ wins2 + " points");
}
}
How would I incorporate Parallel Arrays into Options 3 with the same idea of options 2? I'm really new to learning about parallel arrays and couldn't get any help finding information online about it.
UPDATE
else if (option == 3){
int teams = 10;
String phrase[] = new String[teams];
int wins[] = new int [teams];
int overtime[] = new int [teams];
int loss[] = new int [teams];
int points[] = new int [teams];
int x;
for (x = 0; x < teams; x++){
phrase[x] = keyboard.next();
while (go3){
String letter = keyboard.next();
if (letter.equals("W")){
wins[x]++;
}
else if (letter.equals("L")){
loss[x]++;
}
else if (letter.equals("O")){
overtime[x]++;
}
else if (letter.equals("N") || letter.equals("Q")){
points[x] = wins[x]*2+overtime[x];
go3 = false;
if (letter.equals("Q")){
break;
}
}
}
}
System.out.println("Team W O L P");
for (int i = x; i >= 0; i--){
System.out.println(phrase[i] + " " + wins[i] + " " + overtime[i] + " " + loss[i] + " " + points[i]);
}
}
}
}
ERROR I GET:

You need arrays for names, wins, losses, overtimes and points. However, when you learn more, you will better manage it by creating a custom type say,
Gamewhich will have attributes like,name, and aListtype attribute for recording wins, losses, overtimes etc.A sample run: