Sie sind auf Seite 1von 6

CSD2221 Individual Programming Assignment 2017

Deadline for submission 17:00, Friday, 8th December, 2017


Please read all of this assignment specification carefully first, before asking
your tutor any questions.
General information
You are required to submit your work via the dedicated Unihub assignment link in the week 10
folder by the specified deadline. This link will timeout at the submission deadline. Your work will
not be accepted as an email attachment if you miss this deadline. Therefore, you are strongly
advised to allow plenty of time to upload your work prior to the deadline.

Submission should comprise a single ZIP file. This file should contain a separate, cleaned, NetBeans
project for each of the three tasks described below. The work will be compiled and run in a Windows
environment, so it is strongly advised that you test your work in the University labs prior to cleaning
and submission.

That is to say, when the ZIP file is extracted, there should be three folders representing three
independent NetBeans projects as illustrated by Figure 1 below.

Figure 1: When the ZIP file is extracted there should be three folders named Task1, Task2 and Task3

Accordingly, when loaded into NetBeans, each task must be a separate project as illustrated by
Figure 2 below.

Figure 2: Each task must be a separate NetBeans Project

1
For this assignment, a single data (text) file is provided as a test file. This test file should be used for
all of the three tasks and should not be altered in any way (use a separate copy of the file for each
task, as described below). When checking your work, the tutors will use a different test file with
identical structure to that provided. That is to say, your programs should work because the structure
of the second test file is identical, but the program outputs will be different. The markers will
examine these outputs to verify the correctness of your programs.

Task 1 (20 marks)


Inspect the test file provided, which is called shark-data.txt. This is a delimited text file which
contains data about different types of sharks. Each new line represents a single shark species with
seven fields delimited by the colon character. The seven fields represent different information about
the shark in the following order:-

o Common name
o Latin name (by genus and species)
o Maximum length in centimetres that the shark can grow to
o Maximum depth the shark type can swim in metres
o The maximum number of young a female shark of that species would have in their lifetime
o A global presence indicator which is an integer between 1 and 10 to reflect how widespread
that shark species can roam
o A list of oceanic regions that the shark species has been observed, with each region
delimited by the comma character

Write a Java program (as a NetBeans project) that opens up the data file, parses the shark data, and
prints the following information to the console:

a) The three largest sharks by length, ordered by the largest first. Print the common name of
each shark on a newline along with the maximum length in centimetres.
b) The three smallest sharks by length, ordered by the smallest first. Print the common name of
each shark on a newline along with the maximum length in centimetres.
c) The total number of letters (not including whitespace characters) of all the Latin names for
all sharks in the data file. Duplicate letters must be counted.
d) The total number of unique words contained within all of the Latin names for all sharks in
the data file that have an even number of letters.
e) The total number of unique words contained within all of the Latin names for all sharks in
the data file that have an odd number of letters.

On compiling and running, your program should have output similar to the following:

--- Three largest sharks ---

Shark A, Length = a centimetres

Shark B, Length = b centimetres

Shark C, Length = c centimetres

2
--- Three smallest sharks ---

Shark X, Length = x centimetres

Shark Y, Length = y centimetres

Shark Z, Length = z centimetres

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

Total number of letters in all Latin names = P

Total number of unique even words in Latin names = Q

Total number of unique odd words in Latin names = R

Where the values Shark A through Shark C and Shark X through Shark Z are replaced with the
relevant shark common names, and the values a through c and x though z are replaced with their
respective maximum lengths, and the values P, Q and R replaced with the respective letter and word
counts.

In addition to the console output, your program should also save all of the output to parts (a)
through (e) above to a text file in the NetBeans project root folder. Call the file results.txt.

Having performed these actions, your program should close the opened file properly.

Your program should handle exceptions robustly.

Locating and opening the test file

You must not, under any circumstances, include a hard-coded file path to the test data file location.
Each of the three tasks described here should be separate NetBeans projects, and each project
should have its own copy of the test file. The test data file must be accessed relative to the NetBeans
project folder. That is to say, when viewing the project folder in Windows Explorer, the test data file
should be located as illustrated by Figure 3 below.

Figure 3: Location of the test data file when viewed in Windows Explorer

Accordingly, if you select the Files tab for the given NetBeans project, you will see the location of
the test data file relative to the project files, as illustrated by Figure 4 below.

3
Figure 4: Location of the test data file when viewed in NetBeans (select Files)

With the test data file located in the correct place (i.e., the root of the specific NetBeans project),
then the following lines of code will correctly return a relative path to the test file.

String fileLocation = System.getProperty("user.dir");

String dataPath = fileLocation + File.separator + "shark-data.txt";

In approaching the solution for your Java program, you are encouraged to design a Java class to
represent a shark species, with appropriate instance data, constructors, accessor methods (getter
methods) and an appropriate toString() method. The design of such a class will be taken into account
when assessing the work.

4
Task 2 (10 marks)
Remember, create a new (separate) NetBeans project for this task, named Task2.

As with Task1, you are required to write a Java program that opens the test data file of shark
information. Use a separate copy of the test data file located in the root of the Task2 NetBeans
project.

For this task you are required to write a Java program that analyses the oceanic regions associated
with each shark listed in the test data file. For each unique region that is contained in the entire
shark data set, the Java program should print to the output window (console) the oceanic region and
an associated list of sharks (using their common name, in alphabetical order) that are known to
roam within that region. Each oceanic region and associated list of sharks should be printed on a
separate line, as illustrated below.
Region 1 -> [Shark A, Shark B, Shark C]

Region 2 -> [Shark D, Shark E]

Region 3 -> [Shark F, Shark G, Shark H, Shark I]

. . .

Etc.

Each region should be listed only once, and the associated list of sharks for that region should not
contain duplicates. Sharks should be listed using their common name. The printout should list
regions alphabetically, and the list of sharks associated with each region should also be in
alphabetical order (based on their common name).

Outputs that are not in alphabetical order will be penalised with mark deductions.

In addition to the console output, your program should also save all of the output to a text file in the
NetBeans project root folder. Call the file results.txt.

Having performed these tasks, your program should close the opened file properly.

Your program should handle exceptions robustly.

5
Task 3 (10 marks)
Remember, create a new (separate) NetBeans project for this task, named Task3.

As with the previous tasks, you are required to write a Java program that opens the test data file of
shark information. Use a separate copy of the test data file located in the root of the Task3 NetBeans
project.

For this task, your Java program should prompt the User to enter a search string at the command
prompt, i.e., the NetBeans console window. The program should then match the input search string
against all of the Latin names in the shark data set and print a list of the sharks that match. The
matching should be case insensitive. In other words, the strings aBc and AbC should match.

On entering a search string expression at the console (command prompt), and after processing the
data matching, the program should return a list of matching sharks ordered by their common name
in alphabetical order, but which also lists their Latin name with all occurrences of matching string in
uppercase and the rest of the Latin name in lowercase. The following examples illustrate how the
program should operate.

Example 1
Enter search string for Latin names: > tUm

You entered string "tUm"

The following matches have been found:-

Nurse Shark - Latin name: Ginglymostoma cirraTUM

Variegated Shark - Latin name: Stegostoma fasciaTUM

Example 2
Enter search string for Latin names: > Charc

You entered string "Charc"

The following matches have been found:-

Great White Shark - Latin name: CHARCharodon CHARCharias

Das könnte Ihnen auch gefallen