Commit c641ec48 authored by sam.pople's avatar sam.pople

inital commit

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 example = new BankAccount(97812345, "Sam", 34343);
example.withdrawal(100000);
example.Overdraftvalue(100000000);
example.withdrawal(500000);
example.display();
SavingsAccount example2 = new SavingsAccount(97812345, "Sam", 34343);
example2.Overdraftvalue(100000000);
example2.withdrawal(1000000);
}
}
public class BankAccount {
// Transactions are in pence
public BankAccount(int accountNumber, String name, int balance) {
this.AccountNumbervalue(accountNumber);
this.Namevalue(name);
this.Balancevalue(balance);
}
private int accountNumber;
private int balance;
private String name;
private double fees = 0.95;
protected int overdraft = 0;
public int getAccountNumber() {
return accountNumber;
}
public String getName() {
return name;
}
public int getBalance() {
return balance;
}
public double getFees() {
return fees;
}
public int getOverdraft() {
return overdraft;
}
public void AccountNumbervalue(int accountNumber) {
this.accountNumber = accountNumber;
}
public void Namevalue(String name) {
this.name = name;
}
public void Balancevalue(int balance) {
this.balance = balance;
}
public void Feesvalue(Double fees) {
this.fees = fees;
}
public void Overdraftvalue(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) {
}
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.Balancevalue(this.getBalance() + amount);
}
public boolean withdrawal(int amount) throws Exception {
if (this.getBalance() + this.getOverdraft() < amount) {
System.out.println("Not enough funds for a withdrawal \n");
return false;
} else {
this.Balancevalue(this.getBalance() - amount);
System.out.println("Withdrawal successful " + this.formatAmount(amount) + "\n");
return true;
}
}
public void bankFees() throws Exception {
this.Balancevalue(((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 balance = this.formatAmount(this.getBalance());
System.out.println("Balance: " + balance);
}
}
public class SavingsAccount extends BankAccount {
public SavingsAccount(int accountNumber, String name, int balance) {
super(accountNumber, name, balance);
this.Feesvalue(1.00);
}
public void accrueInterest() throws Exception {
this.Balancevalue((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