Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This program is Football.java. Sample Input: ------------- Football Program -- v

ID: 3634324 • Letter: T

Question

This program is Football.java.

Sample Input:
-------------
Football Program -- v. 1.0 Fall 2011
LSU 514 3216 9 0
OSU 587 5016 9 0
STAN 558 4552 9 0
BSU 512 3832 9 0
BAMA 513 3956 8 1
OSU 482 2878 6 3
NoSuchTeam
LSU 5016
OSU 5016
NoSuchTeam


The first line of the input is a title line.
This line is read and printed, but it is not processed in any other way.

The next section of data, down through "NoSuchTeam", is the database of team names
and a few statistics. Each line in this section contains a team name abbreviation
(LSU, etc.), number of runs and catches (514, etc.), the total yards (3216, etc.),
the number of wins (9, etc.), and the number of losses(0, etc.). This section
is terminated by a sentinel String "NoSuchTeam".

The next section contains team abbreviations and total yards.
The program will look up these teams in the database.
If the team is not found, the program will print an appropriate message.
If the team is found, the program will print a message and the rest of the statistics.

The methods that are required could be organized as follows.
(You can change the parameter lists and/or parameter names to suit yourself.)

public static void main(...)

public static int readDatabase(Scanner scan, String sTeamSentinel,
String[] sTeamArr, int[] iAttemptsNumArr, int[] iYardsArr,
int[] iWinArr, int[] iLoseArr)

public static void printDatabase(int numRecords, String[] sTeamArr,
int[] iAttemptsNumArr, int[] iYardsArr, int[] iWinArr, int[] iLoseArr,
int iTeamNameLength)

public static void sortDatabase(int numRecords, String[] sTeamArr,
int[] iAttemptsNumArr, int[] iYardsArr, int[] iWinArr, int[] iLoseArr)

public static int seqSearch(int numRecords, String[] sTeamArr,
int[] iYardsNumArr, String sTeamKey, int iYardsNumKey)


This program will use five "parallel arrays", one array of Strings and four
arrays of ints.

Parallel arrays are discussed in the textbook on pages 298-299 (Chapter 7).

The arrays are declared in the main method, and could be declared as

final int ARR_SIZE = 100;

String[] sTeamArr = new String[ARR_SIZE];

int[]
iAttemptsNumArr = new int[ARR_SIZE],
iYardsArr = new int[ARR_SIZE],
iWinArr = new int[ARR_SIZE],
iLoseArr = new int[ARR_SIZE];

(Of course you could use any valid identifiers you wish for the names.)

In main, declare also as final named constants: a sentinel String
"NoSuchTeam", and a standard length of 4 for printing Team
abbreviations in the method printDatabase.

The title line could be printed either in main or in readDatabase.

The structure of the program is as follows.

main does any preliminary work necessary.
main calls readDatabase to read in the database of team name abbreviation and statistics,
stopping at the first sentinel String "NoSuchTeam". readDatabase returns
to main the number of records in the database (in the Sample Data, 5).
main calls printDatabase to print the database.
main calls sortDatabase to sort the database on team abbreviation
and total yards. (See the Sample Output below.)
main calls printDatabase to print the sorted database.
main then uses a sentinel loop to read in the search keys (LSU 5016, etc.).
Each search key consists of a team name abbreviation (a String)
and a total yards (an int).
For each search key, main calls seqSearch to search in the database
for this search key, and main prints a message for found or not found.

readDatabase checks to see that all five arrays are of the same length.
if not same length print an error message and terminate the program.
readDatabase contains a sentinel loop to read in each line of data
for the database, store the String and the four int values
into the next elements in the five arrays, count the lines of data,
and return the number of lines of data.
readDatabase checks that the arrays are large enough to hold the lines
of data; if not, it prints an error message and terminates.
readDatabase uses scan.has____ methods to check that data values
are available.

printDatabase prints the lines in the database. It attaches blanks
onto the end of each short department name, such as "OSU",
to make each name have the maximum standard length of iTeamLength.

sortDatabase sorts the data in the five arrays to put the team name abbreviations
into alphabetical order, and the total yards for each team
into numerical order. That is, LSU 3216 comes before OSU 2878 because
"LSU" comes before "OSU" (use the .compareTo method to do this), and
OSU 2878 comes before OSU 5016 because although the team name abbreviations
are the same, 2878 is less than 5016. See Chapter 6 of the textbook,
and the lecture notes, for the selection sort method.
Note that the pairs of elements in ALL FIVE ARRAYS must be swapped,
whenever the end of each pass of the selection sort is reached!

seqSearch searches two arrays to find if there is any team that has
a team name abbreviation equal to sTeamKey and a total yards equal to
iYardNumKey. If so, seqSearch returns the index (position) of that
data record in the five parallel arrays. If not, seqSearch returns -1 .
See Chapter 6 of the textbook, and the lecture notes,
for the sequential (linear) search algorithm.


The sentinel record is "NoSuchTeam", with no statistics.
The way to write a sentinel loop in readDatabase for this case is

read the first team name abbreviation
while(team name abbreviation is not equal to the sentinel)
{
read the number of runs and catches (when reading the database data records)
read the total yards
read the number of wins (when reading the database data records)
read the number of losses (when reading the database data records)
process this information
read the next team name abbreviation (or the sentinel)
}

In the sentinel loop in the main program, there is no runs and catches, number of wins
number of losses to be read.




Output:
----------------------------

Football Program -- v. 1.0 Fall 2011

Print the database:
Record number: 0 Team: LSU Advances: 514 Yards: 3216 Number of wins: 9 Number of losses: 0
Record number: 1 Team: OSU Advances: 587 Yards: 5016 Number of wins: 9 Number of losses: 0
Record number: 2 Team: STAN Advances: 558 Yards: 4552 Number of wins: 9 Number of losses: 0
Record number: 3 Team: BSU Advances: 512 Yards: 3832 Number of wins: 9 Number of losses: 0
Record number: 4 Team: BAMA Advances: 513 Yards: 3956 Number of wins: 8 Number of losses: 1
Record number: 5 Team: OSU Advances: 482 Yards: 2878 Number of wins: 6 Number of losses: 3

Sort the database.

Print the database:
Record number: 0 Team: BAMA Advances: 513 Yards: 3956 Number of wins: 8 Number of losses: 1
Record number: 1 Team: BSU Advances: 512 Yards: 3832 Number of wins: 9 Number of losses: 0
Record number: 2 Team: LSU Advances: 514 Yards: 3216 Number of wins: 9 Number of losses: 0
Record number: 3 Team: OSU Advances: 482 Yards: 2878 Number of wins: 6 Number of losses: 3
Record number: 4 Team: OSU Advances: 587 Yards: 5016 Number of wins: 9 Number of losses: 0
Record number: 5 Team: STAN Advances: 558 Yards: 4552 Number of wins: 9 Number of losses: 0

Is there a team with an abbreviation = LSU
and total yards = 5016 in the database,
and if so, what is its number of wins.
No, there is no such team in the database.

Is there a team with an abbreviation = OSU
and total yards = 5016 in the database,
and if so, what is its number of wins.
Yes. The number of wins is 9.

Explanation / Answer

