Question

In: Computer Science

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

Solutions

Expert Solution

import java.util.*;
class data
{
String name1,name2,street,city,state;
int zip;
long phone;
data()
{
Scanner sc = new Scanner(System.in);//to read input
System.out.print("Enter two names:");
name1=sc.nextLine();
name2=sc.nextLine();
System.out.print("Enter zip code:");
zip = sc.nextInt();
System.out.print("Enter street name:");
street = sc.nextLine();
street = sc.nextLine();
System.out.print("Enter city name:");
city =sc.nextLine();
System.out.print("Enter state name:");
state = sc.nextLine();
System.out.print("Enter phone number:");
phone = sc.nextLong();
}
void print()
{
System.out.println("Name1 :"+name1+"\nName2 :"+name2+"\nZip :"+zip+"\nstreet :"+street+"\ncity :"+city+"\nstate :"+state+"\nphone :"+phone);
}
}
public class Main
{
   public static void main(String[] args) {
       System.out.println("Enter number of values you want to store:");
       int n;
       Scanner sc = new Scanner(System.in);//to readinput
       n=sc.nextInt();
      
       ArrayList<data> a = new ArrayList<data>();//storing values in ArrayList
      
       int i=0;
       while(i<n)
       {
      
       data d = new data();
       a.add(d);//adding to arraylist
      
       i++;
       }
       System.out.println("----Displaying List---------");
       i=0;
       while(i<n)
       {
       a.get(i).print();
      
       i++;
       }
       //displaying data
      
   }
}

output:

Enter number of values you want to store:                                                                                               

2                                                                                                                                       

Enter two names:surya                                                                                                                   

saikam                                                                                                                                  

Enter zip code:120003                                                                                                                   

Enter street name:rice mill                                                                                                             

Enter city name:turbun                                                                                                                  

Enter state name:njy                                                                                                                    

Enter phone number:1234567890                                                                                                           

Enter two names:phani                                                                                                                   

k                                                                                                                                       

Enter zip code:12003                                                                                                                    

Enter street name:R j                                                                                                                   

Enter city name:basti                                                                                                                   

Enter state name:Ap                                                                                                                     

Enter phone number:9876543211                                                                                                           

----Displaying List---------                                                                                                            

Name1 :surya                                                                                                                            

Name2 :saikam                                                                                                                           

Zip :120003                                                                                                                             

street :rice mill                                                                                                                       

city :turbun                                                                                                                            

state :njy                                                                                                                              

phone :1234567890                                                                                                                       

Name1 :phani                                                                                                                            

Name2 :k                                                                                                                                

Zip :12003                                                                                                                              

street :R j                                                                                                                             

city :basti                                                                                                                             

state :Ap                                                                                                                               

phone :9876543211                                                                                                                       

                      


Related Solutions

Written in JAVA Coding Write a java project that reads a sequence of up to 25...
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...
Please write in java: Write a fragment that reads a sequence of strings and inserts each...
Please write in java: Write a fragment that reads a sequence of strings and inserts each string that is not numeric at the front of a deque and each string that is numeric at the rear of a deque. Your fragment should also count the number of strings of each kind. Display the message "Strings that are not numeric" followed by the nonnumeric strings and then the message "Strings that are numbers" followed by the numeric strings. Do not empty...
Java: create a program that reads in a piece of DNA sequence from a sequence file...
Java: create a program that reads in a piece of DNA sequence from a sequence file (dna.seq) (alternatively you can use the getRandomSeq(long) method of the RandomSeq class to generate a piece of DNA sequence), and then print out all the codons in three forward reading frames. Design a method called codon() that can be used to find all the codons from three reading frames. The method will take in an argument, the reading frame (1, 2, or 3), and...
In Java A palindrome is a word or sequence of characters which reads the same backward...
In Java A palindrome is a word or sequence of characters which reads the same backward and forward, such as madam, dad, racecar, 5885. In java Write a program that asks user to enter a word and prints if the word is a palindrome or not.
Using Java Project 2: Deduplication Write a program that reads a file of numbers of type...
Using Java Project 2: Deduplication Write a program that reads a file of numbers of type int and outputs all of those numbers to another file, but without any duplicate numbers. You should assume that the input file is sorted from smallest to largest with one number on each line. After the program is run, the output file should contain all numbers that are in the original file, but no number should appear more than once. The numbers in the...
C++ Write a program that reads in a list of 10 names as input from a...
C++ Write a program that reads in a list of 10 names as input from a user and places them in an array. The program will prompt for a name and return the number of times that name was entered in the list. The program should output total number of instances of that name and then prompt for another name until the word done is typed in. For this lab, use the string data type as opposed to char to...
in JAVA, Project: Displaying Words in Ascending Alphabetical Order Write a program that reads words from...
in JAVA, Project: Displaying Words in Ascending Alphabetical Order Write a program that reads words from a text file and displays all the words (duplicates allowed) in ascending alphabetical order. The words must start with a letter. 1. You must use one of following Concrete class to store date from the input.txt file. Vector, Stack, ArrayList, LinkedList 2. To sort those words, you should use one of existing interface methods available in Collection class.
you are to write a program in Java, that reads in a set of descriptions of...
you are to write a program in Java, that reads in a set of descriptions of various geometric shapes, calculates the areas and circumferences of the shapes, and then prints out the list of shapes and their areas in sorted order from smallest to largest area. There are four possible shapes: Circle, Square, Rectangle, and Triangle. The last is always an equilateral triangle. The program should read from standard input and write to standard output. The program should read until...
Write a Java program that reads a name and displays on the screen.
Write a Java program that reads a name and displays on the screen.
C++ Write a program that reads candidate names and numbers of votes in from a file....
C++ Write a program that reads candidate names and numbers of votes in from a file. You may assume that each candidate has a single word first name and a single word last name (although you do not have to make this assumption). Your program should read the candidates and the number of votes received into one or more dynamically allocated arrays. In order to allocate the arrays you will need to know the number of records in the file....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT