public class CreditInquiry
{
private MenuOption accountType;
private Scanner input;
private MenuOption choices[] = { MenuOption.ZERO_BALANCE,
MenuOption.CREDIT_BALANCE, MenuOption.DEBIT_BALANCE,
MenuOption.END };
private void readRecords()
{
AccountRecord record = new AccountRecord();
try
{
input = new Scanner( new File( "client.txt" ) );
while ( input.hasNext() )
{
record.setAccount( input.nextInt() );
record.setFirstName( input.next() );
record.setLastName( input.next() );
record.setBalance( input.nextDouble() );
if ( shouldDisplay( record.getBalance() ) )
System.out.printf( "%-10d%-12s%-12s%10.2f\n",
record.getAccount(), record.getFirstName(),
record.getLastName(), record.getBalance() );
}
}
catch ( NoSuchElementException elementException )
{
System.err.println( "File improperly formed." );
input.close();
System.exit( 1 );
}
catch ( IllegalStateException stateException )
{
System.err.println( "Error reading from file." );
System.exit( 1 );
}
catch ( FileNotFoundException fileNotFoundException )
{
System.err.println( "File cannot be found." );
System.exit( 1 );
}
finally
{
if ( input != null )
input.close();
}
}
private boolean shouldDisplay( double balance )
{
if ( ( accountType == MenuOption.CREDIT_BALANCE )
&& ( balance < 0 ) )
return true;
else if ( ( accountType == MenuOption.DEBIT_BALANCE )
&& ( balance > 0 ) )
return true;
else if ( ( accountType == MenuOption.ZERO_BALANCE )
&& ( balance == 0 ) )
return true;
return false;
}
private MenuOption getRequest()
{
Scanner textIn = new Scanner( System.in );
int request = 1;
System.out.printf( "\n%s\n%s\n%s\n%s\n%s\n",
"Enter request", " 1 - List accounts with zero balances",
" 2 - List accounts with credit balances",
" 3 - List accounts with debit balances", " 4 - End of run" );
try
{
do
{
System.out.print( "\n? " );
request = textIn.nextInt();
} while ( ( request <> 4 ) );
}
catch ( NoSuchElementException elementException )
{
System.err.println( "Invalid input." );
System.exit( 1 );
}
return choices[ request - 1 ];
}
public void processRequests()
{
accountType = getRequest();
while ( accountType != MenuOption.END )
{
switch ( accountType )
{
case ZERO_BALANCE:
System.out.println( "\nAccounts with zero balances:\n" );
break;
case CREDIT_BALANCE:
System.out.println( "\nAccounts with credit balances:\n" );
break;
case DEBIT_BALANCE:
System.out.println( "\nAccounts with debit balances:\n" );
break;
}
readRecords();
accountType = getRequest();
}
}
}
=====================
public class CreditInquiryTest
{
public static void main( String args[] )
{
CreditInquiry application = new CreditInquiry();
application.processRequests();
}
}=================================
public enum MenuOption
{
ZERO_BALANCE( 1 ),
CREDIT_BALANCE( 2 ),
DEBIT_BALANCE( 3 ),
END( 4 );
private final int value;
MenuOption( int valueOption )
{
value = valueOption;
}
public int getValue()
{
return value;
}
}
About Me
- .;'-------';.
- I dont want to tell 2 much bout my self coz you will nkow me personally than to judge me from what you hear and see bout me... hmm......... i will react the way you show your guisture but still i can hold my temper if needed.. ... I an a band member.. I am also a vocalist in an underground band. i am also a composer.. in fact i have composed several songs for polititian here in mati city. more bout that ?? single pako only 4 a moment.. jejeje ect,,
My post.................!!!!
-
▼
2010
(31)
-
▼
July
(31)
- Where are you now
- Where are you now
- Thingking of you
- lovestory
- the climb
- home
- the reason
- over you
- narda
- Prinsesa
- Fall for you
- Sitiches and burns
- love will keep us alive.
- Magbalik
- Sige
- Kahit Maputi Na ang Buhok ko
- Bisan pa
- ADDD
- assigment
- programming
- Mp3-Codes
- Mp3-Codes
- Mp3-Codes
- Ignorance
- Missery Bussines
- PESSURE BY Paramore
- Solo by Iyaz
- The Only Exeption by paramore
- Fireflies by Owlcity
- Fifteen by Tayor Swift
- Taylor Swift
-
▼
July
(31)
Subscribe to:
Post Comments (Atom)
Like it!!!
- songs
No comments:
Post a Comment