1 Replies - 386 Views - Last Post: 28 November 2011 - 10:47 PM Rate Topic: -----

#1 ryano  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-November 11

parallel arrays programming assignment.

Posted 28 November 2011 - 10:18 PM

hello, can somebody help me in this programming assignment?

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.



this is my work
Public class Football
{
   public static void main(String[] args)
   {
      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];

      String title = " ";
      title = scan.nextLine();
      System.out.println(title);


      int Database = 0;
      Database = readDatabase(scan, sTeamArr);

      printDatabase(numRecords, sTeamArr, iAttemptsNumArr, iYardsArr, iWinArr, iLoseArr, iTeamNameLength);

      sortDatabase(numRecords, sTeamArr, iAttemptsNumArr, iYardsArr, iWinArr, iLoseArr);

      int sqSearch = 0;
      sqSearch = seqSearch(numRecords, sTeamArr, iYardsNumArr, sTeamKey, iYardsNumKey);




   }

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

   String end = "NoSuchTeam";

      if((scan.hasNext()) && (sTeamsentinel.length == iAttemptsNumArr.length == iYardsArr.length == iWinArr.length == iLoseArr.length))
      {
        sTeamSentinel = scan.next(),
        iAttemptsNumArr = scan.nextInt(),
        iYardsArr = scan.nextInt(),
        iWinArr = scan.nextInt,
        iLoseArr = scan.nextInt;
      }
      else
      (
        System.out.println("The length of the five arrays are not the same.");
        System.exit(0);
      }
   }

   while(!name.equals(end))
   {
        System.out.println(

   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)
   {

      string[] tempTeamArr = sTeamArr;
      Array.sorts(tempTeamArr)
      for(int i=0; i<tempTeamArr.length; i++)
      {
         for(int j=0; j<sTeamArr.length; j++)
         {
            if(tempTeamArr[i] == sTeamArr[j])
            {
              teamName = sTeamArr[i];
              System.out.println("Record number: " + numRecords[j] + " Team: " + sTeamArr[j] + " Advances: "
                                  + iAttemptsNumArr[j] + " Yards: " + iYardsArr[j] + " Number of wins: " + iWinArr[j]
                                  + " Number of losses: " + iLoseArr[j]);
              break;
            }
          }
       }
    }


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




i would appreciate it if someone can help me.

*Edited: welcome at DIC. Code tags added for a newbie
Please :code:

This post has been edited by pbl: 28 November 2011 - 10:35 PM


Is This A Good Question/Topic? 0
  • +

Replies To: parallel arrays programming assignment.

#2 ryano  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-November 11

Re: parallel arrays programming assignment.

Posted 28 November 2011 - 10:47 PM

please someone help me, or at least give me guidance to do this programming assignment..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1