Question: Using this code can you modify it to the intructions i have attached import java.io . File; import java.io . FileWriter; import java.io . IOException;
Using this code can you modify it to the intructions i have attached import java.ioFile;
import java.ioFileWriter;
import java.ioIOException;
import java.util.ArrayList;
import java.util.Scanner;
class Person
private String name;
private double height; in meters
private double weight; in kilograms
public PersonString name, double height, double weight
this.name name;
this.height height;
this.weight weight;
public double getHeight
return height;
public double getWeight
return weight;
public void setHeightdouble height
this.height height;
public void setWeightdouble weight
this.weight weight;
@Override
public String toString
return name height weight;
@Override
public boolean equalsObject o
if o null return false;
if this o return true;
if o instanceof Person return false;
Person p Person o;
return this.name.equalspname && this.height pheight && this.weight pweight;
interface PersonList
void addPerson p;
Person getint index;
class PersonSet implements PersonList
protected ArrayList people new ArrayList;
@Override
public void addPerson p
if people.containsp
people.addp;
@Override
public Person getint index
if index && index people.size
return people.getindex;
return null;
@Override
public String toString
StringBuilder sb new StringBuilder;
for Person p : people
sbappendptoStringappend
;
return sbtoString;
public class Main
public static void mainString args
Test the Person and PersonSet classes
Person person new PersonMario; Example data
PersonSet personSet new PersonSet;
personSet.addperson;
Reading from the hrtxt file
try
File inputFile new Filehrtxt;
Scanner fileReader new ScannerinputFile;
Skip the first row header
if fileReaderhasNextLine
fileReader.nextLine;
Reading and adding data to the PersonSet
while fileReaderhasNext
String name fileReader.next;
double height fileReader.nextDouble;
double weight fileReader.nextDouble;
Person person new Personname height, weight;
personSet.addperson;
fileReader.close;
Displaying the list of persons
System.out.printlnpersonSettoString;
Writing the list to an output file
FileWriter fileWriter new FileWriteroutputfiletxt;
fileWriter.writepersonSettoString;
fileWriter.close;
catch IOException e
eprintStackTrace;
System.out.printlne;
System.exit;
INSTRUCTIONS
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
You need to write two new classes for part : PersonImperialSet and PersonOrderedSet.
Add a toString method to PersonSet that loops through the ArrayList, concatenating the Persons data to a String variable, which is then returned. The format needs to match the format of hrtxt
Write a class named, PersonOrderedSet. This class should extend PersonSet and override the add method to add Persons in alphabetical order by name.
Write a class named, PersonImperialSet. This class should extend PersonSet and override the add method to convert the height measurement from centimeters to inches and the weight from kilograms to pounds. Look up the conversions online.
Modify Main to
A instantiate a PersonOrderedSet and a PersonImperial
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
