forked from stiers/COPRO2_SampleJavaPrograms
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GuestList.java
96 lines (63 loc) · 2.33 KB
/
GuestList.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* @author Ephramar Telog, CK
*/
import java.io.*;
public class GuestList extends Guest {
public static void main( String args[] ) throws IOException {
BufferedReader console = new BufferedReader( new InputStreamReader( System.in ) );
Guest p = new Guest(); // initializes the object
int guestAge = 0;
String guestName, guestAddress, choice;
String guestList[] = new String[50];
int i = 0; // counter
System.out.println( "Guest List\n" );
// added for precision
while( true ) {
System.out.print( "Gender Type: " );
choice = console.readLine();
if( choice.equalsIgnoreCase( "m" ) ) {
System.out.print( "Enter Name: " );
guestName = console.readLine();
System.out.print( "Enter Age: " );
try { guestAge = Integer.parseInt( console.readLine() ); }
catch( NumberFormatException e ) {
System.out.println( "Not a number!\n" );
continue;
}
System.out.print( "Enter Address: " );
guestAddress = console.readLine();
guestList[i] = "Mr. " + p.name( guestName ) + p.age( guestAge ) + " years old of " + p.address( guestAddress );
System.out.println();
}
else if( choice.equalsIgnoreCase( "f" ) ) {
System.out.print( "Enter Name: " );
guestName = console.readLine();
System.out.print( "Enter Age: " );
try { guestAge = Integer.parseInt( console.readLine() ); }
catch( NumberFormatException e ) {
System.out.println( "Not a number!" );
continue;
}
System.out.print( "Enter Address: " );
guestAddress = console.readLine();
guestList[i] = "Ms. " + p.name( guestName ) + p.age( guestAge ) + " years old of " + p.address( guestAddress );
System.out.println();
}
else if( choice.equalsIgnoreCase( "DONE" ) ) {
System.out.print( "\n" ); // added for precision
System.out.println( "List of Guest(s)\n" );
for( int j = 0; j < i; j ++ ) {
System.out.println( guestList[j] );
}
System.out.print( "\n" ); // added for precision
break; // breaks the loop and terminates the program
}
else {
System.out.println( "\nM for Male, F for Female" );
System.out.println( "DONE to terminate the program\n" );
//i --; // force to decrement the counter by 1 to ensure precision
}
++i; // force the counter to increment by 1 to increase array size
} // end while
} // end main
} // end class