Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone fill in the blanks in write your code part? import java.util. * ; import java.util.stream. * ; import static java.util.stream.Collectors.toList; class Account {

Can someone fill in the blanks in write your code part?
import java.util.*;
import java.util.stream.*;
import static java.util.stream.Collectors.toList;
class Account {
public long accountNumber;
public String holderName;
public double balance;
// Create constructor to initialize the class with the 3 params above
public Account(long accountNumber, String holderName, double balance){
this.accountNumber = accountNumber;
this.holderName = holderName;
this.balance = balance;
}
interface IBankingSystem {
void createAccount(Account account);
void updateAccountName(long accountNumber, String newHolderName);
void deleteAccount(long accountNumber);
void deposit(long accountNumber, double amount);
void withdraw(long accountNumber, double amount);
void printAllAccountSummariesByHolderName(String holderName);
}
class BankingSystem implements IBankingSystem {
private List accountList = new ArrayList();
public void printAllAccountsSummary(){
for (Account account : accountList){
printAccountSummary(account);
}
}
private void printAccountSummary(Account account){
String summary = String.format("{accountNumber: %d, holderName: %s,
balance: %.2f}", account.accountNumber,
account.holderName, account.balance);
printMessage(summary);
}
public void printAccountSummary(long accountNumber){
Account account = findAccount(accountNumber);
printAccountSummary(account);
}
// Use this to print messages.
public void printMessage(String message){
System.out.println(message);
}
// Use this method as a utility to locate the requested account.
// For example, you can use this when updating an account.
private Account findAccount(long accountNumber){
// Write your code here...
}
// Implement the [IBankingSystem] interface
// Write your code here...
// Hint: Use switch
}
class Solution {
public static void main(String[] args) throws IOException {
BankingSystem bank = new BankingSystem();
// input handling
BufferedReader bufferedReader = new BufferedReader(new
InputStreamReader(System.in));
int operationCount =
Integer.parseInt(bufferedReader.readLine().replaceAll("\\s+$","").split("=")
[1].trim());
bufferedReader.readLine();
IntStream.range(0, operationCount).forEach(opCountItr ->{
try {
List theInput =
Stream.of(bufferedReader.readLine().replaceAll("\\s+$","").split(","))
.collect(toList());
String action = theInput.get(0);
String arg1= theInput.size()>1? theInput.get(1).trim() : null;
String arg2= theInput.size()>2? theInput.get(2).trim() : null;
String arg3= theInput.size()>3? theInput.get(3).trim() : null;
ProcessInputs(bank, action, arg1, arg2, arg3);
} catch (IOException exception){
throw new RuntimeException(exception);
}
});
bufferedReader.close();
}
private static void ProcessInputs(BankingSystem bank, String action, String
arg1, String arg2, String arg3){
long accountNumber;
String holderName;
double amount;
switch (action){
case "createAccount":
accountNumber = Long.parseLong(arg1);
holderName = arg2;
amount = Double.parseDouble(arg3);
Account account = new Account(accountNumber, holderName, amount);
bank.createAccount(account);
break;
case "deleteAccount":
accountNumber = Long.parseLong(arg1);
bank.deleteAccount(accountNumber);
break;
case "deposit": {
accountNumber = Long.parseLong(arg1);
amount = Double.parseDouble(arg2);
bank.deposit(accountNumber, amount);
break;
}
case "printAllAccountsSummary":
bank.printAllAccountsSummary();
break;
case "printAllAccountSummariesByHolderName":
holderName = arg1;
bank.printAllAccountSummariesByHolderName(holderName);
break;
case "printAccountSummary":
accountNumber = Long.parseLong(arg1);
bank.printAccountSummary(accountNumber);
break;
case "updateAccountName":
accountNumber = Long.parseLong(arg1);
holderName = arg2;
bank.updateAccountName(accountNumber, holderName);
break;
case "withdraw":
accountNumber = Long.parseLong(arg1);
amount = Double.parseDouble(arg2);
bank.withdraw(accountNumber, amount);
break;
default:
throw new IllegalArgumentException("No know action name was
provided.");
}
}
}
/*Sample Input 0
OPERATION_COUNT=2
createAccount, 123, "Alice", 100.00
printAccountSummary, 123
Sample Output 0
{accountNumber: 123, holderName: "Alice", balance: 100.00}
Sample Input 1
OPERATION_COUNT=2
createAccount, 2, "Alice", 352.14
updateAccountName, 5, "Bob"
Sample Output 1
ACCOUNT_NOT_FOUND
Sample Input 2
OPERATION_COUNT=3
createAccount, 2, "Alice", 352.14
updateAccountName, 2, "Bob"
printAccountSummary, 2
Sample Output 2
{accountNumber: 2, holderName: "Bob", balance: 352.14}
Sample Input 3
OPERATION_COUNT=2
createAccount, 123, "Alice", 100.00
withdraw, 456,42.61
Sample Output 3
ACCOUNT_NOT_FOUND

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions