PP 7.8 Design and implement an application that reads a sequence of up to 25 pai
ID: 3621797 • Letter: P
Question
PP 7.8 Design and implement an application that reads a sequence of up to 25 pairs of names and postal zip codes for individuals. Store the data in an object designed to store a first name (string), last name (string), and postal code (integer). Assume each line of input will contain two strings followed by an integer value, each separated by a tab character. Then, after the input has been read in, print the list in an appropriate format to the screen.PP 7.9 Modify the program you created in PP 7.8 to accomplish the following:
Support the storing of additional user information: street address(string), city(string), state(string), and 10 digit phone number(long integer, contains area code and does not include special characters such as (,) or (-).
Store data in an ArrayList object.
Please help, I tried and tried but I always end up back at line one. Thanks.
Explanation / Answer
Hope this helps. Let me know if you have any questions. Please rate. :) This accomplishes the first part. I could do the second, but I'm not sure the exact requirements. Will all records contain the extra data? Or will some contain that data and some won't? It would be easier if all contained exactly that data, but it is still possible (with the use of some StringTokenizers) to do the other option. Let me know, if you'd like I could do that and PM you the modified code. Either way, this will work for the first part. import java.util.Scanner; public class PostalCodes { public static void main(String[] args) { String input; int i = 0; // Array to hold up to 25 people information Person[] people = new Person[25]; Scanner s = new Scanner(System.in); // Some termination of input needs to be given // I will assume that the input will end with a -1, but this can change if you'd like it to. System.out.println("Please enter first name, last name, and zip code, or -1 to end: "); input = s.next(); while (!input.equalsIgnoreCase("-1")) { people[i] = new Person(); people[i].fname = input; people[i].lname = s.next(); people[i].zip = s.nextInt(); i++; if (i >= 25) break; // exit loop if we're past 25 people - they won't fit in our array System.out.println("Please enter first name, last name, and zip code, or -1 to end: "); input = s.next(); } // Now print all the data - i items for (int j = 0; jRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.