In: Computer Science
a.Three strikes bowling lanes hosts an annual
tournament for 12 teams. Design a program that accepts each teams
name and total score for the tourtament and stores them in parallel
arrays. display the names of the top three teams
b. modify the bowling tourtament program so that, instead of the
teams total score the program accepts the score of each of the four
team members. Display the names of the five top scorers in the
tourtament as well as their team names.
just need psuedocode help. not a specific language. thanks
Note: As it was not language-specific. So I have used java for this question.
A)
CODE
import java.util.*;
import java.io.*;
class MyObject {
public String teamName;
public Integer totalScore;
public MyObject(String teamName,
Integer totalScore){
this.teamName =
teamName;
this.totalScore
= totalScore;
}
}
public class Tournament {
public static void main(String[]
args) {
Scanner sc = new
Scanner(System.in);
//To create an Array:
MyObject[] MyObjects = new
MyObject[12]; //array of size 12
for(int i=0;i<12;i++) {
System.out.println("Enter team name ");
String str =
sc.next();
System.out.println("Enter team total score ");
int val =
sc.nextInt();
MyObjects[i] =
new MyObject(str, val); // Random string and integer in the
constructor.
}
// for the display of teams and
total score
/*
for(int i=0;i<12;i++) {
System.out.println(MyObjects[i].teamName);
System.out.println(MyObjects[i].totalScore);
}
*/
int first, second, third;
third = first = second = 0;
for(int i=0;i<12;i++) {
if
(MyObjects[i].totalScore > MyObjects[first].totalScore) {
third = second;
second = first;
first = i;
}
else if (MyObjects[i].totalScore > MyObjects[second].totalScore)
{
third = second;
second = i;
}
else if (MyObjects[i].totalScore >
MyObjects[third].totalScore)
third = i;
}
System.out.println("Top three teams
are " + MyObjects[first].teamName + " " +
MyObjects[second].teamName + " " +
MyObjects[third].teamName);
}
}
NOTE - I have shown 5 teams for output for a clear and better understanding.
Snapshot -
Output
B)
CODE
import java.util.*;
import java.io.*;
class MyObject {
public String teamName;
public String player1Name;
public String player2Name;
public String player3Name;
public String player4Name;
public Integer player1;
public Integer player2;
public Integer player3;
public Integer player4;
public MyObject(String
teamName,String player1Name, Integer player1,String
player2Name,
Integer player2,String player3Name,Integer
player3,String player4Name,
Integer player4){
this.teamName =
teamName;
this.player1 =
player1;
this.player2 =
player2;
this.player3 =
player3;
this.player4 =
player4;
this.player1Name
= player1Name;
this.player2Name
= player2Name;
this.player3Name
= player3Name;
this.player4Name
= player4Name;
}
}
public class Tournament {
public static void main(String[]
args) {
Scanner sc = new
Scanner(System.in);
//To create an Array:
MyObject[] MyObjects = new
MyObject[12]; //array of size 12
for(int i=0;i<12;i++) {
System.out.println("Enter team name ");
String str =
sc.next();
System.out.println("Enter first player name ");
String pl1 =
sc.next();
System.out.println("Enter first player score ");
int vpl1 =
sc.nextInt();
System.out.println("Enter second player name ");
String pl2 =
sc.next();
System.out.println("Enter second player score
");
int vpl2 =
sc.nextInt();
System.out.println("Enter third player name ");
String pl3 =
sc.next();
System.out.println("Enter third player score ");
int vpl3 =
sc.nextInt();
System.out.println("Enter fourth player name ");
String pl4 =
sc.next();
System.out.println("Enter fourth player score
");
int vpl4 =
sc.nextInt();
MyObjects[i] =
new MyObject(str, pl1, vpl1, pl2, vpl2, pl3, vpl3, pl4,
vpl4);
}
// for display of teams and total
score
for(int i=0;i<12;i++) {
System.out.println(MyObjects[i].teamName);
System.out.println(MyObjects[i].player1Name);
System.out.println(MyObjects[i].player1);
System.out.println(MyObjects[i].player2Name);
System.out.println(MyObjects[i].player2);
System.out.println(MyObjects[i].player3Name);
System.out.println(MyObjects[i].player3);
System.out.println(MyObjects[i].player4Name);
System.out.println(MyObjects[i].player4);
}
int l=0;
int m=0;
int[] arr = new int[48]; // change
to 48 for 12 teams
String[] str1 = new
String[48];
while(l<48) {
if(m<12) {
arr[l] =
MyObjects[m].player1;
arr[l+1] =
MyObjects[m].player2;
arr[l+2] =
MyObjects[m].player3;
arr[l+3] =
MyObjects[m].player4;
str1[l] =
MyObjects[m].player1Name;
str1[l+1] =
MyObjects[m].player2Name;
str1[l+2] =
MyObjects[m].player3Name;
str1[l+3] =
MyObjects[m].player4Name;
l = l+4;
m++;
}
}
for(int i=0;i<48;i++) {
System.out.println(arr[i] + str1[i] );
}
int i;
int idx[] = new int[5];
int max = 0, index;
for (int j = 0; j < 5; j++) {
max = arr[0];
index = 0;
for (i = 1; i < arr.length; i++) {
if (max < arr[i]) {
max = arr[i];
index = i;
}
}
idx[j] = index;
arr[index] = Integer.MIN_VALUE;
}
System.out.println("Five top scorers are ");
for(int k=0;k<5;k++) {
if(idx[k] >= 0 && idx[k]
<4) {
System.out.println("Name:" + str1[idx[k]] + " Team:" +
MyObjects[0].teamName);
}
else if(idx[k] >= 4 &&
idx[k] <8) {
System.out.println("Name:" + str1[idx[k]] + " Team:" +
MyObjects[1].teamName);
}
else if(idx[k] >= 8 &&
idx[k] <12) {
System.out.println("Name:" + str1[idx[k]] + " Team:" +
MyObjects[2].teamName);
}
else if(idx[k] >= 12 &&
idx[k] <16) {
System.out.println("Name:" + str1[idx[k]] + " Team:" +
MyObjects[3].teamName);
}
else if(idx[k] >= 16 &&
idx[k] <20) {
System.out.println("Name:" + str1[idx[k]] + " Team:" +
MyObjects[4].teamName);
}
else if(idx[k] >= 20 &&
idx[k] <24) {
System.out.println("Name:" + str1[idx[k]] + " Team:" +
MyObjects[5].teamName);
}
else if(idx[k] >= 24 &&
idx[k] <28) {
System.out.println("Name:" + str1[idx[k]] + " Team:" +
MyObjects[6].teamName);
}
else if(idx[k] >= 28 &&
idx[k] <32) {
System.out.println("Name:" + str1[idx[k]] + " Team:" +
MyObjects[7].teamName);
}
else if(idx[k] >= 32 &&
idx[k] <36) {
System.out.println("Name:" + str1[idx[k]] + " Team:" +
MyObjects[8].teamName);
}
else if(idx[k] >= 36 &&
idx[k] <40) {
System.out.println("Name:" + str1[idx[k]] + " Team:" +
MyObjects[9].teamName);
}
else if(idx[k] >= 40 &&
idx[k] <44) {
System.out.println("Name:" + str1[idx[k]] + " Team:" +
MyObjects[10].teamName);
}
else if(idx[k] >= 44 &&
idx[k] <48) {
System.out.println("Name:" + str1[idx[k]] + " Team:" +
MyObjects[11].teamName);
}
}
}
}
I have tried to
answer the question as briefly and simply as possible if you find
any problem in the solution provided ask in comment and provide
feedback.