SlideShare a Scribd company logo
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.pdf
alliedscorporation
 
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
stopgolook
 
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
amrishinda
 
JAVA.pdf
JAVA.pdfJAVA.pdf
JAVA.pdf
jyotir7777
 
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
NicholasflqStewartl
 
Java practical
Java practicalJava practical
Java practical
william otto
 
Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdf
ICADCMLTPC
 
Java 104
Java 104Java 104
Java 104
Manuela Grindei
 
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
anupamfootwear
 
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
Stewart29UReesa
 
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
manojmozy
 
Lab4
Lab4Lab4
Java file
Java fileJava file
Java file
simarsimmygrewal
 
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
Joni
 
Exceptions and errors in Java
Exceptions and errors in JavaExceptions and errors in Java
Exceptions and errors in Java
Manuela 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 fruit
Vaclav 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.pdf
fantasiatheoutofthef
 

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.pdf
wasemanivytreenrco51
 
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
wasemanivytreenrco51
 
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
wasemanivytreenrco51
 
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
wasemanivytreenrco51
 
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
wasemanivytreenrco51
 
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
wasemanivytreenrco51
 
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
wasemanivytreenrco51
 
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
wasemanivytreenrco51
 
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
wasemanivytreenrco51
 
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
wasemanivytreenrco51
 
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
wasemanivytreenrco51
 
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
wasemanivytreenrco51
 
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
wasemanivytreenrco51
 
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
wasemanivytreenrco51
 
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
wasemanivytreenrco51
 
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
wasemanivytreenrco51
 
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
wasemanivytreenrco51
 
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
wasemanivytreenrco51
 
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
wasemanivytreenrco51
 
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
wasemanivytreenrco51
 

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

Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 

Recently uploaded (20)

Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 

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 */