Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,687 members, 7,809,596 topics. Date: Friday, 26 April 2024 at 11:46 AM

My Fellow Java Programmers Might Like This,its Not A Main Class Though - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / My Fellow Java Programmers Might Like This,its Not A Main Class Though (1131 Views)

How Long Did It Take You Guys To Become Strong Java Programmers / Where Are The Java Programmers? (2) (3) (4)

(1) (Reply) (Go Down)

My Fellow Java Programmers Might Like This,its Not A Main Class Though by donkoleone(m): 3:42pm On Nov 25, 2008
import java.util.Scanner;

public class bank
{
private String bankName;

public bank( String name )
{
bankName = name;
}

public void setBankName( String name )
{
bankName = name;
}

public String getBankName()
{
return bankName;
}

public void displayMessage()
{
System.out.printf( "ACCOUNT UTILITY FOR %s\n",getBankName() );
}



public void processAccount()
{

System.out.println( "DEFAULT MENU BUTTONS:" );
System.out.println( "-'1' accesses new account processing" );
System.out.println( "-'2' accesses crediting transaction" );
System.out.println( "-'3' accesses debiting transaction" );
System.out.println( "-'4' exits application" );
Scanner input = new Scanner( System.in );
System.out.println( "ENTER '1' TO ACCESS NEW ACCOUNT PROCESSING" );
int x=input.nextInt();
if( x == 1 )
{
System.out.println( "ENTER NAME OF ACCOUNT OPENER:" );
String t = input.nextLine();

System.out.println( "ENTER OCCUPATION OF ACCOUNT OPENER:" );
String y = input.nextLine();

System.out.println( "ENTER INITIAL DEPOSIT AMOUNT:" );
int z = input.nextInt();

System.out.println( "ASSIGN ACCOUNT NUMBER:" );
int d = input.nextInt();

System.out.printf( "\nNAME: %s\n", t );
System.out.printf( "\nOCCUPATION: %s\n", y );
System.out.printf( "\nDEPOSIT AMOUNT: %d\n", z );
System.out.printf( "\nACCOUNT NUMBER: %d\n", d );

}else
System.out.println( "ENTER '2' TO ACCESS CREDITING TRANSACTION" );
int u=input.nextInt();
if( u == 2 )
{
System.out.println( "ENTER ACCOUNT NUMBER:" );
int f = input.nextInt();

System.out.println( "ENTER PRESENT AMOUNT IN ACCOUNT:" );
int h = input.nextInt();

System.out.println( "ENTER AMOUNT TO ADD:" );
int g = input.nextInt();

int sum = h + g;


System.out.printf( "AMOUNT SUCCESSFULLY ADDED: %d\n", sum );
}else
System.out.println( "ENTER '3' TO ACCESS DEBITING TRANSACTION" );
int r=input.nextInt();
if( r == 3 )
{
System.out.println( "ENTER ACCOUNT NUMBER:" );
int k = input.nextInt();

System.out.println( "ENTER CURRENT AMOUNT IN ACCOUNT:" );
int w = input.nextInt();

System.out.println( "ENTER AMOUNT TO DEBIT:" );
int q = input.nextInt();

int debit = w - q;

System.out.printf( "AMOUNT SUCCESSFULLY DEBITED: %d\n", debit );
}else
System.out.println( "ENTER '4' TO EXIT APPLICATION" );
int j=input.nextInt();
if( j == 4)
{
System.out.println( " BYE-BYE " );

}

}

}




Re: My Fellow Java Programmers Might Like This,its Not A Main Class Though by candylips(m): 3:55pm On Nov 25, 2008
Its very crude but will still work if you call processAccount() from another class with a main method
Re: My Fellow Java Programmers Might Like This,its Not A Main Class Though by yawatide(f): 4:53pm On Nov 25, 2008
Call me crazy but I think your code would look a lot cleaner if:

1) Instead of "if x == 1" you used switch/case statements  wink

2) You ran your options in a while loop, reading the input and redirecting to a switch or outputting an error if the input isn't text or they pressed say, 5 for "exit".  the way you have it now, and I haven't compiled your code (neither do I intend to  tongue), it seems all I will see is "press 1".  Then after I am done with "1", you tell me to press "2" which isn't how a real-life software would probably work. Right now, it looks very linear.
Re: My Fellow Java Programmers Might Like This,its Not A Main Class Though by candylips(m): 5:50pm On Nov 25, 2008
yea. There is even no exception handling so if i entered a string the whole program is gonna crash because of this
" int x=input.nextInt(); "
Re: My Fellow Java Programmers Might Like This,its Not A Main Class Though by Bassie(m): 6:09pm On Nov 25, 2008
And the Essence of the Post was ?
Re: My Fellow Java Programmers Might Like This,its Not A Main Class Though by yawatide(f): 6:14pm On Nov 25, 2008
To show his mad java "skills" tongue

He probably just read an ebook off of google and/or just learned this in class so he decides to put fingers to keyboard and come up with a class without compiling it for himself to see if it makes the slightest of sense.

Sorry to be harsh but the code sucks. I was actually only trying to be nice at first. Java is an OO language. The way he has it there, it looks more like paschal. In fact, this is the kind of code I call JINO (Java In Name Only)
Re: My Fellow Java Programmers Might Like This,its Not A Main Class Though by donkoleone(m): 3:08pm On Nov 27, 2008
OK so my funny code caused quite a stir,well the code was written months ago and happened to be in my flash as at the time so i posted it,well i agree with ur views cos(1) the lack of:
try( )
{
System.out.print,
int num=oui.nextInt();
}
catch(inputmismatchexception mismatchexception)
{
System.err.print( "TRY ANOTHER VALID VALUE" )
int num,
}
the lack of the exception handling feature was a flaw(i was not used to it as at the time the code was written)'also switch statements tend to make ur code neater and more readable,agreed.as for my brother that did not know what the code was for it was meant to be an ATM demo with acc. opening features.YEWATIDE ur views ar agreed wit but next time exhibit more matured relations wit ur fellow programmers.
Re: My Fellow Java Programmers Might Like This,its Not A Main Class Though by Fdeveloper(m): 4:47pm On Nov 28, 2008
@donkoleone

I think you may have missed the point of the criticism being levelled at you. It appears you have made the same mistake many aspiring programmers make in concentrating on the language rather than first having a clear understanding of the principles of programming.

What I mean is that in my opinion you would do well to fully understand the principles of Object Oriented Programming (OOP) first and then learn how to apply those principles in Java. Had you done so, I suspect your code would not have been so linear as you would have made more use of classes and also you probably would have included exception handling etc.
Re: My Fellow Java Programmers Might Like This,its Not A Main Class Though by yawatide(f): 7:33pm On Nov 28, 2008
donkoleone,

Can you define maturity? If yes, could you look in the mirror and see how it applies to you?
Re: My Fellow Java Programmers Might Like This,its Not A Main Class Though by judy4all: 5:23am On Nov 30, 2008
i still don't see the point of the code, other than using cases, or exception handling, there r tons of things wrong with it, The program is basically spitting back to the user what they enter, It only demonstrates the use of I/O in java,
Re: My Fellow Java Programmers Might Like This,its Not A Main Class Though by mimohmi(m): 6:45pm On Dec 05, 2008


Hi you guys, should learn to be objective when you need
to criticise someone. I believe the aim is to learn and not
mess ourselves up. If I may add my comment. This code
is a tutorial code, the type we wrote in those days
of Basic and Wbasic. It is procedural of course to demonstrate
the if else statement and probably introduction to the Scanner
and printf classes (Java 5 new features.). Hope am right. If not,
please donkoleone clarify.

(1) (Reply)

I Need Help With My Ajaxcontroltoolkit / Need A Developer For A Three Dimensional Store / Is Delphi Faster Than C#

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 23
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.