Question: JAVA- How do I update this code to add these new guidelines? I uploaded an example of the input and what the output should look
JAVA- How do I update this code to add these new guidelines? I uploaded an example of the input and what the output should look like.
Record each transaction (up to 5 per instance of account), and print out the accountshistory whenever the p command is read from the input file.
Print a message with the account ID every time a new instance of Account is created(this should happen at the very beginning of your program)

This is the code I need to edit. There are 2 JAVA files:*************
import java.util.Scanner;
public class LP2 { public static void main(String[] args) { Scanner reader = new Scanner(System.in); Account[] myAccount; char type; double amount; int numAccnts = reader.nextInt(); myAccount = new Account[numAccnts];
while(reader.hasNext()) { type = reader.next().charAt(0); if(type == 'd'){ int accNum = reader.nextInt(); if (accNum >= numAccnts) System.out.println("Sorry you cannot create this account!!!"); else{ amount = reader.nextDouble(); myAccount[accNum] = new Account(); myAccount[accNum].deposit(amount); System.out.printf(" $%.2f deposited into account %d ", amount, myAccount[accNum].getAccountNumber());
} } else if(type == 'w'){ int accNum = reader.nextInt(); if (accNum >= myAccount.length ) System.out.println("Sorry this account does not exist!!"); else{ amount = reader.nextDouble(); myAccount[accNum].withdraw(amount);
System.out.printf(" $%.2f withdrawn from account %d ", amount, myAccount[accNum].getAccountNumber()); } } else if(type == 'p'){ for(int i=0;i System.out.println(); } } ************************************************ import java.util.Scanner; class Account{ private int accountNumber; private double balance; public Account(){ //Generating a random 4 digit Account Number accountNumber = (int)(Math.random() * 9000) + 1000; balance = 0.0; } //Getter method for Account Number public int getAccountNumber(){ return accountNumber; } //Method that adds amount to balance public void deposit(double amt){ //Updating new balance balance = balance + amt; } //Method that withdraws amount from balance public void withdraw(double amt){ //Validating amount if((balance - amt) //Method that adds interest to balance amount public double addInterest(){ double actualBalance = balance; //Adding interest to balance balance = balance * 1.005; //Returning amount of interest added return (balance - actualBalance); } //Method that returns balance amount public double getBalance(){ return balance; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
