Ask 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 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.

+5
Answers (1)
  1. 3 June, 12:27
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers