SHOW:
|
|
- or go back to the newest paste.
| 1 | import java.util.*; | |
| 2 | public class Directory | |
| 3 | {
| |
| 4 | static class personName | |
| 5 | {
| |
| 6 | ||
| 7 | private String first; | |
| 8 | private String second; // first and second names | |
| 9 | private int number; // phone number | |
| 10 | ||
| 11 | void getInfo() | |
| 12 | {
| |
| 13 | first = Console.readToken(); | |
| 14 | second = Console.readToken(); //reads name from primary input | |
| 15 | number = Console.readInt(); | |
| 16 | } | |
| 17 | ||
| 18 | ||
| 19 | void putName() | |
| 20 | {
| |
| 21 | String name = second + ", " + first; | |
| 22 | int phoneNumber = number; //place name in required format | |
| 23 | System.out.printf("%-25s%-15d", name, phoneNumber);
| |
| 24 | System.out.println(); | |
| 25 | } | |
| 26 | } | |
| 27 | ||
| 28 | public static void main(String[] args) | |
| 29 | {
| |
| 30 | ||
| 31 | System.out.println("Enter names:");
| |
| 32 | ||
| 33 | personName name = new personName(); | |
| 34 | personName[]names = new personName[50]; | |
| 35 | ||
| 36 | int x = 0; | |
| 37 | ||
| 38 | while(!Console.endOfFile()) | |
| 39 | {
| |
| 40 | name = new personName(); | |
| 41 | name.getInfo(); | |
| 42 | names[x] = name; | |
| 43 | x++; | |
| 44 | } | |
| 45 | ||
| 46 | for(int i=0; i < names.length; i++) | |
| 47 | {
| |
| 48 | if(names[i]!=null) | |
| 49 | {
| |
| 50 | names[i].putName(); | |
| 51 | } | |
| 52 | } | |
| 53 | } | |
| 54 | } |