In: Computer Science
Written in JAVA Coding
Write a java project that reads a sequence of up to 25 pairs of names and postal (ZIP) codes for individuals (sample input data is attached). 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.
CODE IN JAVA:
Address.java file:
import java.util.ArrayList;
import java.util.Scanner;
public class Address {
String fname;
String lname;
int zipcode;
Address(String fname,String lname,int zipcode){
this.fname = fname;
this.lname = lname;
this.zipcode = zipcode;
}
public String toString() {
return this.fname+" "+this.lname+"
"+this.zipcode;
}
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
int n;
System.out.print("Enter an
integer(upto 25):");
n = sc.nextInt();
String fname,lname;
int zipcode;
ArrayList<Address> addr = new
ArrayList<Address>();
sc.nextLine();
for(int i=1;i<=n;i++) {
System.out.print("Enter first name:");
fname =
sc.nextLine();
System.out.print("Enter last name:");
lname =
sc.nextLine();
System.out.print("Enter zip code:");
zipcode =
sc.nextInt();
sc.nextLine();
Address ad = new
Address(fname,lname,zipcode);
addr.add(ad);
}
System.out.println("\nFname Lname
Zipcode");
System.out.println();
for(Address a:addr) {
System.out.println(a);
}
}
}
OUTPUT: