Re: Simple Banking System
Quote:
Originally Posted by
ShadowKing98
I want to make a Simple Banking System. I am bit confused.
There will be some duties in the bank
recieveCash
sendCash
1 variable called
balance
When someone uses recieveCash, it will increase the balance, when someone spends it will decrease the balance
1 method called getBalance will show the balance of cash in the Bank. getBalance will print. getBalance should be private.
Please Help
:-t:-t
Ok, you've said nothing on how you want to go about doing this?
receive cash and send cash sound like they are supposed to be methods.
balance should probably be a double or float variable I think.
I think you should also have a method called setBalance.
Also, was balance supposed to be private or getBalance?
A setter method looks like this(oh, and make sure to have some other type of class variable, i.e. one defined at the beginning with variable declarations.
Like so:
private double balance;
Anyway, a setter method looks like this, using the variable defined above when I'm referring to this.balance (this is an object's reference to itself).
Code java:
public void setBalance(double balance)
{
this.balance=balance;
}
This method will print balance.
Code java:
private void getBalance()
{
System.out.println(balance);
}
I'd recommend that for send cash and receive cash, you make them setter methods and pass them a double variable called cash as a parameter.
Then I recommend you call setBalance with balance +- cash as parameter.
Also, you should have something like
Code java:
if ((balance-cash) < 0)
{
System.out.println("Cannot withdraw this amount!");
return;
}
This will exit the method and stop the account from going into the negative.
To have a method call another method inside itself, do something like this:
Code java:
setBalance(balance + cash);
Ask if you have any more questions.
:cool:
Can't say how to implement it, (GUI or command prompt as you didn't specify that.)
Re: Simple Banking System
Im kinda a noob. Yes getBalance was supposed to be private. Could you tell me how to build it with return values only. And please tell me where to put the code. Oh yeah it doesnt really matter where to implement it. Could you tell me should I make a new class or do I put it in main. Please tell me where to put the pieces of code you gave me
Please
Re: Simple Banking System
Code :
package bankassignment;
public class Main {
public static void main(String[] args) {
}
}
Please tell me where to put the pieces of code
Re: Simple Banking System
JavaPenguin, spoon feeding to that extent when he showed such very little effort will not help him.
If he can't do the basics himself, he will keep coming back asking 'ok what next?', as he won't have a hope in hell of doing the rest of the code.
Would have been more beneficial to provide him with some reading material and tutorials.
Re: Simple Banking System
OK please help me out newbie
Re: Simple Banking System
As I don't quite know how much experience you have with Java, i'll point you here.
Trail: Learning the Java Language (The Java™ Tutorials)
The first three topics should be sufficient.
- Feel free to come back with questions if you're not sure on a particular topic.
Re: Simple Banking System
This might be slightly off topic for you but I would probably have the balance and any other monetary amounts as data type of long and then remove the decimal point.
The reason being that different operating systems have different floating point precision. Otherwise you could set the balance as a strictfp float but I'd still go with longs.
This might not be too much of an issue for you though but be careful with floating point comparisons.
// Json