Commit 04404339 authored by elliot.copeland's avatar elliot.copeland

Exercise complete

parents
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
public class App {
public static void main(String[] args) throws Exception {
BankAccount test = new BankAccount(800, "Elliot", 100);
test.display();
System.out.println(" ");
test.deposit(1);
test.display();
System.out.println(" ");
test.withdrawal(102);
test.display();
System.out.println(" ");
test.bankFees();
test.display();
System.out.println(" ");
test.addOverdraft(500);
test.withdrawal(800);
test.display();
BankAccount test2 = new SavingAccount(900, "Bob", 100);
test2.display();
System.out.println(" ");
test2.deposit(1);
test2.display();
System.out.println(" ");
test2.withdrawal(1);
test2.display();
System.out.println(" ");
test2.bankFees();
test2.display();
test2.addOverdraft(500);
test2.display();
}
}
public class BankAccount {
protected int accountNumber;
protected String name;
protected float balance;
protected float overdraft = 0;
public BankAccount(int accountnumber, String uname, float cbalance) {
this.accountNumber = accountnumber;
this.name = uname;
this.balance = cbalance;
}
public void deposit(float i) {
balance += i;
}
public void withdrawal(float i) {
if ((balance + overdraft - i) >= 0) {
balance -= i;
}
else {
System.out.println("You do not have enough funds in your account.");
}
}
public void bankFees() {
balance -= (balance * 0.05);
}
public void display() {
System.out.println("Name: " + name);
System.out.println("Account Number: " + Integer.toString(accountNumber));
System.out.println("Balance: " + Float.toString(balance));
}
public void addOverdraft(float od) {
overdraft = od;
}
}
public class SavingAccount extends BankAccount {
public SavingAccount(int accountnumber, String uname, float cbalance) {
super(accountnumber, uname, cbalance);
}
public void accrueIntrest() {
balance += (balance + (balance * 0.05f));
}
@Override
public void bankFees() {
System.out.println("There are no fees on a savings account.");
}
@Override
public void addOverdraft(float od) {
System.out.println("You cannot add overdraft on a savings account.");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment