Java Reference
In-Depth Information
83
// if proper acount type, display record
84
if (shouldDisplay(accountType, balance))
85
System.out.printf( "%-10d%-12s%-12s%10.2f%n" , accountNumber,
86
firstName, lastName, balance);
87
else
88
input.nextLine(); // discard the rest of the current record
89
}
90
}
91
catch (NoSuchElementException |
92
IllegalStateException | IOException e)
93
{
94
System.err.println( "Error processing file. Terminating." );
95
System.exit( 1 );
96
}
97
} // end method readRecords
98
99 // use record type to determine if record should be displayed
100 private static boolean shouldDisplay(
101 MenuOption accountType, double balance)
102 {
103 if ((accountType == MenuOption.CREDIT_BALANCE ) && (balance < 0 ))
104 return true ;
105 else if ((accountType == MenuOption.DEBIT_BALANCE ) && (balance > 0 ))
106 return true ;
107 else if ((accountType == MenuOption.ZERO_BALANCE ) && (balance == 0 ))
108 return true ;
109
110 return false ;
111 }
112 } // end class CreditInquiry
Enter request
1 - List accounts with zero balances
2 - List accounts with credit balances
3 - List accounts with debit balances
4 - Terminate program
? 1
Accounts with zero balances:
300 Pam White 0.00
Enter request
1 - List accounts with zero balances
2 - List accounts with credit balances
3 - List accounts with debit balances
4 - Terminate program
? 2
Accounts with credit balances:
200 Steve Green -345.67
400 Sam Red -42.16
Fig. 15.8 | Credit-inquiry program. (Part 3 of 4.)
Search WWH ::




Custom Search