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