package templates;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Account {
private double accountBalance;
private List<String> miniStatement;
private boolean accountStatus;
private String accountPIN;
public Account() {
this.accountBalance = 10000.0;
this.accountStatus = true;
this.accountPIN = "1111";
this.miniStatement = new ArrayList<>();
}
public String doWithdraw(double amount) {
if(this.accountStatus) {
if(getBalance() > 0.00 && amount > 0.00 && getBalance() >= amount) {
this.accountBalance -= amount;
String str = "Account debited with $"+amount;
this.miniStatement.add(str);
return str;
}else
return "Amount entered is high, please enter less amount !!! ";
}else
return "Account is already closed";
}
public double getBalance() {
if(checkAccountStatus())
return this.accountBalance;
return -1.00;
}
public boolean changePIN(String newPin) {
if(checkAccountStatus()) {
this.accountPIN = newPin;
return true;
}
return false;
}
private boolean checkAccountStatus() {
return this.accountStatus;
}
public String closeAccount() {
if(checkAccountStatus()) {
System.out.printf("%s","Please collect $"+ getBalance());
this.accountStatus = false;
return ". Account is now closed";
}
return "Account is already closed";
}
public void printMiniStatement() {
if(checkAccountStatus()) {
Iterator<String> itr = this.miniStatement.iterator();
System.out.printf("%20s%n", "MINI STATEMENT");
while(itr.hasNext()) {
System.out.printf("%s%n", itr.next());
}
}
}
}
package templates;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Account {
private double accountBalance;
private List<String> miniStatement;
private boolean accountStatus;
private String accountPIN;
public Account() {
this.accountBalance = 10000.0;
this.accountStatus = true;
this.accountPIN = "1111";
this.miniStatement = new ArrayList<>();
}
public String doWithdraw(double amount) {
if(this.accountStatus) {
if(getBalance() > 0.00 && amount > 0.00 && getBalance() >= amount) {
this.accountBalance -= amount;
String str = "Account debited with $"+amount;
this.miniStatement.add(str);
return str;
}else
return "Amount entered is high, please enter less amount !!! ";
}else
return "Account is already closed";
}
public double getBalance() {
if(checkAccountStatus())
return this.accountBalance;
return -1.00;
}
public boolean changePIN(String newPin) {
if(checkAccountStatus()) {
this.accountPIN = newPin;
return true;
}
return false;
}
private boolean checkAccountStatus() {
return this.accountStatus;
}
public String closeAccount() {
if(checkAccountStatus()) {
System.out.printf("%s","Please collect $"+ getBalance());
this.accountStatus = false;
return ". Account is now closed";
}
return "Account is already closed";
}
public void printMiniStatement() {
if(checkAccountStatus()) {
Iterator<String> itr = this.miniStatement.iterator();
System.out.printf("%20s%n", "MINI STATEMENT");
while(itr.hasNext()) {
System.out.printf("%s%n", itr.next());
}
}
}
}
package templates;
public class User {
private String firstName;
private String lastName;
private String address;
private String phoneNumber;
public User(String firstName,String lastName,String address,String phoneNumber) {
this.firstName = firstName;
this.lastName = lastName;
this.address = address;
this.phoneNumber = phoneNumber;
}
public boolean setFirstName(String fname) {
if(!fname.isEmpty()) {
this.firstName = fname;
return true;
}
return false;
}
public String getFirstName() {
return this.firstName;
}
public boolean setLastName(String lname) {
if(!lname.isEmpty()) {
this.lastName = lname;
return true;
}
return false;
}
public String getLastName() {
return this.lastName;
}
public boolean setAddress(String addr) {
if(!addr.isEmpty()) {
this.address = addr;
return true;
}
return false;
}
public String getAddress() {
return this.address;
}
public boolean setPhoneNumer(String phonenum) {
if(phonenum.length() == 10) {
this.phoneNumber = phonenum;
return true;
}
return false;
}
public String getPhoneNumber() {
return this.phoneNumber;
}
}
Main/Test Class
package test;
import templates.*;
public class ATMTest {
public static void main(String[] args) {
Account savings = new Account();
User user1 = new User("Dummy","Name","27, First Floor, Suok-I","8888888888");
System.out.printf("%s%n", "Account Balance is $"+savings.getBalance());
System.out.println("-------------------------------------");
System.out.printf("%s%n", savings.doWithdraw(50.85));
System.out.println("-------------------------------------");
System.out.printf("%s%n", savings.doWithdraw(5540.85));
System.out.println("-------------------------------------");
System.out.printf("%s%n", savings.doWithdraw(3350.85));
System.out.println("-------------------------------------");
System.out.printf("%s%n", savings.doWithdraw(1090.50));
System.out.println("-------------------------------------");
System.out.printf("%s%n", savings.doWithdraw(90.50));
System.out.println("-------------------------------------");
System.out.printf("%s%n", savings.doWithdraw(966.94));
System.out.println("-------------------------------------");
System.out.printf("%s%n", "Account Balance is $"+savings.getBalance());
System.out.println("-------------------------------------");
savings.changePIN("1611");
savings.printMiniStatement();
System.out.println("-------------------------------------");
System.out.printf("%s%n", user1.getFirstName());
System.out.printf("%s%n", user1.getLastName());
System.out.printf("%s%n", user1.getAddress());
System.out.printf("%s%n", user1.getPhoneNumber());
System.out.println("-------------------------------------");
user1.setFirstName("Rain");
user1.setLastName("Man");
user1.setAddress("32, Second Floor, Suok-I");
user1.setPhoneNumer("9999999999");
System.out.printf("%s%n", user1.getFirstName());
System.out.printf("%s%n", user1.getLastName());
System.out.printf("%s%n", user1.getAddress());
System.out.printf("%s%n", user1.getPhoneNumber());
System.out.println("-------------------------------------");
System.out.printf("%s%n", savings.closeAccount());
System.out.println("-------------------------------------");
System.out.printf("%s%n", savings.doWithdraw(1111.50));
System.out.println("-------------------------------------");
}
}