Program Assignment 7 Fall 2011 Due before midnight Monday, 28 November 2011 Updated on: Monday, 14 November 2011 All updated are in red Note: Remember to follow all programming guidelines as given in Handout 4. This program is Football.java. Sample Input: ------------- Football Program -- v. 1.0 Fall 2011 LSU 514 3216 9 0 OSU 587 5016 9 0 STAN 558 4552 9 0 BSU 512 3832 9 0 BAMA 513 3956 8 1 OSU 482 2878 6 3 NoSuchTeam LSU 5016 OSU 5016 NoSuchTeam The first line of the input is a title line. This line is read and printed, but it is not processed in any other way. The next section of data, down through "NoSuchTeam", is the database of team names and a few statistics. Each line in this section contains a team name abbreviation (LSU, etc.), number of runs and catches (514, etc.), the total yards (3216, etc.), the number of wins (9, etc.), and the number of losses(0, etc.). This section is terminated by a sentinel String "NoSuchTeam". The next section contains team abbreviations and total yards. The program will look up these teams in the database. If the team is not found, the program will print an appropriate message. If the team is found, the program will print a message and the rest of the statistics. The methods that are required could be organized as follows. (You can change the parameter lists and/or parameter names to suit yourself.) public static void main(...) public static int readDatabase(Scanner scan, String sTeamSentinel, String[] sTeamArr, int[] iAttemptsNumArr, int[] iYardsArr, int[] iWinArr, int[] iLoseArr) public static void printDatabase(int numRecords, String[] sTeamArr, int[] iAttemptsNumArr, int[] iYardsArr, int[] iWinArr, int[] iLoseArr, int iTeamNameLength) public static void sortDatabase(int numRecords, String[] sTeamArr, int[] iAttemptsNumArr, int[] iYardsArr, int[] iWinArr, int[] iLoseArr) public static int seqSearch(int numRecords, String[] sTeamArr, int[] iYardsNumArr, String sTeamKey, int iYardsNumKey) This program will use five "parallel arrays", one array of Strings and four arrays of ints. Parallel arrays are discussed in the textbook on pages 298-299 (Chapter 7). The arrays are declared in the main method, and could be declared as final int ARR_SIZE = 100; String[] sTeamArr = new String[ARR_SIZE]; int[] iAttemptsNumArr = new int[ARR_SIZE], iYardsArr = new int[ARR_SIZE], iWinArr = new int[ARR_SIZE], iLoseArr = new int[ARR_SIZE]; (Of course you could use any valid identifiers you wish for the names.) In main, declare also as final named constants: a sentinel String "NoSuchTeam", and a standard length of 4 for printing Team abbreviations in the method printDatabase. The title line could be printed either in main or in readDatabase. The structure of the program is as follows. main does any preliminary work necessary. main calls readDatabase to read in the database of team name abbreviation and statistics, stopping at the first sentinel String "NoSuchTeam". readDatabase returns to main the number of records in the database (in the Sample Data, 5). main calls printDatabase to print the database. main calls sortDatabase to sort the database on team abbreviation and total yards. (See the Sample Output below.) main calls printDatabase to print the sorted database. main then uses a sentinel loop to read in the search keys (LSU 5016, etc.). Each search key consists of a team name abbreviation (a String) and a total yards (an int). For each search key, main calls seqSearch to search in the database for this search key, and main prints a message for found or not found. readDatabase checks to see that all five arrays are of the same length. if not same length print an error message and terminate the program. readDatabase contains a sentinel loop to read in each line of data for the database, store the String and the four int values into the next elements in the five arrays, count the lines of data, and return the number of lines of data. readDatabase checks that the arrays are large enough to hold the lines of data; if not, it prints an error message and terminates. readDatabase uses scan.has____ methods to check that data values are available. printDatabase prints the lines in the database. It attaches blanks onto the end of each short department name, such as "OSU", to make each name have the maximum standard length of iTeamLength. sortDatabase sorts the data in the five arrays to put the team name abbreviations into alphabetical order, and the total yards for each team into numerical order. That is, LSU 3216 comes before OSU 2878 because "LSU" comes before "OSU" (use the .compareTo method to do this), and OSU 2878 comes before OSU 5016 because although the team name abbreviations are the same, 2878 is less than 5016. See Chapter 6 of the textbook, and the lecture notes, for the selection sort method. Note that the pairs of elements in ALL FIVE ARRAYS must be swapped, whenever the end of each pass of the selection sort is reached! seqSearch searches two arrays to find if there is any team that has a team name abbreviation equal to sTeamKey and a total yards equal to iYardNumKey. If so, seqSearch returns the index (position) of that data record in the five parallel arrays. If not, seqSearch returns -1 . See Chapter 6 of the textbook, and the lecture notes, for the sequential (linear) search algorithm. The sentinel record is "NoSuchTeam", with no statistics. The way to write a sentinel loop in readDatabase for this case is read the first team name abbreviation while(team name abbreviation is not equal to the sentinel) { read the number of runs and catches (when reading the database data records) read the total yards read the number of wins (when reading the database data records) read the number of losses (when reading the database data records) process this information read the next team name abbreviation (or the sentinel) } In the sentinel loop in the main program, there is no runs and catches, number of wins number of losses to be read. Output: ---------------------------- Football Program -- v. 1.0 Fall 2011 Print the database: Record number: 0 Team: LSU Advances: 514 Yards: 3216 Number of wins: 9 Number of losses: 0 Record number: 1 Team: OSU Advances: 587 Yards: 5016 Number of wins: 9 Number of losses: 0 Record number: 2 Team: STAN Advances: 558 Yards: 4552 Number of wins: 9 Number of losses: 0 Record number: 3 Team: BSU Advances: 512 Yards: 3832 Number of wins: 9 Number of losses: 0 Record number: 4 Team: BAMA Advances: 513 Yards: 3956 Number of wins: 8 Number of losses: 1 Record number: 5 Team: OSU Advances: 482 Yards: 2878 Number of wins: 6 Number of losses: 3 Sort the database. Print the database: Record number: 0 Team: BAMA Advances: 513 Yards: 3956 Number of wins: 8 Number of losses: 1 Record number: 1 Team: BSU Advances: 512 Yards: 3832 Number of wins: 9 Number of losses: 0 Record number: 2 Team: LSU Advances: 514 Yards: 3216 Number of wins: 9 Number of losses: 0 Record number: 3 Team: OSU Advances: 482 Yards: 2878 Number of wins: 6 Number of losses: 3 Record number: 4 Team: OSU Advances: 587 Yards: 5016 Number of wins: 9 Number of losses: 0 Record number: 5 Team: STAN Advances: 558 Yards: 4552 Number of wins: 9 Number of losses: 0 Is there a team with an abbreviation = LSU and total yards = 5016 in the database, and if so, what is its number of wins. No, there is no such team in the database. Is there a team with an abbreviation = OSU and total yards = 5016 in the database, and if so, what is its number of wins. Yes. The number of wins is 9. Notes: 1. When finished submit your Java source file, x.java, by issuing the appropriate UNIX command line from the list below, where x.java is the name of your Java source file in this case x would be Football.java: If you are in Lab 1 (section 1): handin cs1113 pgm07.1 Football.java If you are in Lab 2 (section 12): handin cs1113 pgm07.2 Football.java If you are in Lab 3 (section 3): handin cs1113 pgm07.3 Football.java If you are in Lab 4 (section 4): handin cs1113 pgm07.4 Football.java If your solution is handed in successfully, you should see the message: Submitting Football.java... ok 3. You can check the handed in status using: If you are in Lab 1 (section 1): handin cs1113 pgm07.1 If you are in Lab 2 (section 2): handin cs1113 pgm07.2 If you are in Lab 3 (section 3): handin cs1113 pgm07.3 If you are in Lab 4 (section 4): handin cs1113 pgm07.4 You should see the message which includes the handin time, file size, and file name. The following input files have been received: Thurs Jan. 27 09:46:42 2006 994 bytes Football.java Note: All OSU students have access to PC labs located in 1. MS 108 2. CLB 408 3. Bennett B19 4. Kerr-Drummond Mezzanine For the hours each lab is open, see https://it.sharepoint.okstate.edu/TechnologySupport/DeskSide/labs/itlabschedule.htm MS 108 is open 24 hours per day, seven days per week, but is not accessible at certain hours when it is used for classes. The lab monitors in these labs may be able to answer questions about Windows, telnet, ftp, printing of output, etc. They are not supposed to answer questions about Java or questions related to any specific course.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote