Java Reference
In-Depth Information
30
case DEBIT_BALANCE :
31
System.out.printf( "%nAccounts with debit balances:%n" );
32
break ;
33
}
34
35
readRecords(accountType);
36
accountType = getRequest(); // get user's request
37
}
38
}
39
40
// obtain request from user
41
private static MenuOption getRequest()
42
{
43
int request = 4 ;
44
45
// display request options
46
System.out.printf( "%nEnter request%n%s%n%s%n%s%n%s%n" ,
47
" 1 - List accounts with zero balances" ,
48
" 2 - List accounts with credit balances" ,
49
" 3 - List accounts with debit balances" ,
50
" 4 - Terminate program" );
51
52
try
53
{
54
Scanner input = new Scanner(System.in);
55
56
do // input user request
57
{
58
System.out.printf( "%n? " );
59
request = input.nextInt();
60
} while ((request < 1 ) || (request > 4 ));
61
}
62
catch (NoSuchElementException noSuchElementException)
63
{
64
System.err.println( "Invalid input. Terminating." );
65
}
66
67
return choices[request - 1 ]; // return enum value for option
68
}
69
70
// read records from file and display only records of appropriate type
71
private static void readRecords(MenuOption accountType)
72
{
73
// open file and process contents
74
try (Scanner input = new Scanner(Paths.get( "clients.txt" )))
75
{
76
while (input.hasNext()) // more data to read
77
{
78
int accountNumber = input.nextInt();
79
String firstName = input.next();
80
String lastName = input.next();
81
double balance = input.nextDouble();
82
Fig. 15.8 | Credit-inquiry program. (Part 2 of 4.)
Search WWH ::




Custom Search