Created
August 13, 2019 11:22
-
-
Save 0ryant/ea15d36c713f444eddd36c97e0d4fea6 to your computer and use it in GitHub Desktop.
Java - Coding Challenge - Bank Account
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BankAccount { | |
// Params | |
private String accountNumber; | |
private double balance; | |
private String customerName; | |
private String emailAddress; | |
private String phoneNumber; | |
// Constructors | |
public BankAccount(){ | |
this("Default Account Number",0.0,"Default Name", | |
"Default Email","Default Phone"); | |
} | |
public BankAccount(String accountNumber,double balance,String customerName, String emailAddress, String phoneNumber){ | |
this.accountNumber = accountNumber; | |
this.balance = balance; | |
this.customerName = customerName; | |
this.emailAddress = emailAddress; | |
this.phoneNumber = phoneNumber; | |
} | |
public BankAccount(String customerName, String emailAddress, String phoneNumber) { | |
this("Default Account Number",0.0,customerName,emailAddress,phoneNumber); | |
this.customerName = customerName; | |
this.emailAddress = emailAddress; | |
this.phoneNumber = phoneNumber; | |
} | |
// Getters | |
public String getAccountNumber(){ | |
return accountNumber; | |
} | |
public double getBalance(){ | |
return balance; | |
} | |
public String getCustomerName(){ | |
return customerName; | |
} | |
public String getEmailAddress(){ | |
return emailAddress; | |
} | |
public String getPhoneNumber(){ | |
return phoneNumber; | |
} | |
// Setters | |
public void setAccountNumber(String accountNumber){ | |
this.accountNumber=accountNumber; | |
} | |
public void setBalance(double balance) { | |
this.balance = balance; | |
} | |
public void setCustomerName(String customerName) { | |
this.customerName = customerName; | |
} | |
public void setEmailAddress(String emailAddress) { | |
this.emailAddress = emailAddress; | |
} | |
public void setPhoneNumber(String phoneNumber) { | |
this.phoneNumber = phoneNumber; | |
} | |
// Methods | |
public void depositFunds(double deposit){ | |
if (deposit <0){ | |
System.out.println("Deposit must be greater than 0!"); | |
} else { | |
this.balance+=deposit; | |
System.out.println("New Balance is "+this.balance); | |
} | |
} | |
public void withdrawFunds(double withdraw){ | |
if (withdraw>this.balance){ | |
System.out.println("Insufficient Funds, "+this.balance+" available but "+withdraw+" was requested!"); | |
} else { | |
this.balance-=withdraw; | |
System.out.println("New Balance is "+this.balance); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment