SlideShare ist ein Scribd-Unternehmen logo
1 von 7
Downloaden Sie, um offline zu lesen
Having a problem figuring out where my errors are. The code is not running how I need it to so I
added a few print statements to help me figure it out but to no avail. Any help would be greatly
appreciated.
import java.io.File;
import java.util.Scanner;
import java.io.FileWriter;
import java.io.IOException;
public class Main
{
public static void main(String[] args)
{
if(args.length != 1)
{
System.out.println("Usage: java Main <input_file>");
return;
}
String inputFileName = args[0];
PersonSet orderedSet = new PersonOrderedSet();
PersonSet imperialSet = new PersonImperialSet();
try(Scanner sc = new Scanner(new File(inputFileName)))
{
if(sc.hasNextLine() && sc.nextLine().startsWith("NametHeight (cm)ttWeight (kg)"))
{
while(sc.hasNextLine())
{
String line = sc.nextLine();
System.out.println("Line:" + line);
String[] parts = line.split("t");
if(parts.length == 3)
{
String name = parts[0];
double height;
double weight;
try
{
height = Double.parseDouble(parts[1]);
weight = Double.parseDouble(parts[2]);
Person person = new Person(name, height, weight);
orderedSet.add(person);
imperialSet.add(person);
}
catch (NumberFormatException e)
{
// skip this line
}
}
}
}
}
catch (IOException e)
{
System.out.println("An error occurred while reading the file.");
e.printStackTrace();
return;
}
try(FileWriter writer = new FileWriter("hr_ordered_set_output.txt")) //write ordered set to file
{
writer.write("NametHeight (cm)ttHeight (kg)n");
writer.write(orderedSet.toText());
}
catch(IOException e)
{
System.out.println("An error occured while writing the ordered set output file.");
e.printStackTrace();
return;
}
try(FileWriter writer = new FileWriter("hr_imperial_set_output.txt")) //write imperial set to file
{
writer.write("NametHeight (in)ttWeight (lb)n");
writer.write(imperialSet.toText());
}
catch(IOException e)
{
System.out.println("An error occured while writing the imperial set output file.");
e.printStackTrace();
return;
}
// Output the ordered data and the imperial data to the screen/console, nicely formatted
System.out.println("Ordered data:");
System.out.println("Name Height (cm) Weight (kg)");
System.out.println("-------------------------------------------");
System.out.print(orderedSet.toString());
System.out.println("Imperial data:");
System.out.println("Name Height (in) Weight (lb)");
System.out.println("------------------------------------------");
System.out.print(imperialSet.toString());
}
}
import java.util.ArrayList;
public class Person implements Comparable<Person> //1
{
private String name;
private double height; //in centimeters
private double weight; // in kilagrams
public Person(String name, double height, double weight)//class that has constructors that
initialize name, height, and weight
{
this.name = name;
this.height = height;
this.weight = weight;
}
@Override
public String toString() //returns a string representation of the person's name, height, and weight
{
return String.format("%st%.1ftt%.1f", name, height, weight);
}
//Below are the getter and setter methods for name, height, and weight variables
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public double getHeight()
{
return height;
}
public void setHeight(double height)
{
this.height = height;
}
public double getWeight()
{
return weight;
}
public void setWeight(double weight)
{
this.weight = weight;
}
@Override
public boolean equals(Object o)
{
if(o == null)
{
return false;
}
if(o == this)
{
return true;
}
if(!(o instanceof Person))
{
return false;
}
Person p = (Person) o;
return this.name.equals(p.getName()) && Double.compare(this.height, p.getHeight()) == 0 &&
Double.compare(this.weight, p.getWeight()) == 0;
}
@Override
public int compareTo(Person p)
{
return this.name.compareTo(p.getName());
}
}
public interface PersonList //2
{
public void add(Person person); //a. takes person as an argument and adds it to the list of persons
public Person get(int index); //b. takes an integer index as an argument and returns the person
object at that index in the list
}
import java.util.ArrayList;
public class PersonSet implements PersonList //3
{
protected ArrayList<Person> personList;
public PersonSet()
{
personList = new ArrayList<Person>();
}
public void add(Person person)
{
System.out.println("Adding person: " + person);
if(!personList.contains(person)) //if person is not already in list, add it
{
personList.add(person);
}
}
public Person get(int index)
{
return personList.get(index); //implement the get method
}
public String toText()
{
System.out.println("Converting PersonSet to text...");
StringBuilder sb = new StringBuilder();
for(Person person: personList)
{
sb.append(person.toString() + "n");
}
return sb.toString();
}
}
import java.util.Collections;
import java.util.ArrayList;
public class PersonOrderedSet extends PersonSet
{
public PersonOrderedSet()
{
super();
}
@Override
public void add(Person person) //add the person object
{
super.add(person);
Collections.sort(personList); //sorts the list in alphabetical order by name
}
@Override
public String toString()
{
ArrayList<Person> sortedList = new ArrayList<Person>(personList);
Collections.sort(sortedList);
StringBuilder sb = new StringBuilder();
for(Person person: sortedList)
{
sb.append(person.toString() + "n");
}
return sb.toString();
}
}
import java.util.ArrayList;
public class PersonImperialSet extends PersonSet
{
public PersonImperialSet()
{
super();
}
@Override
public void add(Person person)
{
double heightInInches = person.getHeight() / 2.54;
double weightInPounds = person.getWeight() / 0.45359237;
Person imperialPerson = new Person(person.getName(), heightInInches, weightInPounds);
super.add(imperialPerson);
}
public String toText()
{
StringBuilder sb = new StringBuilder();
for (Person person : personList)
{
double heightInInches = person.getHeight() / 2.54;
double weightInPounds = person.getWeight() / 0.45359237;
sb.append(person.getName() + "t" + String.format("%.2f", heightInInches) + "tt" +
String.format("%.2f", weightInPounds) + "n");
}
return sb.toString();
}
}

Weitere Àhnliche Inhalte

Ähnlich wie Having a problem figuring out where my errors are- The code is not run.pdf

can you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdfcan you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdfsales88
 
AJUG April 2011 Raw hadoop example
AJUG April 2011 Raw hadoop exampleAJUG April 2011 Raw hadoop example
AJUG April 2011 Raw hadoop exampleChristopher Curtin
 
This is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdfThis is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdfakaluza07
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxwhitneyleman54422
 
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018Codemotion
 
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdfHow do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdfpnaran46
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Jonas Bonér
 
Pragmatic Real-World Scala
Pragmatic Real-World ScalaPragmatic Real-World Scala
Pragmatic Real-World Scalaparag978978
 
Creating a Facebook Clone - Part XLVI - Transcript.pdf
Creating a Facebook Clone - Part XLVI - Transcript.pdfCreating a Facebook Clone - Part XLVI - Transcript.pdf
Creating a Facebook Clone - Part XLVI - Transcript.pdfShaiAlmog1
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldBTI360
 
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfJAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfcalderoncasto9163
 
How to fix this error- Exception in thread -main- q- Exit java-lang-.pdf
How to fix this error-   Exception in thread -main- q- Exit java-lang-.pdfHow to fix this error-   Exception in thread -main- q- Exit java-lang-.pdf
How to fix this error- Exception in thread -main- q- Exit java-lang-.pdfaarokyaaqua
 
Understanding JavaScript Testing
Understanding JavaScript TestingUnderstanding JavaScript Testing
Understanding JavaScript Testingjeresig
 
Not sure why my program wont run.Programmer S.Villegas helper N.pdf
Not sure why my program wont run.Programmer S.Villegas helper N.pdfNot sure why my program wont run.Programmer S.Villegas helper N.pdf
Not sure why my program wont run.Programmer S.Villegas helper N.pdfwasemanivytreenrco51
 
HELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdfHELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdffatoryoutlets
 
