Question

In: Computer Science

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 list in an appropriate format to the screen.

Solutions

Expert Solution

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:


Related Solutions

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...
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...
Written in JAVA Code Write a program that inserts 25 random integers from 0 to 100...
Written in JAVA Code Write a program that inserts 25 random integers from 0 to 100 in order into a LinkedList object. The program should sort the elements, then calculate the sum of the elements and the floating-point average of the elements.
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.
Input the available amount of Rice in kg. Write a program that reads a sequence of...
Input the available amount of Rice in kg. Write a program that reads a sequence of Rice donations in kg and add them to the initially available amount of Rice. The loop should stop once the accumulated amount of Rice exceed 50 kg. Then, the program should print the final amount of Rice and the number of considered donations.
Java Input, Output and for-loop function. Practice01) Write-an average SCORE application called TestScores01 This project reads...
Java Input, Output and for-loop function. Practice01) Write-an average SCORE application called TestScores01 This project reads in a list of integers as SCOREs, one per line, until a sentinel value of -1. After user type in -1, the application should print out how many SCOREs are typed in, what is the max SCORE, the 2nd max SCORE, and the min SCORE, the average SCORE after removing the max and min SCORE. When SCORE >= 90, the school will give this...
Using c++, write a program that reads a sequence of characters from the keyboard (one at...
Using c++, write a program that reads a sequence of characters from the keyboard (one at a time) and creates a string including the distinct characters entered and displays the string on the screen. The input terminates once the user enters a white-space character or the user has entered 50 distinct characters. Do not use C-Strings. 2. Use the following function to append character “ch” to the string “s”: s.push_back(ch); 3. Read the input characters one by one, i.e. do...
The following DNA coding sequence is at the beginning of a coding region of the wildtype...
The following DNA coding sequence is at the beginning of a coding region of the wildtype MCB gene (wildtype allele) DNA   5’ C A T G A A A T G G* G A G C C T G A A G G A 3’ (mutant allele) DNA     5’ C A T G A A A T G A* G A G C C T G A A G G A 3’ There has been a base change mutation at...
Write Java program Lab52.java which reads in a line of text from the user. The text...
Write Java program Lab52.java which reads in a line of text from the user. The text should be passed into the method: public static String[] divideText(String input) The "divideText" method returns an array of 2 Strings, one with the even number characters in the original string and one with the odd number characters from the original string. The program should then print out the returned strings.
Write a Java program that reads a list of integers into an array. The program should...
Write a Java program that reads a list of integers into an array. The program should read this array from the file “input.txt”. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is a two-column list. The first column is the list of the distinct array elements; the second column is the number of occurrences of each element. The list should be sorted on entries in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT