SlideShare a Scribd company logo
1 of 7
Download to read offline
Not sure why my program wont run.
//Programmer: S.Villegas helper Noah
//File name: PP88ArrayList.java
//Description:
//****************************
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class PP88ArrayList
{
public static void main(String[]args)
{
ArrayList persons = new ArrayList(25);
String fileName = "Zips.dat";
int i;
Scanner filescasnner = null;
try
{
filescasnner=new Scanner(new File(fileName));
for(i=0;i persons)
{
for (int i = 0; i < persons.size(); i++)
{
for (int j = 0; j < persons.size()-1; j++)
{
if((persons.get(j).getFirstName().compareTo(persons.get(j+1).getFirstName()))>0)
{
Person temp= persons.get(j);
persons.set(j, persons.get(j+1));
persons.set(j+1, temp);
}
}
}
}
public static void sortByZipCode(ArrayList persons)
{
for (int i = 0; i < persons.size(); i++)
{
for (int j = 0; j < persons.size()-1; j++)
{
if(persons.get(j).getZipCode()>persons.get(j+1).getZipCode())
{
Person temp= persons.get(j);
persons.set(j, persons.get(j+1));
persons.set(j+1, temp);
}
}
}
}
}
//Programmer: S.Villegas helper Noah
//File name: PersonList.java
//Description:
//******************************
public class PersonList
{
private String firstName, lastName;
private int Zip;
public PersonList(String firstName,String lastName, int Zip)
{
this.firstName = firstName;
this.lastName = lastName;
this.Zip = Zip;
}
public String getFirstName()
{
return firstName;
}
public int getZipCode()
{
return Zip;
}
public String toString()
{
return String.format("%-15s%-15s%-10d",firstName,lastName,Zip);
}
}
Solution
//File name: PersonList.java
public class PersonList
{
private String firstName, lastName;
private int Zip;
public PersonList(String firstName,String lastName, int Zip)
{
this.firstName = firstName;
this.lastName = lastName;
this.Zip = Zip;
}
public String getFirstName()
{
return firstName;
}
public int getZipCode()
{
return Zip;
}
public String toString()
{
return String.format("%-15s%-15s%-10d",firstName,lastName,Zip);
}
}
//File name: PP88ArrayList.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class PP88ArrayList
{
public static void main(String[]args)
{
ArrayList persons = new ArrayList(25);
String fileName = "Zips.dat";
int i;
Scanner filescasnner = null;
try
{
filescasnner=new Scanner(new File(fileName));
while(filescasnner.hasNextLine())
{
String firstName = filescasnner.next();
String lastName = filescasnner.next();
int Zip = filescasnner.nextInt();
persons.add(new PersonList(firstName, lastName, Zip));
}
filescasnner.close();
}
catch (FileNotFoundException e)
{
System.out.println(e.getMessage());
}
System.out.println(" List of names and zip codes: ");
System.out.printf("%-15s%-15s%-15s ","First Name","Last Name","Zip");
for (int j = 0; j < persons.size(); j++)
{
System.out.println(persons.get(j));
}
System.out.println(" List of names sort by first name");
sortByName(persons);
System.out.printf("%-15s%-15s%-15s ","First Name","Last Name","Zip");
for (int j = 0; j < persons.size(); j++)
{
System.out.println(persons.get(j));
}
System.out.println(" List of names sort by zip code");
sortByZipCode(persons);
System.out.printf("%-15s%-15s%-15s ","First Name","Last Name","Zip");
for (int j = 0; j < persons.size(); j++)
{
System.out.println(persons.get(j));
}
}
public static void sortByName(ArrayList persons)
{
for (int i = 0; i < persons.size(); i++)
{
for (int j = 0; j < persons.size()-1; j++)
{
if((persons.get(j).getFirstName().compareTo(persons.get(j+1).getFirstName()))>0)
{
PersonList temp= persons.get(j);
persons.set(j, persons.get(j+1));
persons.set(j+1, temp);
}
}
}
}
public static void sortByZipCode(ArrayList persons)
{
for (int i = 0; i < persons.size(); i++)
{
for (int j = 0; j < persons.size()-1; j++)
{
if(persons.get(j).getZipCode()>persons.get(j+1).getZipCode())
{
PersonList temp= persons.get(j);
persons.set(j, persons.get(j+1));
persons.set(j+1, temp);
}
}
}
}
}
/*
Zips.dat
kyle mills 1453
alex hales 2321
eoin morgan 3453
shakid hasan 4756
tim southee 5534
output:
List of names and zip codes:
First Name Last Name Zip
kyle mills 1453
alex hales 2321
eoin morgan 3453
shakid hasan 4756
tim southee 5534
List of names sort by first name
First Name Last Name Zip
alex hales 2321
eoin morgan 3453
kyle mills 1453
shakid hasan 4756
tim southee 5534
List of names sort by zip code
First Name Last Name Zip
kyle mills 1453
alex hales 2321
eoin morgan 3453
shakid hasan 4756
tim southee 5534
*/

More Related Content

Similar to Not sure why my program wont run.Programmer S.Villegas helper N.pdf

3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdfalliedscorporation
 
import java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdfimport java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdfstopgolook
 
Implement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdfImplement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdfamrishinda
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfNicholasflqStewartl
 
Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdfICADCMLTPC
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdfanupamfootwear
 
In Java- Create a Graduate class derived from Student- A graduate has.pdf
In Java- Create a Graduate class derived from Student- A graduate has.pdfIn Java- Create a Graduate class derived from Student- A graduate has.pdf
In Java- Create a Graduate class derived from Student- A graduate has.pdfStewart29UReesa
 
import java.io.BufferedReader;import java.io.File;import java.io.pdf
import java.io.BufferedReader;import java.io.File;import java.io.pdfimport java.io.BufferedReader;import java.io.File;import java.io.pdf
import java.io.BufferedReader;import java.io.File;import java.io.pdfmanojmozy
 
Tips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET ApplicationTips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET ApplicationJoni
 
Exceptions and errors in Java
Exceptions and errors in JavaExceptions and errors in Java
Exceptions and errors in JavaManuela Grindei
 
QA Auotmation Java programs,theory
QA Auotmation Java programs,theory QA Auotmation Java programs,theory
QA Auotmation Java programs,theory archana singh
 
Pick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitPick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitVaclav Pech
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdffantasiatheoutofthef
 

Similar to Not sure why my program wont run.Programmer S.Villegas helper N.pdf (20)

3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
 
import java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdfimport java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdf
 
Implement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdfImplement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdf
 
JAVA.pdf
JAVA.pdfJAVA.pdf
JAVA.pdf
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdf
 
Java practical
Java practicalJava practical
Java practical
 
Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdf
 
Java 104
Java 104Java 104
Java 104
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 
In Java- Create a Graduate class derived from Student- A graduate has.pdf
In Java- Create a Graduate class derived from Student- A graduate has.pdfIn Java- Create a Graduate class derived from Student- A graduate has.pdf
In Java- Create a Graduate class derived from Student- A graduate has.pdf
 
import java.io.BufferedReader;import java.io.File;import java.io.pdf
import java.io.BufferedReader;import java.io.File;import java.io.pdfimport java.io.BufferedReader;import java.io.File;import java.io.pdf
import java.io.BufferedReader;import java.io.File;import java.io.pdf
 
Lab4
Lab4Lab4
Lab4
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
Ann
AnnAnn
Ann
 
Tips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET ApplicationTips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET Application
 
Exceptions and errors in Java
Exceptions and errors in JavaExceptions and errors in Java
Exceptions and errors in Java
 
QA Auotmation Java programs,theory
QA Auotmation Java programs,theory QA Auotmation Java programs,theory
QA Auotmation Java programs,theory
 
Pick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitPick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruit
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
 

More from wasemanivytreenrco51

Explain what differential cell affinity is, how this process is acco.pdf
Explain what differential cell affinity is, how this process is acco.pdfExplain what differential cell affinity is, how this process is acco.pdf
Explain what differential cell affinity is, how this process is acco.pdfwasemanivytreenrco51
 
Explain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdfExplain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdfwasemanivytreenrco51
 
Entamoeba histolytica is an amoeba responsible for the gastrointestin.pdf
Entamoeba histolytica is an amoeba responsible for the gastrointestin.pdfEntamoeba histolytica is an amoeba responsible for the gastrointestin.pdf
Entamoeba histolytica is an amoeba responsible for the gastrointestin.pdfwasemanivytreenrco51
 
Describe briefly each mouth part of the grasshopper. b. Describe how.pdf
Describe briefly each mouth part of the grasshopper.  b. Describe how.pdfDescribe briefly each mouth part of the grasshopper.  b. Describe how.pdf
Describe briefly each mouth part of the grasshopper. b. Describe how.pdfwasemanivytreenrco51
 
Contrast the views of Piaget and Bandura on how children develop..pdf
Contrast the views of Piaget and Bandura on how children develop..pdfContrast the views of Piaget and Bandura on how children develop..pdf
Contrast the views of Piaget and Bandura on how children develop..pdfwasemanivytreenrco51
 
Compute the probability of event E if the odds in favor of E are 31.pdf
Compute the probability of event E if the odds in favor of E are  31.pdfCompute the probability of event E if the odds in favor of E are  31.pdf
Compute the probability of event E if the odds in favor of E are 31.pdfwasemanivytreenrco51
 
Compare and contrast the world population with that of the United St.pdf
Compare and contrast the world population with that of the United St.pdfCompare and contrast the world population with that of the United St.pdf
Compare and contrast the world population with that of the United St.pdfwasemanivytreenrco51
 
8. What protocol is are layers 6 and 7 of the OSI model based on.pdf
8. What protocol is are layers 6 and 7 of the OSI model based on.pdf8. What protocol is are layers 6 and 7 of the OSI model based on.pdf
8. What protocol is are layers 6 and 7 of the OSI model based on.pdfwasemanivytreenrco51
 
Which statement is true of serous membranesA) They line closed cavi.pdf
Which statement is true of serous membranesA) They line closed cavi.pdfWhich statement is true of serous membranesA) They line closed cavi.pdf
Which statement is true of serous membranesA) They line closed cavi.pdfwasemanivytreenrco51
 
Which of the following is not included in the calculation of the VIX .pdf
Which of the following is not included in the calculation of the VIX .pdfWhich of the following is not included in the calculation of the VIX .pdf
Which of the following is not included in the calculation of the VIX .pdfwasemanivytreenrco51
 
What is an Accountable Care Organizations (ACO) How does an ACOs .pdf
What is an Accountable Care Organizations (ACO) How does an ACOs .pdfWhat is an Accountable Care Organizations (ACO) How does an ACOs .pdf
What is an Accountable Care Organizations (ACO) How does an ACOs .pdfwasemanivytreenrco51
 
True or false A selective force (such as antibiotics) must be prese.pdf
True or false A selective force (such as antibiotics) must be prese.pdfTrue or false A selective force (such as antibiotics) must be prese.pdf
True or false A selective force (such as antibiotics) must be prese.pdfwasemanivytreenrco51
 
The receptors in the feedback loop regulating ADH secretion are osmor.pdf
The receptors in the feedback loop regulating ADH secretion are osmor.pdfThe receptors in the feedback loop regulating ADH secretion are osmor.pdf
The receptors in the feedback loop regulating ADH secretion are osmor.pdfwasemanivytreenrco51
 
The UV spectrum of the hot B0V star is significantly below the conti.pdf
The UV spectrum of the hot B0V star is significantly below the conti.pdfThe UV spectrum of the hot B0V star is significantly below the conti.pdf
The UV spectrum of the hot B0V star is significantly below the conti.pdfwasemanivytreenrco51
 
Q2 For any drosophila population, what is the proportion of live ho.pdf
Q2 For any drosophila population, what is the proportion of live ho.pdfQ2 For any drosophila population, what is the proportion of live ho.pdf
Q2 For any drosophila population, what is the proportion of live ho.pdfwasemanivytreenrco51
 
Prove asymptotic upper and lower hounds for each of the following sp.pdf
Prove asymptotic upper and lower hounds for each of the following  sp.pdfProve asymptotic upper and lower hounds for each of the following  sp.pdf
Prove asymptotic upper and lower hounds for each of the following sp.pdfwasemanivytreenrco51
 
pls show details.thx 1. Consider the vectors v1 (a Find the projecti.pdf
pls show details.thx 1. Consider the vectors v1 (a Find the projecti.pdfpls show details.thx 1. Consider the vectors v1 (a Find the projecti.pdf
pls show details.thx 1. Consider the vectors v1 (a Find the projecti.pdfwasemanivytreenrco51
 
Please create an infographic for medical fraud! Thank you so much.pdf
Please create an infographic for medical fraud! Thank you so much.pdfPlease create an infographic for medical fraud! Thank you so much.pdf
Please create an infographic for medical fraud! Thank you so much.pdfwasemanivytreenrco51
 
Internet Programming. For event-driven architecture, how does pollin.pdf
Internet Programming. For event-driven architecture, how does pollin.pdfInternet Programming. For event-driven architecture, how does pollin.pdf
Internet Programming. For event-driven architecture, how does pollin.pdfwasemanivytreenrco51
 
PCAOB Please respond to the followingGo to the PCAOB Website..pdf
PCAOB Please respond to the followingGo to the PCAOB Website..pdfPCAOB Please respond to the followingGo to the PCAOB Website..pdf
PCAOB Please respond to the followingGo to the PCAOB Website..pdfwasemanivytreenrco51
 

More from wasemanivytreenrco51 (20)

Explain what differential cell affinity is, how this process is acco.pdf
Explain what differential cell affinity is, how this process is acco.pdfExplain what differential cell affinity is, how this process is acco.pdf
Explain what differential cell affinity is, how this process is acco.pdf
 
Explain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdfExplain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdf
 
Entamoeba histolytica is an amoeba responsible for the gastrointestin.pdf
Entamoeba histolytica is an amoeba responsible for the gastrointestin.pdfEntamoeba histolytica is an amoeba responsible for the gastrointestin.pdf
Entamoeba histolytica is an amoeba responsible for the gastrointestin.pdf
 
Describe briefly each mouth part of the grasshopper. b. Describe how.pdf
Describe briefly each mouth part of the grasshopper.  b. Describe how.pdfDescribe briefly each mouth part of the grasshopper.  b. Describe how.pdf
Describe briefly each mouth part of the grasshopper. b. Describe how.pdf
 
Contrast the views of Piaget and Bandura on how children develop..pdf
Contrast the views of Piaget and Bandura on how children develop..pdfContrast the views of Piaget and Bandura on how children develop..pdf
Contrast the views of Piaget and Bandura on how children develop..pdf
 
Compute the probability of event E if the odds in favor of E are 31.pdf
Compute the probability of event E if the odds in favor of E are  31.pdfCompute the probability of event E if the odds in favor of E are  31.pdf
Compute the probability of event E if the odds in favor of E are 31.pdf
 
Compare and contrast the world population with that of the United St.pdf
Compare and contrast the world population with that of the United St.pdfCompare and contrast the world population with that of the United St.pdf
Compare and contrast the world population with that of the United St.pdf
 
8. What protocol is are layers 6 and 7 of the OSI model based on.pdf
8. What protocol is are layers 6 and 7 of the OSI model based on.pdf8. What protocol is are layers 6 and 7 of the OSI model based on.pdf
8. What protocol is are layers 6 and 7 of the OSI model based on.pdf
 
Which statement is true of serous membranesA) They line closed cavi.pdf
Which statement is true of serous membranesA) They line closed cavi.pdfWhich statement is true of serous membranesA) They line closed cavi.pdf
Which statement is true of serous membranesA) They line closed cavi.pdf
 
Which of the following is not included in the calculation of the VIX .pdf
Which of the following is not included in the calculation of the VIX .pdfWhich of the following is not included in the calculation of the VIX .pdf
Which of the following is not included in the calculation of the VIX .pdf
 
What is an Accountable Care Organizations (ACO) How does an ACOs .pdf
What is an Accountable Care Organizations (ACO) How does an ACOs .pdfWhat is an Accountable Care Organizations (ACO) How does an ACOs .pdf
What is an Accountable Care Organizations (ACO) How does an ACOs .pdf
 
True or false A selective force (such as antibiotics) must be prese.pdf
True or false A selective force (such as antibiotics) must be prese.pdfTrue or false A selective force (such as antibiotics) must be prese.pdf
True or false A selective force (such as antibiotics) must be prese.pdf
 
The receptors in the feedback loop regulating ADH secretion are osmor.pdf
The receptors in the feedback loop regulating ADH secretion are osmor.pdfThe receptors in the feedback loop regulating ADH secretion are osmor.pdf
The receptors in the feedback loop regulating ADH secretion are osmor.pdf
 
The UV spectrum of the hot B0V star is significantly below the conti.pdf
The UV spectrum of the hot B0V star is significantly below the conti.pdfThe UV spectrum of the hot B0V star is significantly below the conti.pdf
The UV spectrum of the hot B0V star is significantly below the conti.pdf
 
Q2 For any drosophila population, what is the proportion of live ho.pdf
Q2 For any drosophila population, what is the proportion of live ho.pdfQ2 For any drosophila population, what is the proportion of live ho.pdf
Q2 For any drosophila population, what is the proportion of live ho.pdf
 
Prove asymptotic upper and lower hounds for each of the following sp.pdf
Prove asymptotic upper and lower hounds for each of the following  sp.pdfProve asymptotic upper and lower hounds for each of the following  sp.pdf
Prove asymptotic upper and lower hounds for each of the following sp.pdf
 
pls show details.thx 1. Consider the vectors v1 (a Find the projecti.pdf
pls show details.thx 1. Consider the vectors v1 (a Find the projecti.pdfpls show details.thx 1. Consider the vectors v1 (a Find the projecti.pdf
pls show details.thx 1. Consider the vectors v1 (a Find the projecti.pdf
 
Please create an infographic for medical fraud! Thank you so much.pdf
Please create an infographic for medical fraud! Thank you so much.pdfPlease create an infographic for medical fraud! Thank you so much.pdf
Please create an infographic for medical fraud! Thank you so much.pdf
 
Internet Programming. For event-driven architecture, how does pollin.pdf
Internet Programming. For event-driven architecture, how does pollin.pdfInternet Programming. For event-driven architecture, how does pollin.pdf
Internet Programming. For event-driven architecture, how does pollin.pdf
 
PCAOB Please respond to the followingGo to the PCAOB Website..pdf
PCAOB Please respond to the followingGo to the PCAOB Website..pdfPCAOB Please respond to the followingGo to the PCAOB Website..pdf
PCAOB Please respond to the followingGo to the PCAOB Website..pdf
 

Recently uploaded

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
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
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111GangaMaiya1
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17Celine George
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use CasesTechSoup
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
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
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Celine George
 
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
 

Recently uploaded (20)

Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
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
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
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
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
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_...
 

Not sure why my program wont run.Programmer S.Villegas helper N.pdf

  • 1. Not sure why my program wont run. //Programmer: S.Villegas helper Noah //File name: PP88ArrayList.java //Description: //**************************** import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; public class PP88ArrayList { public static void main(String[]args) { ArrayList persons = new ArrayList(25); String fileName = "Zips.dat"; int i; Scanner filescasnner = null; try { filescasnner=new Scanner(new File(fileName)); for(i=0;i persons) { for (int i = 0; i < persons.size(); i++) { for (int j = 0; j < persons.size()-1; j++) { if((persons.get(j).getFirstName().compareTo(persons.get(j+1).getFirstName()))>0) { Person temp= persons.get(j); persons.set(j, persons.get(j+1)); persons.set(j+1, temp); } } } }
  • 2. public static void sortByZipCode(ArrayList persons) { for (int i = 0; i < persons.size(); i++) { for (int j = 0; j < persons.size()-1; j++) { if(persons.get(j).getZipCode()>persons.get(j+1).getZipCode()) { Person temp= persons.get(j); persons.set(j, persons.get(j+1)); persons.set(j+1, temp); } } } } } //Programmer: S.Villegas helper Noah //File name: PersonList.java //Description: //****************************** public class PersonList { private String firstName, lastName; private int Zip; public PersonList(String firstName,String lastName, int Zip) { this.firstName = firstName; this.lastName = lastName; this.Zip = Zip; } public String getFirstName() { return firstName; }
  • 3. public int getZipCode() { return Zip; } public String toString() { return String.format("%-15s%-15s%-10d",firstName,lastName,Zip); } } Solution //File name: PersonList.java public class PersonList { private String firstName, lastName; private int Zip; public PersonList(String firstName,String lastName, int Zip) { this.firstName = firstName; this.lastName = lastName; this.Zip = Zip; } public String getFirstName() { return firstName; } public int getZipCode() { return Zip; } public String toString() { return String.format("%-15s%-15s%-10d",firstName,lastName,Zip);
  • 4. } } //File name: PP88ArrayList.java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; public class PP88ArrayList { public static void main(String[]args) { ArrayList persons = new ArrayList(25); String fileName = "Zips.dat"; int i; Scanner filescasnner = null; try { filescasnner=new Scanner(new File(fileName)); while(filescasnner.hasNextLine()) { String firstName = filescasnner.next(); String lastName = filescasnner.next(); int Zip = filescasnner.nextInt(); persons.add(new PersonList(firstName, lastName, Zip)); } filescasnner.close();
  • 5. } catch (FileNotFoundException e) { System.out.println(e.getMessage()); } System.out.println(" List of names and zip codes: "); System.out.printf("%-15s%-15s%-15s ","First Name","Last Name","Zip"); for (int j = 0; j < persons.size(); j++) { System.out.println(persons.get(j)); } System.out.println(" List of names sort by first name"); sortByName(persons); System.out.printf("%-15s%-15s%-15s ","First Name","Last Name","Zip"); for (int j = 0; j < persons.size(); j++) { System.out.println(persons.get(j)); } System.out.println(" List of names sort by zip code"); sortByZipCode(persons); System.out.printf("%-15s%-15s%-15s ","First Name","Last Name","Zip"); for (int j = 0; j < persons.size(); j++) { System.out.println(persons.get(j)); } }
  • 6. public static void sortByName(ArrayList persons) { for (int i = 0; i < persons.size(); i++) { for (int j = 0; j < persons.size()-1; j++) { if((persons.get(j).getFirstName().compareTo(persons.get(j+1).getFirstName()))>0) { PersonList temp= persons.get(j); persons.set(j, persons.get(j+1)); persons.set(j+1, temp); } } } } public static void sortByZipCode(ArrayList persons) { for (int i = 0; i < persons.size(); i++) { for (int j = 0; j < persons.size()-1; j++) { if(persons.get(j).getZipCode()>persons.get(j+1).getZipCode()) { PersonList temp= persons.get(j); persons.set(j, persons.get(j+1)); persons.set(j+1, temp); } } } } } /* Zips.dat kyle mills 1453
  • 7. alex hales 2321 eoin morgan 3453 shakid hasan 4756 tim southee 5534 output: List of names and zip codes: First Name Last Name Zip kyle mills 1453 alex hales 2321 eoin morgan 3453 shakid hasan 4756 tim southee 5534 List of names sort by first name First Name Last Name Zip alex hales 2321 eoin morgan 3453 kyle mills 1453 shakid hasan 4756 tim southee 5534 List of names sort by zip code First Name Last Name Zip kyle mills 1453 alex hales 2321 eoin morgan 3453 shakid hasan 4756 tim southee 5534 */