Question

Please use pseudocode for this response, any additional advice for making this as easy to understand...

Please use pseudocode for this response, any additional advice for making this as easy to understand as possible is greatly appreciated.

Problem Statement

Assume the Scores array is parallel to the Players array (both arrays are below).

Scores array

Scores[0] = 198

Scores[1] = 486

Scores[2] = 651

Scores[3] = 185

Scores[4] = 216

Scores[5] = 912

Scores[6] = 173

Scores[7] = 319

Scores[8] = 846

Scores[9] = 989

Players Array

Players[0] = "Joe"

Players[1] = "Ann"

Players[2] = "Marty"

Players[3] = "Tim"

Players[4] = "Rosy"

Players[5] = "Jane"

Players[6] = "Bob"

Players[7] = "Lily"

Players[8] = "Granny"

Players[9] = "Liz"

Write a looping program that presents the user with 3 options:

1) Sort Output by Players

2) Sort Output by Scores

3) Exit Program

When the first option is selected, sort the Players array in alphabetical order, keeping the Scores array parallel. Add code that determines the highest and lowest scores in the list. Include code to display each player’s score and name in the sorted order. Below the sorted list display the highest and lowest scores in the list and the name of the player who received that score.

Your sort by Player output display should look like this:

Scores Sorted by Player:

486 Ann

173 Bob

846 Granny

912 Jane

198 Joe

319 Lily

989 Liz

651 Marty

216 Rosy

185 Tim

-----------------------------------

989 Highest Score by Liz

173 Lowest Score by Bob

When the second option is selected, sort the Scores array in numerical order, keeping the Players array parallel. Add code that determines the average score of the entire list. Include code to display each player’s score and name in the sorted order. Below the sorted list display the average of all scores in the list. Your sort by Scores output display should look like this:

Players Sorted by Scores:

173 Bob

185 Tim

198 Joe

216 Rosy

319 Lily

486 Ann

651 Marty

846 Granny

912 Jane

989 Liz

---------------------------

498 Average Score

You may use either the Bubble Sort or the Selection Sort algorithms.

Option three is self explanatory. NEVER call "main" from inside your program. Use a loop that keeps your program running until the user chooses option 3.

Round the Average score to the nearest whole number, as shown in the output example above.

You MUST use Modular Programming techniques by using Sub Modules (Sub Charts in RAPTOR) in your program. Your "main" module should not be very large. Again, NEVER call "main" from inside your program. Also, do not use "recursion" in this program (submodules that call themselves). You are only allowed to use looping techniques to repeat sections of your submodules.

You may NOT "hard code" the numbers for highest and lowest scores. Nor simply sort the array by score and use the lowest and highest indexes. These must be discovered through algorithm that will work on an unsorted array. NOR may you "hard code" the number for the average score. Accumulate the scores in a loop then calculate the average. If the array data is changed, the Hi/Low/Avg scores should automatically be found or calculated with the new data.

Hard-code the values of the arrays into your program. Do NOT ask the user to input the values.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SortExample.java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.student;

import java.util.Scanner;// package

/**
*
* @author Kannarao
*/
public class SortExample {

public static void main(String args[]) {


int c, d, swap;//c for looping player names//d for looping scores
// declare a string scores with initial size

String[] players = new String[10];//players array
int scores[] = new int[10];//scores array


// asigning player names to players[] array

players[0] = "JOE";
players[1] = "ANN";
players[2] = "MARTY";
players[3] = "TIM";
players[4] = "ROSEY";
players[5] = "JAIN";
players[6] = "BOB";
players[7] = "LILY";
players[8] = "GRANNY";
players[9] = "LIZ";
// asigning scores to scores array

scores[0] = 198;
scores[1] = 486;
scores[2] = 651;
scores[3] = 185;
scores[4] = 216;
scores[5] = 198;
scores[6] = 912;
scores[7] = 173;
scores[8] = 319;
scores[9] = 989;

Scanner sc = new Scanner(System.in);//keyboard inputting

System.out.println("Enter your choice");
System.out.println("press 1 for ascending order of scores with players names");
System.out.println("press 2 for alphabitical order of players names with scores");
System.out.println("press 3 for exit");
System.out.println();
int choice = sc.nextInt();

switch (choice) {
case 1:
for (c = 0; c < (10 - 1); c++) {
for (d = 0; d < 10 - c - 1; d++) {
if (scores[d] > scores[d + 1]) /* For descending order use < */ {
swap = scores[d];
scores[d] = scores[d + 1];
scores[d + 1] = swap;
}
}
}

System.out.println("Sorted list of players through scores");
players[0] = "JOE";
players[1] = "ANN";
players[2] = "MARTY";
players[3] = "TIM";
players[4] = "ROSEY";
players[5] = "JAIN";
players[6] = "BOB";
players[7] = "LILY";
players[8] = "GRANNY";
players[9] = "LIZ";

for (c = 0; c < 10; c++) {
System.out.println(players[c] + " scored " + scores[c]);
int least = scores[0];
int highest = scores[0];

for (int i = 1; i < scores.length; i++) {
if (scores[i] > highest) {
highest = scores[i];
} else if (scores[i] < least) {
least = scores[i];
}

}
if (scores[c] == highest) {
System.out.println(players[c] + " scored highest runs : " + highest);
}
if (scores[c] == least) {
System.out.println(players[c] + " scored least runs : " + least);
}


}


break;
case 2:
sortStringBubble(players);
scores[0] = 198;
scores[1] = 486;
scores[2] = 651;
scores[3] = 185;
scores[4] = 216;
scores[5] = 198;
scores[6] = 912;
scores[7] = 173;
scores[8] = 319;
scores[9] = 989;


System.out.println("sorting by players in alphabitical order");
for (c = 0; c < 9; c++) {

System.out.println(players[c] + " scored " + scores[c]);

}

break;
case 3:
System.out.println("you have quitted");
System.exit(0);
break;
default:
System.out.println("Invalid choice.");
break;
}


}

public static void sortStringBubble(String x[]) {
int j;
boolean flag = true; // will determine when the sort is finished
String temp;

while (flag) {
flag = false;
for (j = 0; j < x.length - 1; j++) {
if (x[j].compareToIgnoreCase(x[j + 1]) > 0) { // ascending sort
temp = x[j];
x[j] = x[j + 1]; // swapping
x[j + 1] = temp;
flag = true;
}
}
}
}
}

output

run:
Enter your choice
press 1 for ascending order of scores with players names
press 2 for alphabitical order of players names with scores
press 3 for exit

1
Sorted list of players through scores
JOE scored 173
JOE scored least runs : 173
ANN scored 185
MARTY scored 198
TIM scored 198
ROSEY scored 216
JAIN scored 319
BOB scored 486
LILY scored 651
GRANNY scored 912
LIZ scored 989
LIZ scored highest runs : 989

run:
Enter your choice
press 1 for ascending order of scores with players names
press 2 for alphabitical order of players names with scores
press 3 for exit

2
sorting by players in alphabitical order
ANN scored 198
BOB scored 486
GRANNY scored 651
JAIN scored 185
JOE scored 216
LILY scored 198
LIZ scored 912
MARTY scored 173
ROSEY scored 319

run:
Enter your choice
press 1 for ascending order of scores with players names
press 2 for alphabitical order of players names with scores
press 3 for exit

3
you have quitted

run:
Enter your choice
press 1 for ascending order of scores with players names
press 2 for alphabitical order of players names with scores
press 3 for exit

5
Invalid choice.
BUILD SUCCESSFUL (total time: 3 seconds)

Add a comment
Know the answer?
Add Answer to:
Please use pseudocode for this response, any additional advice for making this as easy to understand...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and...

    [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...

  • Write you code in a class named HighScores, in file named HighScores.java. Write a program that...

    Write you code in a class named HighScores, in file named HighScores.java. Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look approximately like this: Enter the name for score #1: Suzy Enter the score for score #1: 600 Enter the name for score...

  • Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the...

    Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the original high score program,: Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look exactly like this: Enter the name for score #1: Suzy Enter the score for...

  • I need to update this C++ code according to these instructions. The team name should be...

    I need to update this C++ code according to these instructions. The team name should be "Scooterbacks". I appreciate any help! Here is my code: #include <iostream> #include <string> #include <fstream> using namespace std; void menu(); int loadFile(string file,string names[],int jNo[],string pos[],int scores[]); string lowestScorer(string names[],int scores[],int size); string highestScorer(string names[],int scores[],int size); void searchByName(string names[],int jNo[],string pos[],int scores[],int size); int totalPoints(int scores[],int size); void sortByName(string names[],int jNo[],string pos[],int scores[],int size); void displayToScreen(string names[],int jNo[],string pos[],int scores[],int size); void writeToFile(string...

  • INPUT FILE INTO ARRAY. CHECKING FOR COMMAS AND SUCH. HOW TO DO? PLEASE READ CAREFULLY. MAX_SIZE...

    INPUT FILE INTO ARRAY. CHECKING FOR COMMAS AND SUCH. HOW TO DO? PLEASE READ CAREFULLY. MAX_SIZE is size of array When iterating over the candidates’ list, do not iterate over the entire array, but just over the records where data is filled in void readFile(Candidate candidates[]) – reads the elections.txt file, fills the candidates[] array. Hint: use substr() and find() functions. Set Score to 0. void List(Candidate candidates[]) – prints the array of Candidate structs. One candidate per one line,...

  • A particular talent competition has five judges, each of whom awards a score between 0 and...

    A particular talent competition has five judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores, such as 8.3, are allowed. A performer’s final score is determined by dropping the highest and the lowest score received then averaging the three remaining scores. Write a program that does the following: 1. Reads names and scores from an input file into a dynamically allocated array of structures. The first number in the input file represents the...

  • IN PYTHON PLEASE...... Process bowlers and their 3 bowling scores. Use my data file below: bowlers2.txt...

    IN PYTHON PLEASE...... Process bowlers and their 3 bowling scores. Use my data file below: bowlers2.txt ( Showed below) And you can also use a while loop to read your file if you prefer. How to average down an array, which you don’t have to do. In this case that would be the game 1 average for all bowlers for example. Find the low average and high average. Start with read the data into arrays/lists and printed out the arrays/lists...

  • Lab Objectives Be able to write methods Be able to call methods Be able to declare...

    Lab Objectives Be able to write methods Be able to call methods Be able to declare arrays Be able to fill an array using a loop Be able to access and process data in an array Introduction Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT