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

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...
I am coding with NetBeans LDE Java. Write a program that reads a positive integer n...
I am coding with NetBeans LDE Java. Write a program that reads a positive integer n , prints all sums from 1 to any integer m 1≤m≤n . For example, if n=100, the output of your program should be The sum of positive integers from 1 to 1 is 1;       The sum of positive integers from 1 to 2 is 3;       The sum of positive integers from 1 to 3 is 6;       The sum of positive integers...
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...
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.
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.
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT