Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.io.IOException;
- public class Directory
- {
- static class personName
- {
- private String first;
- private String second; // first and second names
- private int number; // phone number
- personName(String reqFirst, String reqSecond, int reqThird)
- {
- first = reqFirst;
- second = reqSecond; //reads name from primary input
- number = reqThird;
- }
- void putName()
- {
- String name = second + ", " + first;
- int phoneNumber = number; //place name in required format
- System.out.printf("%-25s%-15d", name, phoneNumber);
- System.out.println();
- }
- }
- public static void main(String[] args) throws IOException
- {
- System.out.println("Enter names:");
- personName[]names = new personName[50];
- BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
- int x = 0;
- String currentLine;
- while((currentLine = input.readLine()) != null)
- {
- String[] fields = currentLine.split(" ");
- names[x] = new personName(fields[0], fields[1], Integer.parseInt(fields[2]));
- x++;
- }
- for(int i=0; i < names.length; i++)
- {
- if(names[i]!=null)
- {
- names[i].putName();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment