Share

PRELIMCLASS2

Public

09 March 2021

Views: 29

import java.util.Scanner;
public class Details{

static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
Bank account = getBank();
displayDetails(account);

System.out.println("Enter the amount (Positive to Credit or Negative to Withdraw):");
double amount = sc.nextDouble();
sc.nextLine();

if(amount >0) {
account.credit(amount);
}else {
account.withdraw(amount);
}

System.out.println("Last operation performed: "+account.getLastOperationPerformed());

System.out.println("Enter the percentage to increase the balance: ");
int percent = sc.nextInt();
double increaseAmount = account.getBalance() * percent * 0.01;

account.credit(increaseAmount);
}
private static void displayDetails(Bank account) {
System.out.println("Account details: ");
System.out.println("Name: "+account.getName() + " "+account.getSurName());
System.out.println("Address: "+account.getAddress());
System.out.println("Phone Num: "+account.getPhoneNum());
System.out.println("Balance: "+account.getBalance());
System.out.println("Last Operation performed: "+account.getLastOperationPerformed());
}

private static Bank getBank() {
Bank account;
String name, surname, address;
long phoneNum;

System.out.println("FILL OUT THE DETAILS: ");
System.out.println("First name: ");
name = sc.nextLine();

System.out.println("SurName: ");
surname = sc.nextLine();

System.out.println("Phone number: ");
phoneNum = Long.parseLong( sc.nextLine());

System.out.println("Address: ");
address = sc.nextLine();

//instantiating the BankAccount class
account = new Bank(name, surname,address, phoneNum);
return account;
}
}

Advertisement

Disable Third Party Ads