Question: using this code please modify it to match the intructions i have attached below import java.io . File; import java.io . FileWriter; import java.io .
using this code please modify it to match the intructions i have attached below
import java.ioFile;
import java.ioFileWriter;
import java.ioIOException;
import java.util.Scanner;
public class Main
public static void mainString args
System.out.println;
Don't overcomplicate the data
reading. After skipping the
first row, you can use the
following to read a row of
character info, assuming your
Scanner is named "fileReader"
String name fileReader.next;
double height fileReader.nextDouble;
double weight fileReader.nextDouble;
try
FileWriter fileWriterOrder new FileWriteroutputfiletxt;
fileWriterOrder.writetesting;
fileWriterOrder.close;
catchIOException e
eprintStackTrace;
System.out.printlne;
System.exit;
This assignment has the following objectives:
apply inheritance to objects
implement an interface
apply polymorphism to the class hierarchy
read data from file and create new output files
Problem Description
Nintendos human resources data is disorganized, full of duplicates, and in metric! The information is stored in a database file, hrtxt and its your task to create two new versions of it:
One version will be in alphabetical order
One version will be converted from metric to imperial units
And both versions will have no duplicates
List of classes that you will write:
Main contains the main method.
Person stores HR information
PersonList an interface
PersonSet a class implementing the interface
PersonImperialSet a class inheriting from PersonSet
PersonOrderedSet another class inheriting from PersonSet
Instructions for Part
For part you need to create three classes: Person, PersonList, and PersonSet. A mostlyblank Main.java has been provided, but youll need to fill it in AND you must answer the five questions at the top of the document.
Write a class named Person. This will be a very basic class with three attributes for storing name, height, and weight information. This class should also have a toString method that returns the Person data in a databaseready String format.
Write an interface named PersonList. The interface should have two abstract methods:
A add This method takes a Person as input and returns void.
B get This method takes an int as input and returns a Person at the corresponding index of the input int.
Write a class named, PersonSet, that implements the interface PersonList. Use an ArrayList and fill in the add and get methods. You may not use any built in Settype Java classes.
In addition to implementing add and get methods, PersonSet must make sure that no duplicate Persons are added. If you want to use the ArrayLists builtin contains method to make this easier, you will need to add an equals method to Person. See below for more details.
In the main method in Main:
A Instantiate a single Person object as a test. You can make up the data passed to the constructor.
B Instantiate a PersonSet object as a test.
C Read data in from the file hrtxt and display it on the command prompt.
If you want to use the ArrayLists contains method to see if a Person is already in the set, then you need to make sure that Person overrides the default equals method. To do so fill in the following comment outline and also refer to this resource for more information:
@Override
public boolean equalsObject o
if Object o is null then return false
if Object o this then return true
if Object o is not an instance of Person then return false
Declare a new variable of type Person perhaps named p
and assign it to Object o cast as type Person
if Person p has the same name, height, and weight as
this then return true
else return false
UML Diagram for HumanResources Part
PersonList
addp : Person : void
getindex : int : Person
The pound sign or hashtag in the next diagram indicates protected which is important so that the ordered set can easily sort the ArrayList in part
PersonSet PersonList
# people : ArrayList
add p : Person : void
get index : int : Person
toString : String
Person
name : string
height : double
weight : double
Person
getHeight : double
getWeight : double
setHeightheight : double : void
setWeightweight : double : void
toString : String
Compilation and Execution
I will test your program as follows:
javac java
java Main hrtxt
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
