Inspect the data file provided called superheroes.txt. This is a delimited text file which contains data about a number of comic book heroes. Each new line represents a single hero with nine fields delimited by the colon character. The nine fields represent different information about the hero in the following order:-
Write a Java program (as a NetBeans project) that opens up the data file, parses the superhero data, and prints the following information to the console:
a) The five tallest superheroes by height, ordered by the tallest first. Print both the hero pseudonym and the real name of each hero on a newline along with their height in centimetres.
b) The five weakest superheroes in terms of strength rating, ordered by the weakest first. Print both the hero pseudonym and real name of each hero on a newline along with their strength rating.
c) The total number of unique words contained within all of the descriptions for all superheroes in the data file that have an even number of letters.
d) The total number of unique words contained within all of the descriptions for all superheroes in the data file that have an odd number of letters.
With reference to tasks (c) and (d) described above, if a word has a non-letter character, then strip out the non-letter character and count only the letters of the remaining word, with the exception of the hyphen character, in which case the expression should be split into separate words.
For example, the word (acronym) S.H.I.E.L.D. should be treated as the single word SHIELD, whereas the hyphenated phrase X-Men should be treated as the two separate words X and Men.
If a word has an apostrophe, e.g., as in the possessive term humanitys, then it should be stripped to leave the single word humanitys.
On compiling and running, your program should have output similar to the following:
--- Five tallest heroes ---
Pseudonym A (real name), Height = a centimetres
Pseudonym B (real name), Height = b centimetres
Pseudonym C (real name), Height = c centimetres
Pseudonym D (real name), Height = d centimetres
Pseudonym E (real name), Height = e centimetres
--- Five weakest heroes ---
Pseudonym V (real name), Strength rating = v
3
Pseudonym W (real name), Strength rating = w
Pseudonym X (real name), Strength rating = x
Pseudonym Y (real name), Strength rating = y
Pseudonym Z (real name), Strength rating = z
--------------------------
Total number of unique even words in hero descriptions = P
Total number of unique odd words in hero descriptions = Q
Where the values Pseudonym A to Pseudonym E and Pseudonym V to Pseudonym Z are replaced with the relevant hero pseudonym, and the values a to e and v to z are replaced with their respective data values. The values P and Q are replaced with the respective word counts.
In addition to the console output, your program should also save all of the output to parts (a) to (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(s) properly.
Your program should handle exceptions robustly.
Locating and opening the data 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 in this document should be provided as separate NetBeans projects, and each project should have its own data file. The data file must be accessed relative to the NetBeans project folder. That is to say, when viewing the project folder in Windows Explorer, the 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. Figure 4: Location of the test data file when viewed in NetBeans (select ‘Files’)
With the 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 data file.
String fileLocation = System.getProperty("user.dir");
String dataPath = fileLocation + File.separator + "superheroes.txt";
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 a data file. The data file should be located relative to the NetBeans project root folder as before.
For this task, the delimited data file contains information about animals, specifically different types of predators. The data file is called predators.txt.
For this task, you will specifically be assessed on Java class design and good object-oriented programming principles in addition to correct program output.
For the predators data file, there are eight data fields representing the following information (in order): name, Latin name, weight, speed, risk of encounter, a killer rating, and an interesting fact about that animal.
For this task, you are required to design a class to represent a predator entity, create a collection to dynamically store all the predator records read from the data file, and then provide a console-based menu that loops, allowing the User to inspect the details of each predator interactively. Figure 5: UML class specification for Predator class
As part of your solution, you are required to design the class represented by the UML class specification illustrated in Figure 5. In addition, the natural ordering of the Predator class should be based on the Latin name of the animal, in ascending alphabetical order. This should be achieved by implementing the Comparable interface.
Once loaded into a suitable collection, the program should prompt the User with a menu to navigate the predator entities. This menu should loop until the User enters a character to exit the loop (e.g., zero as illustrated below). The menu should offer four options: First, Next, Previous and Last. On selection of First the details of the first predator should be displayed, according to the specified ordering on Latin name.
Accordingly, the Next, Previous and Last options should enable the User to navigate through the collection in order. The console interaction should be similar to that illustrated below:
First............1
Next.............2
Previous.........3
Last.............4
Exit.............0
Enter choice:> 1
E.g., the User could simply enter a digit 1-4 to navigate back and forth through the predators, and enter 0 (zero) to exit. So, for example if the User entered the number 1, then based on the default ordering on Latin name, the following details should be displayed:-
-------------------------------------------------------------------
Name The predator name
Latin name The predator Latin name
Weight The predator weight (kg)
Speed The predator speed (mph)
Stealth A numerical stealth value
Risk of encounter A numerical risk of encounter value
Killer rating A numerical killer rating value
Interesting fact:
The listed fact about that particular predator
-------------------------------------------------------------------
First............1
Next.............2
Previous.........3
Last.............4
Exit.............0
Enter choice:>
If the User then enters the number 2, then the next predator details should be displayed, based on the ordering of Latin name, if 3 is entered it is the previous animal in the ordering, and if 4 is entered then the details of the last animal in the ordering is displayed.
If the User is currently viewing the first predator in the collection, on selecting Previous, the display should not change, i.e., it should remain on the first predator and not wrap to the last predator in the ordered collection. Similarly, if the User is currently viewing the last predator in the collection, on selecting Next, the display should not change, i.e., it should remain on the last predator and not wrap to the first predator.
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 a data file of information. However, for this third task, the data file is a binary file rather than an ascii text file.
The name of the data file is sportscars.dat.
As before, the location of the data file should be relative to the root folder of the NetBeans project.
For this task, you are required to read a number of records from the binary data file and display some information about the data. The format of the data in the sportscars.dat file is as follows: Figure 6: Data file schema for sportscars.dat
That is to say, each sports car record is encoded in the binary data file with the above schema in sequence. When parsing the binary data file, and reading the information into your Java program, you should interpret the data as a series of strings.
For this task you are required to write a Java program that analyses the country of origin associated with each sports car listed in the test data file. For each unique country of origin that is contained in the entire sports car data set, the Java program should print to the output window (console) the country of origin and an associated list of sports cars (using their name). Each country of origin and associated list of sports should be printed on a separate line, as illustrated below.
Country 1 -> [Sports Car A, Sports Car B, Sports Car C]
Country 2 -> [Sports Car D, Sports Car E]
Country 3 -> [Sports Car F, Sports Car G, Sports Car H, Sports Car I]
. . .
Etc.
Each country of origin should be listed only once and the list of countries should be in alphabetical order. The list of sports cars associated with each country should also be listed in alphabetical order.
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(s) properly.
When checking your solution, the tutors will use a series of different test files with identical data structure but the number of records in the test files will vary.
For Task 3, you must assume that the verification data file(s) will have different numbers of records from the test file that is provided.
So, your program must be able to handle data files of different sizes (in terms of records), and handle exceptions robustly.