Skip to content

Instantly share code, notes, and snippets.

@jimmykurian
Created February 3, 2012 21:45
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save jimmykurian/1732868 to your computer and use it in GitHub Desktop.
Save jimmykurian/1732868 to your computer and use it in GitHub Desktop.
A Java program that creates a Bank Account with withdraw, deposit, and intrest functions. And a tester class, that tests the SavingsAccount class.
//SavingsAccount.java - Jimmy Kurian
public class SavingsAccount
{
private double balance;
private double interest;
public SavingsAccount()
{
balance = 0;
interest = 0;
}
public SavingsAccount(double initialBalance, double initialInterest)
{
balance = initialBalance;
interest = initialInterest;
}
public void deposit(double amount)
{
balance = balance + amount;
}
public void withdraw(double amount)
{
balance = balance - amount;
}
public void addInterest()
{
balance = balance + balance * interest;
}
public double getBalance()
{
return balance;
}
}
//SavingsAccountTester.java - Jimmy Kurian
public class SavingsAccountTester
{
public static void main(String[] args)
{
SavingsAccount jimmysSavings = new SavingsAccount(1000, 0.10);
jimmysSavings.withdraw(250);
jimmysSavings.deposit(400);
jimmysSavings.addInterest();
System.out.println(jimmysSavings.getBalance());
System.out.println("Expected: 1265.0");
//1000-250=750 => 750+400=1150 => 1150+1150*0.10=1265.0
}
}
@honghuguo
Copy link

what are parts of the bank system?

@Nakhtaram
Copy link

how can we save our data by java programming?

@nandiniramana
Copy link

why we have choosen private double balance;
private double amount;
why cannot we take public instead of private

@Renesamuel
Copy link

@nandiniramana We took private for balance and interest because each account holder should have access only to their account and not to other's bank account. If we choose public , bank balance of an individual customer will be open to all the account holders.

@riyadskater
Copy link

is it possible to display this on a lcd screen?

@arunandrews123
Copy link

how can i create multiple objects
please show me with an example

@shashidharybhat
Copy link

@arunandrews123 It is very easy to create multiple objects.Just use different object names.
Ex : SavingsAccount MySaving = new SavingsAccount(1000, 0.10);
SavingsAccount SamuelSavings = new SavingsAccount(1000, 0.10);
SavingsAccount DanielSavings = new SavingsAccount(1000, 0.10);
..................................................................................................................................................................................

@basheeep
Copy link

If you wish to remove an account, how do you do it in the container class?

@Ollie7Seven
Copy link

hey guys, please I'm trying to write a code that displays Strings in an array, calculates the longest word(s), displays the word(s). any suggestions? thanks!

@amansingh227
Copy link

how we can make this program with user input

@wai-uts
Copy link

wai-uts commented Sep 27, 2020

public SavingsAccount()
{
balance = 0;
interest = 0;
}

public SavingsAccount(double initialBalance, double initialInterest)
{
	balance = initialBalance;
	interest = initialInterest;
}

not complaining?

@ElFuji
Copy link

ElFuji commented Oct 25, 2020

how declare overdraft

@ElFuji
Copy link

ElFuji commented Oct 25, 2020

do you*

@PrajaktaSathe
Copy link

how we can make this program with user input

Using Scanner class

@jainam03
Copy link

Java Program to Create Account with 1000 Rs Minimum Balance, Deposit Amount
Withdraw Amount and Also Throws LessBalanceException. It has a Class Called
LessBalanceException Which returns the Statement that Says WithDraw Amount(_Rs) is No
Valid. It has a Class Which Creates 2 Accounts, Both Account Deposite Money and One
Account Tries to WithDraw more Money Which Generates a LessBalanceException Tak
Appropriate Action for the Same.

Would a similar type of program help to solve this problem statement?

@DarkraiIce
Copy link

how can we save our data by java programming?

how can we save our data by java programming?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment