Skip to content

Instantly share code, notes, and snippets.

@johnSerrano
Last active October 17, 2015 06:40
Show Gist options
  • Save johnSerrano/56ef92270f816a88b391 to your computer and use it in GitHub Desktop.
Save johnSerrano/56ef92270f816a88b391 to your computer and use it in GitHub Desktop.
public class Account
{
private double checkingBalance;
private double savingsBalance;
public Account ( Double balance1, Double balance2 )
// constructor
{
checkingBalance = balance1;
savingsBalance = balance2;
}
public void setsavingsBalance( double balance2 )
{
if (balance2 >= 0)
savingsBalance = balance2;
else
System.out.println("Invalid amount");
}
public void creditChecking( double amount )
{
checkingBalance = checkingBalance + amount;
}
public void creditSavings( double amount )
{
savingsBalance = savingsBalance + amount;
}
public double getCheckingBalance()
{
return checkingBalance;
}
public double getSavingsBalance()
{
return savingsBalance;
}
public void debitChecking( double amount )
{
if (amount>checkingBalance)
System .out.println("Transaction amount exceeded checking balance" );
else
checkingBalance = checkingBalance - amount;
}
public void debitSavings( double amount )
{
if (amount>savingsBalance)
System .out.println("Transaction amount exceeded checking balance" );
else
savingsBalance = savingsBalance - amount;
}
public void moveFromSavingsToChecking(double amount)
{
if (amount>savingsBalance){
System .out.println("Transaction amount exceeded checking balance" );
}
else {
checkingBalance -= amount;
savingsBalance += amount;
}
}
public void moveFromCheckingToSavings(double amount)
{
if (amount>checkingBalance){
System .out.println("Transaction amount exceeded checking balance" );
}
else {
checkingBalance += amount;
savingsBalance -= amount;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment