Question

Write a java project that reads a sequence of up to 25 pairs of names and...

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. It should also 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 '-'. Need to Store the data in an ArrayList object. DATA SHOULD BE READ FROM INPUT FILE

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/***************************ReadPerson.java**************************/

/**
* The Class ReadPerson.
*/
public class ReadPerson {

   /** The first name. */
   private String firstName;
  
   /** The last name. */
   private String lastName;
  
   /** The zipcode. */
   private int zipcode;
  
   /** The street address. */
   private String streetAddress;
  
   /** The city. */
   private String city;
  
   /** The state. */
   private String state;
  
   /** The phone number. */
   private long phoneNumber;

   /**
   * Instantiates a new read person.
   *
   * @param firstName the first name
   * @param lastName the last name
   * @param zipcode the zipcode
   */
   public ReadPerson(String firstName, String lastName, int zipcode) {
       super();
       this.firstName = firstName;
       this.lastName = lastName;
       this.zipcode = zipcode;
   }

   /**
   * Gets the first name.
   *
   * @return the first name
   */
   public String getFirstName() {
       return firstName;
   }

   /**
   * Sets the first name.
   *
   * @param firstName the new first name
   */
   public void setFirstName(String firstName) {
       this.firstName = firstName;
   }

   /**
   * Gets the last name.
   *
   * @return the last name
   */
   public String getLastName() {
       return lastName;
   }

   /**
   * Sets the last name.
   *
   * @param lastName the new last name
   */
   public void setLastName(String lastName) {
       this.lastName = lastName;
   }

   /**
   * Gets the zipcode.
   *
   * @return the zipcode
   */
   public int getZipcode() {
       return zipcode;
   }

   /**
   * Sets the zipcode.
   *
   * @param zipcode the new zipcode
   */
   public void setZipcode(int zipcode) {
       this.zipcode = zipcode;
   }

   /**
   * Gets the street address.
   *
   * @return the street address
   */
   public String getStreetAddress() {
       return streetAddress;
   }

   /**
   * Sets the street address.
   *
   * @param streetAddress the new street address
   */
   public void setStreetAddress(String streetAddress) {
       this.streetAddress = streetAddress;
   }

   /**
   * Gets the city.
   *
   * @return the city
   */
   public String getCity() {
       return city;
   }

   /**
   * Sets the city.
   *
   * @param city the new city
   */
   public void setCity(String city) {
       this.city = city;
   }

   /**
   * Gets the state.
   *
   * @return the state
   */
   public String getState() {
       return state;
   }

   /**
   * Sets the state.
   *
   * @param state the new state
   */
   public void setState(String state) {
       this.state = state;
   }

   /**
   * Gets the phone number.
   *
   * @return the phone number
   */
   public long getPhoneNumber() {
       return phoneNumber;
   }

   /**
   * Sets the phone number.
   *
   * @param phoneNumber the new phone number
   */
   public void setPhoneNumber(long phoneNumber) {
       this.phoneNumber = phoneNumber;
   }

   /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "First Name: " + firstName + "\nLast Name: " + lastName + "\nZipcode :" + zipcode;
   }

   /**
   * Addition info.
   *
   * @return the string
   */
   public String additionInfo() {

       return "Street Address: " + streetAddress + "\nCity: " + city + "\nState: " + state + "\nPhone Number: "
               + phoneNumber + "\n";

   }
}
/********************************ReadPersonTest.java**************************/

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;


/**
* The Class ReadPersonTest.
*/
public class ReadPersonTest {

   /**
   * The main method.
   *
   * @param args the arguments
   */
   public static void main(String[] args) {

       ArrayList<ReadPerson> persons = new ArrayList<>();

       try {
           File file = new File("inputData.txt");
           Scanner scan = new Scanner(file);

           while (scan.hasNextLine()) {

               String line = scan.nextLine();

               String data[] = line.split("\\t");
               String firstName = data[0];
               String lastName = data[1];
               int zipCode = Integer.parseInt(data[2]);
               String streetAddress = data[3];
               String city = data[4];
               String state = data[5];
               long phoneNumber = Long.parseLong(data[6]);

               ReadPerson person = new ReadPerson(firstName, lastName, zipCode);
               person.setStreetAddress(streetAddress);
               person.setCity(city);
               person.setState(state);
               person.setPhoneNumber(phoneNumber);

               persons.add(person);

           }
           scan.close();
       } catch (FileNotFoundException e) {
           System.out.println("File not fount!");
       }
      
       for (ReadPerson readPerson : persons) {
          
           System.out.println(readPerson.toString());
           System.out.println(readPerson.additionInfo());
       }
   }
}
/************************inputData.txt*********************/

Virat   Kohli   322028   bajaj nagar   Jaipur   Rajasthan   7387389479
MS   Dhoni   322028   bajaj nagar   Jaipur   Rajasthan   7439384793
R   Jadeja   433433   New Colony   JP   RJ   8754599488

/*****************************************output***********************/

First Name: Virat
Last Name: Kohli
Zipcode :322028
Street Address: bajaj nagar
City: Jaipur
State: Rajasthan
Phone Number: 7387389479

First Name: MS
Last Name: Dhoni
Zipcode :322028
Street Address: bajaj nagar
City: Jaipur
State: Rajasthan
Phone Number: 7439384793

First Name: R
Last Name: Jadeja
Zipcode :433433
Street Address: New Colony
City: JP
State: RJ
Phone Number: 8754599488

Please let me know if you have any doubt or modify the answer, Thanks:)

Add a comment
Know the answer?
Add Answer to:
Write a java project that reads a sequence of up to 25 pairs of names and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a java project that reads a sequence of up to 25 pairs of names and...

    Write a java project that reads a sequence of up to 25 pairs of names and postal (ZIP) codes, street address, city, state, and 10-digit phone number for individuals. Store the data in an object designed to store a first name (string), last name (string), and postal code (integer), 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 '-' . Assume each...

  • Write a Java program that reads a series of strings from a user until STOP is...

    Write a Java program that reads a series of strings from a user until STOP is entered. Each input consists of information about one student at the ABC Professional School. The input consists of the student’s last name (the first 15 characters with extra blanks on the right if the name is not 15 characters long), the student’s number (the next 4 characters, all digits, a number between 1000 and 5999), and the student’s program of study (one character, either...

  • C PROGRAMMING      Write a printf or scanf statement for each of the following: a) Print...

    C PROGRAMMING      Write a printf or scanf statement for each of the following: a) Print unsigned integer 2001 right justified in a 12-digit field with 6 digits. b) Print 3.150 in a 9-digit field with preceding zeros. // part of my answer: Printf(“%09 c) Read a time of the form hh-mm-ss, storing the parts of the time in the integer variables hour, minute and second. Skip the dash (-) in the input stream. Use the assignment suppression character. d)...

  • In Java. Write a GUI contact list application. The program should allow you to input names...

    In Java. Write a GUI contact list application. The program should allow you to input names and phone numbers. You should also be able to input a name and have it display the previously entered phone number. The GUI should look something like the following, although you are welcome to format it in any way that works. This should be a GUI application with a JFrame. The program should contain two arrays of Strings. One array will contain a list...

  • this is in C programming language 1. Write a printf or scanf statement for each of...

    this is in C programming language 1. Write a printf or scanf statement for each of the following: a) Print unsigned integer 1001 right justified in a 10-digit field with 5 digits. b) Read a hexadecimal value into variable hex. c) Print 300 with and without a sign. .d) Print 200 in hexadecimal form preceded by Ox. e) Read characters into array m until the letter z is encountered. f) Print 7.350 in a 7-digit field with preceding zeros. B)...

  • Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class...

    Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class) Data fields: A String object named firstName A String object named middleName A String object name lastName Methods: A Module2 constructor method that accepts no parameters and initializes the data fields from 1) to empty Strings (e.g., firstName =...

  • please Answer the following regular expressions questions(also do number 9) Q4 Choose the pattern that finds...

    please Answer the following regular expressions questions(also do number 9) Q4 Choose the pattern that finds all filenames in which the first letters of the filename are astA, followed by a digit, followed by the file extension .txt. 1) astA[[:digit:]]\.txt 2) astA[[0-9]].txt 3) astA.\.txt 4) astA[[:digit:]].txt Q5 What's the difference between [0-z]+ and \w+ ? 1) The first one accepts 0 and z and the other doesn't. 2) The first one doesn't allow for uppercase letters. 3) The first one...

  • IN JAVA 3 ZIPS, What Order?: Write a program named ZipOrder that the reads in three...

    IN JAVA 3 ZIPS, What Order?: Write a program named ZipOrder that the reads in three zip codes from standard input and prints to standard output one of three words: "ASCENDING", "DESCENDING", "UNSORTED". The zip codes are guaranteed to be distinct from each other. In particular: if each zip code read in is greater than to the previous one, "ASCENDING"  is printed. if each zip code read in is less than to the previous one, "DESCENDING" is printed. otherwise, "UNSORTED" is...

  • Write C++ program T 1030 UUIII DUCOUL The bar code on an envelope used by the...

    Write C++ program T 1030 UUIII DUCOUL The bar code on an envelope used by the US Postal Service represents a five (or more) digit zip code using a format called POSTNET (this format is being deprecated in favor of a new system, OneCode, in 2009). The bar code consists of long and short bars as shown below: Illlllllllll For this program we will represent the bar code as a string of digits. The digit 1 represents a long bar...

  • This is for C++ Write a program that reads in a sequence of characters entered by...

    This is for C++ Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along with the number of times it occured. All non-alphabetic characters must...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT