Commit d44b255b authored by cosmina.dunca's avatar cosmina.dunca

Commit

parents
File added
## 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 {
// test app 1 - bank acc
BankAccount myAcc = new BankAccount(23456789, "John Doe", 3680.0);
myAcc.display();
myAcc.deposit(84.5);
System.out.println(myAcc.balance);
myAcc.withdarw(57.33);
System.out.println(myAcc.balance);
// test app 2 - savings acc
SavingsAccount sAcc = new SavingsAccount(42787794, "Mary Watson", 30.0);
sAcc.display();
// check deposit
sAcc.deposit(42.0);
System.out.println(sAcc.balance);
// try too withdraw more than 100
sAcc.withdarw(155);
System.out.println(sAcc.balance);
// withdraw
sAcc.withdarw(15);
System.out.println(sAcc.balance);
// add overdraft
sAcc.addOverdraft(250);
System.out.println(sAcc.overdraft);
// withdraw overdraft
sAcc.withdarw(100);
System.out.println(sAcc.balance);
// add money so that the overdraft is not used
sAcc.deposit(77);
System.out.println(sAcc.balance);
sAcc.accrueInterest();
System.out.println(sAcc.balance);
}
}
public class BankAccount {
// variables
public int accountNumber;
public String name;
public double balance;
// constructor
BankAccount(int accountNumber, String name, double balance){
this.accountNumber = accountNumber;
this.name = name;
this.balance = balance;
}
public void BankFees() {
double fee = 0.05 * this.balance;
this.balance -= fee;
}
public void deposit(double amount) {
this.balance += amount;
BankFees();
}
public void withdarw(double amount) {
double fee = 0.05 * this.balance;
if(amount <= this.balance - fee) {
this.balance -= amount;
BankFees();
}
}
public void display() {
System.out.println("The account number is: " + this.accountNumber + ". The name of the owner is " + this.name + ". The account balance is: " + this.balance + ".");
}
}
public class SavingsAccount extends BankAccount {
public double overdraft;
public double totalOverdraft;
//constructor
SavingsAccount(int accountNumber, String name, double balance) {
super(accountNumber, name, balance);
}
@Override
public void deposit(double amount) {
if(overdraft != totalOverdraft)
{
if(amount > totalOverdraft - overdraft)
{
this.balance += amount - (totalOverdraft - overdraft);
overdraft = totalOverdraft;
}
} else {
this.balance += amount;
}
}
@Override
public void withdarw(double amount) {
if(amount <= this.balance && amount <= 100) {
this.balance -= amount;
} else if (amount > this.balance && amount < overdraft && amount <= 100) {
overdraft = overdraft - (amount - this.balance);
this.balance = 0;
double amountLeftToUse = totalOverdraft - overdraft;
System.out.println("Your account was overdrafted. You have used " + amountLeftToUse + ". The amount left: " + overdraft + ".");
}
}
public void accrueInterest() {
double interest = 0.05 * this.balance;
deposit(interest);
}
public void addOverdraft(double overdraft) {
this.overdraft += overdraft;
totalOverdraft += overdraft;
}
}
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