Commit 446f5000 authored by Gabriel Penman's avatar Gabriel Penman

my workk

parents
File added
{
"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).
File added
File added
public class App {
public static void main(String[] args) throws Exception {
BankAccount example = new BankAccount(93946723, 10000, "Gabriel");
example.withdraw(100000);
example.setOverdraft(100000000);
example.withdraw(500000);
example.display();
SavingsAccount example2 = new SavingsAccount(93946723, 10000, "Gabriel");
example2.setOverdraft(100000000);
example2.withdraw(1000000);
}
}
public class BankAccount {
// All transactions stored in pence
public BankAccount(int accountNumber, int balance, String name) {
this.setAccountNumber(accountNumber);
this.setBalance(balance);
this.setName(name);
}
private int accountNumber;
private int balance;
private String name;
private double fees = 0.95;
protected int overdraft = 0;
public int getAccountNumber() {return accountNumber;}
public int getBalance() {return balance;}
public String getName() {return name;}
public double getFees() {return fees;}
public int getOverdraft() {return overdraft;}
public void setAccountNumber(int accountNumber) {this.accountNumber=accountNumber;}
public void setBalance(int balance) {this.balance=balance;}
public void setName(String name) {this.name=name;}
public void setFees(Double fees) {this.fees=fees;}
public void setOverdraft(int overdraft) {this.overdraft=overdraft;}
public String formatAmount(int amount) throws Exception {
String string;
boolean negative;
if (amount < 0) {
string = String.valueOf(amount*-1);
negative = true;
} else {
string = String.valueOf(amount);
negative = false;
}
if (string.length() == 1) {
string = "00"+string;
}
if (string.length() == 2) {
string = "0"+string;
}
if (negative) {
return "-£ "+string.substring(0, string.length()-2) + "." + string.substring(string.length()-2, string.length());
} else {
return "£"+string.substring(0, string.length()-2) + "." + string.substring(string.length()-2, string.length());
}
}
public void deposit(int amount) throws Exception {
this.setBalance(this.getBalance() + amount);
}
public boolean withdraw(int amount) throws Exception {
if (this.getBalance()+this.getOverdraft() < amount) {
System.out.println("Insufficent funds to withdraw \n");
return false;
} else {
this.setBalance(this.getBalance() - amount);
System.out.println("Successfully withdrawn "+this.formatAmount(amount)+"\n");
return true;
}
}
public void bankFees() throws Exception {
this.setBalance(((int) Math.round(this.getBalance()*this.getFees())));
}
public void display() throws Exception {
System.out.println("Bank details:\n");
System.out.println("Account no: " +this.getAccountNumber()+ "\nAccount holder: "+this.getName());
String bal = this.formatAmount(this.getBalance());
System.out.println("Balance: "+bal);
}
}
\ No newline at end of file
public class SavingsAccount extends BankAccount {
public SavingsAccount(int accountNumber, int balance, String name){
super(accountNumber, balance, name);
this.setFees(1.00);
}
public void accrueInterest() throws Exception {
this.setBalance((int) Math.round(this.getBalance()*1.05));;
}
public int getOverdraft(int amount) {return 0;}
}
\ No newline at end of file
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