Computer Science Draw the Control flow graph for the following class public class Account { private double balance; private boolean frozen; Logger log = Logger.getLogger("log"); public Account(double balance, boolean frozen) { log.entering("Account", "constructor"); log.exiting("Account", "constructor"); this.balance = balance; this.frozen = frozen; } public void deposit(int amt) { log.entering("Account", "deposit"); if (frozen == true) { log.config("Account is frozen"); InvalidBankTransaction invalidTransaction = new InvalidBankTransaction("Bank Account Frozen"); System.out.println(invalidTransaction.getMessage()); } else { log.config("deposit proccessing"); balance = balance + amt; System.out.println("Amount deposited Successfully"); System.out.println(" "); System.out.println("Total Balance: " + balance); System.out.println(" "); log.exiting("Account", "deposit"); } } public int userInput() { log.entering("Account", "userInput"); Scanner scanner = new Scanner(System.in); System.out.println("Enter the amount to be deposited: "); int amt = scanner.nextInt(); if (amt <= 0) { InvalidBankTransaction depositnegativeError = new InvalidBankTransaction("Invalid Deposit Amount"); System.out.println(depositnegativeError.getMessage()); userInput(); } else { return amt; } log.exiting("Account", "constructor"); return amt; } public void withdraw(int amt) { log.entering("Account", "withdraw"); System.out.println(" "); if (frozen == true) { InvalidBankTransaction invalidTransaction = new InvalidBankTransaction("Bank Account Frozen"); System.out.println(invalidTransaction.getMessage()); } else if (balance < amt && frozen == false) { InvalidBankTransaction invalidWithDraw = new InvalidBankTransaction("InValid Withdrawal Amount"); System.out.println(invalidWithDraw.getMessage()); } else { balance = (balance - amt); System.out.println("Please Collect your " + amt + " Riyals"); System.out.println(" "); System.out.println("Total Balance: " + balance); System.out.println(" "); } } public double getBalance() { log.entering("Account", "getBalance"); return balance; } public boolean isFrozen() { log.entering("Account", "isFrozen"); log.exiting("Account", "isFrozen"); return frozen; } public void setBalance(double balance) { log.entering("Account", "setBalance"); this.balance = balance; } public void setFrozen(boolean frozen) { log.entering("Account", "setFrozen"); this.frozen = frozen; } }
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Computer Science
Draw the Control flow graph for the following class
public class Account {
private double balance;
private boolean frozen;
Logger log = Logger.getLogger("log");
public Account(double balance, boolean frozen) {
log.entering("Account", "constructor");
log.exiting("Account", "constructor");
this.balance = balance;
this.frozen = frozen;
}
public void deposit(int amt) {
log.entering("Account", "deposit");
if (frozen == true) {
log.config("Account is frozen");
InvalidBankTransaction invalidTransaction = new InvalidBankTransaction("Bank Account Frozen");
System.out.println(invalidTransaction.getMessage());
} else {
log.config("deposit proccessing");
balance = balance + amt;
System.out.println("Amount deposited Successfully");
System.out.println(" ");
System.out.println("Total Balance: " + balance);
System.out.println(" ");
log.exiting("Account", "deposit");
}
}
public int userInput() {
log.entering("Account", "userInput");
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the amount to be deposited: ");
int amt = scanner.nextInt();
if (amt <= 0) {
InvalidBankTransaction depositnegativeError = new InvalidBankTransaction("Invalid Deposit Amount");
System.out.println(depositnegativeError.getMessage());
userInput();
} else {
return amt;
}
log.exiting("Account", "constructor");
return amt;
}
public void withdraw(int amt) {
log.entering("Account", "withdraw");
System.out.println(" ");
if (frozen == true) {
InvalidBankTransaction invalidTransaction = new InvalidBankTransaction("Bank Account Frozen");
System.out.println(invalidTransaction.getMessage());
} else if (balance < amt && frozen == false) {
InvalidBankTransaction invalidWithDraw = new InvalidBankTransaction("InValid Withdrawal Amount");
System.out.println(invalidWithDraw.getMessage());
} else {
balance = (balance - amt);
System.out.println("Please Collect your " + amt + " Riyals");
System.out.println(" ");
System.out.println("Total Balance: " + balance);
System.out.println(" ");
}
}
public double getBalance() {
log.entering("Account", "getBalance");
return balance;
}
public boolean isFrozen() {
log.entering("Account", "isFrozen");
log.exiting("Account", "isFrozen");
return frozen;
}
public void setBalance(double balance) {
log.entering("Account", "setBalance");
this.balance = balance;
}
public void setFrozen(boolean frozen) {
log.entering("Account", "setFrozen");
this.frozen = frozen;
}
}
Step by step
Solved in 3 steps with 1 images