Ad
Code
Diff
  • import java.time.LocalDateTime;
    import java.time.format.DateTimeFormatter;
    
    public class Account {
    
        LocalDateTime lastTransactionDate = LocalDateTime.of(1900,1,1,1,1);
        int lastTransactionAmount = 0;
        int lastTransactionBalance = 0;
        private String statement = "Date Amount Balance" + "\n";
        private static final String DATE_FORMATTER= "dd-MM-yyyy";
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMATTER);
    
    
        public String printStatement() {
          if(this.lastTransactionBalance < 0){
            return this.statement + "\n Failed: Insufficient Funds";
          } else if(this.lastTransactionAmount <= 0){
            return this.statement + "Failed: Negative Transaction";
          }
            return this.statement + "\n" + lastTransactionDate.format(formatter) + " " + lastTransactionAmount + " " + lastTransactionBalance;
        }
    
        public void deposit(int amount){
            this.lastTransactionBalance += amount;
            this.lastTransactionAmount = amount;
            this.lastTransactionDate = LocalDateTime.now();;
        }
      
      public void withdraw(int amount){
        this.lastTransactionBalance -= amount;
        this.lastTransactionAmount = amount;
        this.lastTransactionDate = LocalDateTime.now();
      }
    }
    • import java.time.LocalDateTime;
    • import java.time.format.DateTimeFormatter;
    • public class Account {
    • LocalDateTime lastTransactionDate = LocalDateTime.of(1900,1,1,1,1);
    • int lastTransactionAmount = 0;
    • int lastTransactionBalance = 0;
    • private String statement = "Date Amount Balance" + "\n";
    • private static final String DATE_FORMATTER= "dd-MM-yyyy";
    • DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMATTER);
    • public String printStatement() {
    • if(this.lastTransactionBalance < 0){
    • return this.statement + "\n Failed: Insufficient Funds";
    • } else if(this.lastTransactionAmount <= 0){
    • return this.statement + "Failed: Negative Transaction";
    • }
    • return this.statement + "\n" + lastTransactionDate.format(formatter) + " " + lastTransactionAmount + " " + lastTransactionBalance;
    • }
    • public void deposit(int amount){
    • this.lastTransactionBalance += amount;
    • this.lastTransactionAmount = amount;
    • this.lastTransactionDate = LocalDateTime.now();;
    • }
    • public String printStatement() {
    • return "Date Amount Balance" + "\n" + "31.10.2022 " + "400 " + "400";
    • public void withdraw(int amount){
    • this.lastTransactionBalance -= amount;
    • this.lastTransactionAmount = amount;
    • this.lastTransactionDate = LocalDateTime.now();
    • }
    • public void deposit(int amount){};
    • }
Code
Diff
  • public class Account {
      
      public String printStatement() {
        return "Date Amount Balance" + "\n" + "31.10.2022 " + "400 " + "400";
      }
      
       public void deposit(int amount){};
    }
    • public class Account {
    • public String printStatement() {
    • return "Date Amount Balance";
    • return "Date Amount Balance" + "\n" + "31.10.2022 " + "400 " + "400";
    • }
    • public void deposit(int amount){};
    • }