Stop Making Excuses and Start Testing Your JavaScript
Stop Making Excuses and Start Testing Your JavaScriptStop Making Excuses and Start Testing Your JavaScript
Stop Making Excuses and Start Testing Your JavaScriptRyan Anklam
 
Better Software: introduction to good code
Better Software: introduction to good codeBetter Software: introduction to good code
Better Software: introduction to good codeGiordano Scalzo
 
There is something wrong with my program-- (once I do a for view all t.pdf
There is something wrong with my program-- (once I do a for view all t.pdfThere is something wrong with my program-- (once I do a for view all t.pdf
There is something wrong with my program-- (once I do a for view all t.pdfaashienterprisesuk
 
Manual tecnic sergi_subirats
Manual tecnic sergi_subiratsManual tecnic sergi_subirats
Manual tecnic sergi_subiratsSergi Subirats Cugat
 

Ähnlich wie Having a problem figuring out where my errors are- The code is not run.pdf (20)

can you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdfcan you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdf
 
AJUG April 2011 Raw hadoop example
AJUG April 2011 Raw hadoop exampleAJUG April 2011 Raw hadoop example
AJUG April 2011 Raw hadoop example
 
This is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdfThis is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdf
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
 
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
 
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdfHow do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
 
Pragmatic Real-World Scala
Pragmatic Real-World ScalaPragmatic Real-World Scala
Pragmatic Real-World Scala
 
Creating a Facebook Clone - Part XLVI - Transcript.pdf
Creating a Facebook Clone - Part XLVI - Transcript.pdfCreating a Facebook Clone - Part XLVI - Transcript.pdf
Creating a Facebook Clone - Part XLVI - Transcript.pdf
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
 
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfJAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
 
How to fix this error- Exception in thread -main- q- Exit java-lang-.pdf
How to fix this error-   Exception in thread -main- q- Exit java-lang-.pdfHow to fix this error-   Exception in thread -main- q- Exit java-lang-.pdf
How to fix this error- Exception in thread -main- q- Exit java-lang-.pdf
 
Understanding JavaScript Testing
Understanding JavaScript TestingUnderstanding JavaScript Testing
Understanding JavaScript Testing
 
Not sure why my program wont run.Programmer S.Villegas helper N.pdf
Not sure why my program wont run.Programmer S.Villegas helper N.pdfNot sure why my program wont run.Programmer S.Villegas helper N.pdf
Not sure why my program wont run.Programmer S.Villegas helper N.pdf
 
HELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdfHELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdf
 
Stop Making Excuses and Start Testing Your JavaScript
Stop Making Excuses and Start Testing Your JavaScriptStop Making Excuses and Start Testing Your JavaScript
Stop Making Excuses and Start Testing Your JavaScript
 
Better Software: introduction to good code
Better Software: introduction to good codeBetter Software: introduction to good code
Better Software: introduction to good code
 
There is something wrong with my program-- (once I do a for view all t.pdf
There is something wrong with my program-- (once I do a for view all t.pdfThere is something wrong with my program-- (once I do a for view all t.pdf
There is something wrong with my program-- (once I do a for view all t.pdf
 
Manual tecnic sergi_subirats
Manual tecnic sergi_subiratsManual tecnic sergi_subirats
Manual tecnic sergi_subirats
 
Migrating to JUnit 5
Migrating to JUnit 5Migrating to JUnit 5
Migrating to JUnit 5
 

Mehr von NicholasflqStewartl

he amount of income taxesThe amount of income taxes A- the corporation.pdf
he amount of income taxesThe amount of income taxes A- the corporation.pdfhe amount of income taxesThe amount of income taxes A- the corporation.pdf
he amount of income taxesThe amount of income taxes A- the corporation.pdfNicholasflqStewartl
 
Having a hard time with this one- Fill in the blanks with the follow.pdf
Having a hard time with this one-   Fill in the blanks with the follow.pdfHaving a hard time with this one-   Fill in the blanks with the follow.pdf
Having a hard time with this one- Fill in the blanks with the follow.pdfNicholasflqStewartl
 
Harriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdf
Harriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdfHarriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdf
Harriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdfNicholasflqStewartl
 
Hardworking Americans Should Not Be Living in Poverty has fallen to $6.pdf
Hardworking Americans Should Not Be Living in Poverty has fallen to $6.pdfHardworking Americans Should Not Be Living in Poverty has fallen to $6.pdf
Hardworking Americans Should Not Be Living in Poverty has fallen to $6.pdfNicholasflqStewartl
 
Government and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdf
Government and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdfGovernment and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdf
Government and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdfNicholasflqStewartl
 
Hammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdf
Hammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdfHammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdf
Hammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdfNicholasflqStewartl
 
Hacer un programa en c++ que lea la frase y determine que caracteres s.pdf
Hacer un programa en c++ que lea la frase y determine que caracteres s.pdfHacer un programa en c++ que lea la frase y determine que caracteres s.pdf
Hacer un programa en c++ que lea la frase y determine que caracteres s.pdfNicholasflqStewartl
 
Given the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdf
Given the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdfGiven the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdf
Given the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdfNicholasflqStewartl
 
Grouper Corporation is authorized to issue both preferred and commonst.pdf
Grouper Corporation is authorized to issue both preferred and commonst.pdfGrouper Corporation is authorized to issue both preferred and commonst.pdf
Grouper Corporation is authorized to issue both preferred and commonst.pdfNicholasflqStewartl
 
Guessing or knowing the initial TCP sequence number (ISN) that a serve.pdf
Guessing or knowing the initial TCP sequence number (ISN) that a serve.pdfGuessing or knowing the initial TCP sequence number (ISN) that a serve.pdf
Guessing or knowing the initial TCP sequence number (ISN) that a serve.pdfNicholasflqStewartl
 
Given the following XML fragment- what XPath expression would select a.pdf
Given the following XML fragment- what XPath expression would select a.pdfGiven the following XML fragment- what XPath expression would select a.pdf
Given the following XML fragment- what XPath expression would select a.pdfNicholasflqStewartl
 
Greener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdf
Greener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdfGreener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdf
Greener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdfNicholasflqStewartl
 
Given the following for the Titan Company- the company began operation.pdf
Given the following for the Titan Company- the company began operation.pdfGiven the following for the Titan Company- the company began operation.pdf
Given the following for the Titan Company- the company began operation.pdfNicholasflqStewartl
 
Given the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdfGiven the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdfNicholasflqStewartl
 
Given the following class in Java- public class ThreeTenDynArray-T- {.pdf
Given the following class in Java-  public class ThreeTenDynArray-T- {.pdfGiven the following class in Java-  public class ThreeTenDynArray-T- {.pdf
Given the following class in Java- public class ThreeTenDynArray-T- {.pdfNicholasflqStewartl
 
Given Information #1- Period 1 is when Devah is working and earning mo.pdf
Given Information #1- Period 1 is when Devah is working and earning mo.pdfGiven Information #1- Period 1 is when Devah is working and earning mo.pdf
Given Information #1- Period 1 is when Devah is working and earning mo.pdfNicholasflqStewartl
 
Give concise and substantial answers by relating your answers to your.pdf
Give concise and substantial answers by relating your answers to your.pdfGive concise and substantial answers by relating your answers to your.pdf
Give concise and substantial answers by relating your answers to your.pdfNicholasflqStewartl
 
Given a stream of strings- remove all empty strings- import java-uti.pdf
Given a stream of strings- remove all empty strings-   import java-uti.pdfGiven a stream of strings- remove all empty strings-   import java-uti.pdf
Given a stream of strings- remove all empty strings- import java-uti.pdfNicholasflqStewartl
 
Given an IntNode struct and the operating functions for a linked list-.pdf
Given an IntNode struct and the operating functions for a linked list-.pdfGiven an IntNode struct and the operating functions for a linked list-.pdf
Given an IntNode struct and the operating functions for a linked list-.pdfNicholasflqStewartl
 
Given a string- does -oce- appear in the middle of the string- To defi.pdf
Given a string- does -oce- appear in the middle of the string- To defi.pdfGiven a string- does -oce- appear in the middle of the string- To defi.pdf
Given a string- does -oce- appear in the middle of the string- To defi.pdfNicholasflqStewartl
 

Mehr von NicholasflqStewartl (20)

he amount of income taxesThe amount of income taxes A- the corporation.pdf
he amount of income taxesThe amount of income taxes A- the corporation.pdfhe amount of income taxesThe amount of income taxes A- the corporation.pdf
he amount of income taxesThe amount of income taxes A- the corporation.pdf
 
Having a hard time with this one- Fill in the blanks with the follow.pdf
Having a hard time with this one-   Fill in the blanks with the follow.pdfHaving a hard time with this one-   Fill in the blanks with the follow.pdf
Having a hard time with this one- Fill in the blanks with the follow.pdf
 
Harriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdf
Harriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdfHarriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdf
Harriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdf
 
Hardworking Americans Should Not Be Living in Poverty has fallen to $6.pdf
Hardworking Americans Should Not Be Living in Poverty has fallen to $6.pdfHardworking Americans Should Not Be Living in Poverty has fallen to $6.pdf
Hardworking Americans Should Not Be Living in Poverty has fallen to $6.pdf
 
Government and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdf
Government and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdfGovernment and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdf
Government and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdf
 
Hammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdf
Hammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdfHammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdf
Hammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdf
 
Hacer un programa en c++ que lea la frase y determine que caracteres s.pdf
Hacer un programa en c++ que lea la frase y determine que caracteres s.pdfHacer un programa en c++ que lea la frase y determine que caracteres s.pdf
Hacer un programa en c++ que lea la frase y determine que caracteres s.pdf
 
Given the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdf
Given the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdfGiven the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdf
Given the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdf
 
Grouper Corporation is authorized to issue both preferred and commonst.pdf
Grouper Corporation is authorized to issue both preferred and commonst.pdfGrouper Corporation is authorized to issue both preferred and commonst.pdf
Grouper Corporation is authorized to issue both preferred and commonst.pdf
 
Guessing or knowing the initial TCP sequence number (ISN) that a serve.pdf
Guessing or knowing the initial TCP sequence number (ISN) that a serve.pdfGuessing or knowing the initial TCP sequence number (ISN) that a serve.pdf
Guessing or knowing the initial TCP sequence number (ISN) that a serve.pdf
 
Given the following XML fragment- what XPath expression would select a.pdf
Given the following XML fragment- what XPath expression would select a.pdfGiven the following XML fragment- what XPath expression would select a.pdf
Given the following XML fragment- what XPath expression would select a.pdf
 
Greener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdf
Greener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdfGreener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdf
Greener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdf
 
Given the following for the Titan Company- the company began operation.pdf
Given the following for the Titan Company- the company began operation.pdfGiven the following for the Titan Company- the company began operation.pdf
Given the following for the Titan Company- the company began operation.pdf
 
Given the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdfGiven the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdf
 
Given the following class in Java- public class ThreeTenDynArray-T- {.pdf
Given the following class in Java-  public class ThreeTenDynArray-T- {.pdfGiven the following class in Java-  public class ThreeTenDynArray-T- {.pdf
Given the following class in Java- public class ThreeTenDynArray-T- {.pdf
 
Given Information #1- Period 1 is when Devah is working and earning mo.pdf
Given Information #1- Period 1 is when Devah is working and earning mo.pdfGiven Information #1- Period 1 is when Devah is working and earning mo.pdf
Given Information #1- Period 1 is when Devah is working and earning mo.pdf
 
Give concise and substantial answers by relating your answers to your.pdf
Give concise and substantial answers by relating your answers to your.pdfGive concise and substantial answers by relating your answers to your.pdf
Give concise and substantial answers by relating your answers to your.pdf
 
Given a stream of strings- remove all empty strings- import java-uti.pdf
Given a stream of strings- remove all empty strings-   import java-uti.pdfGiven a stream of strings- remove all empty strings-   import java-uti.pdf
Given a stream of strings- remove all empty strings- import java-uti.pdf
 
Given an IntNode struct and the operating functions for a linked list-.pdf
Given an IntNode struct and the operating functions for a linked list-.pdfGiven an IntNode struct and the operating functions for a linked list-.pdf
Given an IntNode struct and the operating functions for a linked list-.pdf
 
Given a string- does -oce- appear in the middle of the string- To defi.pdf
Given a string- does -oce- appear in the middle of the string- To defi.pdfGiven a string- does -oce- appear in the middle of the string- To defi.pdf
Given a string- does -oce- appear in the middle of the string- To defi.pdf
 

KĂŒrzlich hochgeladen

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
TỔNG ÔN TáșŹP THI VÀO LỚP 10 MÔN TIáșŸNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGở Â...
TỔNG ÔN TáșŹP THI VÀO LỚP 10 MÔN TIáșŸNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGở Â...TỔNG ÔN TáșŹP THI VÀO LỚP 10 MÔN TIáșŸNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGở Â...
TỔNG ÔN TáșŹP THI VÀO LỚP 10 MÔN TIáșŸNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGở Â...Nguyen Thanh Tu Collection
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
80 ĐỀ THI THỏ TUYỂN SINH TIáșŸNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỏ TUYỂN SINH TIáșŸNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỏ TUYỂN SINH TIáșŸNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỏ TUYỂN SINH TIáșŸNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 

KĂŒrzlich hochgeladen (20)

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
TỔNG ÔN TáșŹP THI VÀO LỚP 10 MÔN TIáșŸNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGở Â...
TỔNG ÔN TáșŹP THI VÀO LỚP 10 MÔN TIáșŸNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGở Â...TỔNG ÔN TáșŹP THI VÀO LỚP 10 MÔN TIáșŸNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGở Â...
TỔNG ÔN TáșŹP THI VÀO LỚP 10 MÔN TIáșŸNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGở Â...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
80 ĐỀ THI THỏ TUYỂN SINH TIáșŸNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỏ TUYỂN SINH TIáșŸNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỏ TUYỂN SINH TIáșŸNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỏ TUYỂN SINH TIáșŸNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 

Having a problem figuring out where my errors are- The code is not run.pdf

  • 1. Having a problem figuring out where my errors are. The code is not running how I need it to so I added a few print statements to help me figure it out but to no avail. Any help would be greatly appreciated. import java.io.File; import java.util.Scanner; import java.io.FileWriter; import java.io.IOException; public class Main { public static void main(String[] args) { if(args.length != 1) { System.out.println("Usage: java Main <input_file>"); return; } String inputFileName = args[0]; PersonSet orderedSet = new PersonOrderedSet(); PersonSet imperialSet = new PersonImperialSet(); try(Scanner sc = new Scanner(new File(inputFileName))) { if(sc.hasNextLine() && sc.nextLine().startsWith("NametHeight (cm)ttWeight (kg)")) { while(sc.hasNextLine()) { String line = sc.nextLine(); System.out.println("Line:" + line); String[] parts = line.split("t"); if(parts.length == 3) { String name = parts[0]; double height; double weight; try { height = Double.parseDouble(parts[1]); weight = Double.parseDouble(parts[2]); Person person = new Person(name, height, weight); orderedSet.add(person); imperialSet.add(person); }
  • 2. catch (NumberFormatException e) { // skip this line } } } } } catch (IOException e) { System.out.println("An error occurred while reading the file."); e.printStackTrace(); return; } try(FileWriter writer = new FileWriter("hr_ordered_set_output.txt")) //write ordered set to file { writer.write("NametHeight (cm)ttHeight (kg)n"); writer.write(orderedSet.toText()); } catch(IOException e) { System.out.println("An error occured while writing the ordered set output file."); e.printStackTrace(); return; } try(FileWriter writer = new FileWriter("hr_imperial_set_output.txt")) //write imperial set to file { writer.write("NametHeight (in)ttWeight (lb)n"); writer.write(imperialSet.toText()); } catch(IOException e) { System.out.println("An error occured while writing the imperial set output file."); e.printStackTrace(); return; } // Output the ordered data and the imperial data to the screen/console, nicely formatted System.out.println("Ordered data:"); System.out.println("Name Height (cm) Weight (kg)"); System.out.println("-------------------------------------------"); System.out.print(orderedSet.toString()); System.out.println("Imperial data:"); System.out.println("Name Height (in) Weight (lb)");
  • 3. System.out.println("------------------------------------------"); System.out.print(imperialSet.toString()); } } import java.util.ArrayList; public class Person implements Comparable<Person> //1 { private String name; private double height; //in centimeters private double weight; // in kilagrams public Person(String name, double height, double weight)//class that has constructors that initialize name, height, and weight { this.name = name; this.height = height; this.weight = weight; } @Override public String toString() //returns a string representation of the person's name, height, and weight { return String.format("%st%.1ftt%.1f", name, height, weight); } //Below are the getter and setter methods for name, height, and weight variables public String getName() { return name; } public void setName(String name) { this.name = name; } public double getHeight() { return height; }
  • 4. public void setHeight(double height) { this.height = height; } public double getWeight() { return weight; } public void setWeight(double weight) { this.weight = weight; } @Override public boolean equals(Object o) { if(o == null) { return false; } if(o == this) { return true; } if(!(o instanceof Person)) { return false; } Person p = (Person) o; return this.name.equals(p.getName()) && Double.compare(this.height, p.getHeight()) == 0 && Double.compare(this.weight, p.getWeight()) == 0; } @Override public int compareTo(Person p) { return this.name.compareTo(p.getName()); } }
  • 5. public interface PersonList //2 { public void add(Person person); //a. takes person as an argument and adds it to the list of persons public Person get(int index); //b. takes an integer index as an argument and returns the person object at that index in the list } import java.util.ArrayList; public class PersonSet implements PersonList //3 { protected ArrayList<Person> personList; public PersonSet() { personList = new ArrayList<Person>(); } public void add(Person person) { System.out.println("Adding person: " + person); if(!personList.contains(person)) //if person is not already in list, add it { personList.add(person); } } public Person get(int index) { return personList.get(index); //implement the get method } public String toText() { System.out.println("Converting PersonSet to text..."); StringBuilder sb = new StringBuilder(); for(Person person: personList) { sb.append(person.toString() + "n"); } return sb.toString(); } }
  • 6. import java.util.Collections; import java.util.ArrayList; public class PersonOrderedSet extends PersonSet { public PersonOrderedSet() { super(); } @Override public void add(Person person) //add the person object { super.add(person); Collections.sort(personList); //sorts the list in alphabetical order by name } @Override public String toString() { ArrayList<Person> sortedList = new ArrayList<Person>(personList); Collections.sort(sortedList); StringBuilder sb = new StringBuilder(); for(Person person: sortedList) { sb.append(person.toString() + "n"); } return sb.toString(); } } import java.util.ArrayList; public class PersonImperialSet extends PersonSet { public PersonImperialSet() { super(); } @Override public void add(Person person) { double heightInInches = person.getHeight() / 2.54; double weightInPounds = person.getWeight() / 0.45359237;
  • 7. Person imperialPerson = new Person(person.getName(), heightInInches, weightInPounds); super.add(imperialPerson); } public String toText() { StringBuilder sb = new StringBuilder(); for (Person person : personList) { double heightInInches = person.getHeight() / 2.54; double weightInPounds = person.getWeight() / 0.45359237; sb.append(person.getName() + "t" + String.format("%.2f", heightInInches) + "tt" + String.format("%.2f", weightInPounds) + "n"); } return sb.toString(); } }