Ask Question
31 July, 16:23

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.

+1
Answers (1)
  1. 31 July, 18:46
    0
    Kindly go to the explanation for the answer.

    Explanation:

    Person. java

    public class Person{

    private String firstName, lastName;

    private int zip;

    public Person (String firstName, String lastName, int zip) {

    super ();

    this. firstName = firstName;

    this. lastName = lastName;

    this. zip = zip;

    }

    public String toString () {

    String line = "/tFirst Name = " + this. firstName + "/n/tLast Name = " + this. lastName;

    line + = "/n/tZip Code = " + this. zip + "/n";

    return line;

    }

    }

    Test. java

    import java. util. ArrayList;

    import java. util. Scanner;

    public class Test{

    public static void main (String args[]) {

    Scanner in = new Scanner (System. in);

    ArrayList al = new ArrayList ();

    for (int i = 0; i < 25; i++) {

    System. out. print ("Enter person details: ");

    String line = in. nextLine ();

    String words[] = line. split ("/t");

    String fname = words[0];

    String lname = words[1];

    int numb = Integer. parseInt (words[2]);

    Person p = new Person (fname, lname, numb);

    al. add (p);

    }

    for (int i = 0; i < 25; i++) {

    System. out. println ("Person " + (i + 1) + ":");

    System. out. println (al. get (i));

    }

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “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 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers