Question: please help make this code run import java.io . File; import java.io . FileWriter; import java.io . IOException; import java.util.ArrayList; import java.util.Scanner; class Person {
please help make this code run
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;
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
