//George Koutsogiannakis //Fall 2009 import javax.swing.JOptionPane; import java.util.Scanner; import java.io.File; import java.io.IOException; import java.util.StringTokenizer; public class PeopleClientTextFile { public static void main(String[] args) { /* Scanner scan=new Scanner(System.in); System.out.println("Please enter the first name:"); String fn1=scan.next(); System.out.println("Please enter the last name:"); String ln1=scan.next(); System.out.println("Please enter the social security number:"); int ssn1=scan.nextInt(); System.out.println("Please enter the height"); double hei1=scan.nextDouble(); People person1=new People(fn1,ln1,ssn1,hei1); String fn2=args[0]; String ln2=args[1]; String ssn2str=args[2]; int ssn2=Integer.parseInt(ssn2str); String hei2str=args[3]; double hei2=Double.parseDouble(hei2str); //System.out.println("fn="+fn2+"ln="+ln2+"ssn="+ssn2+"hei="+hei2); People person2=new People(fn2, ln2, ssn2, hei2); String fn3=JOptionPane.showInputDialog(null, "Input from User", "Enter the first name", JOptionPane.INFORMATION_MESSAGE); String ln3=JOptionPane.showInputDialog(null, "Information", "Enter the last name", JOptionPane.INFORMATION_MESSAGE); String ssn3str=JOptionPane.showInputDialog(null, "Information", "Enter the social sec. num", JOptionPane.INFORMATION_MESSAGE); int ssn3=Integer.parseInt(ssn3str); String hei3str=JOptionPane.showInputDialog(null, "Information", "Enter the height", JOptionPane.INFORMATION_MESSAGE); double hei3=Double.parseDouble(hei3str); People person3=new People(fn3, ln3, ssn3, hei3); People person4=new People(); int id3=person3.getID(); int pid3=person3.getPersonID(); JOptionPane.showMessageDialog(null, "person3 id="+" "+id3+", "+"person3 personID="+" "+pid3); System.out.println(person1.toString()); System.out.println(person2.toString()); System.out.println(person3.toString()); System.out.println(person4.toString()); person1.setID(10); System.out.println(person1.toString()); System.out.println(person2.toString()); System.out.println(person3.toString()); System.out.println(person4.toString()); */ //NEW CODE TO READ DATA FROM TEXT FILE data.txt //We are going tosave the objects from the text file into an array //We need to determine the size of teh array. Therfore there are going to be two while loops People[] peoar=null; try { File f=new File("data.txt"); Scanner scan1=new Scanner(f); int count=0; while(scan1.hasNextLine()) { scan1.nextLine(); count++; } peoar=new People[count]; Scanner scan2=new Scanner(f); int index=0; while(scan2.hasNextLine()) { String line=scan2.nextLine(); StringTokenizer stt=new StringTokenizer(line); String fn=stt.nextToken(); String ln=stt.nextToken(); String ssns=stt.nextToken(); int ssn=Integer.parseInt(ssns); String hts=stt.nextToken(); double ht=Double.parseDouble(hts); People p=new People(fn,ln,ssn,ht); peoar[index]=p; index++; } } catch (IOException ioe) { System.out.println(ioe.getMessage()); } for (int j=0; j