For example, the input: S 1 100.00 C 2 200.00 S 5 500.00 C 4 20.00 q 1 D 50.00 2 W 250.00 2 W 50.00 5 W 450.00 5 W 200.00 2 D 50.00 2 D 100.00 4 W 10.00 -1 must generate the following output: Error: withdrawal from account No.2 not allowed Error: withdrawal from account No.5 not allowed Error: deposit into account No.2 not allowed Savings Account Number: 1 Balance = 150.0 Credit Account Number: 2 Balance = 0.0 limit = 200.0 Savings Account Number: 5 Balance = 50.0v Credit Account Number: 4 Balance = 10.0 limit = 20.0v       import java.util.ArrayList; import java.util.Scanner;   public class LabProgram {     public static int find(ArrayList accounts, int acctNo) {         for (int i = 0; i < accounts.size(); i++)             if (accounts.get(i).getAcctNo() == acctNo)                 return (i);         return (-1);     }     public static void display(ArrayList accounts) {         /* Displays account information for eaach account in accounts */         /* Type your code here */     }     public static void transactions(ArrayList accounts, Scanner kb) {         int acctNo = kb.nextInt();         double amount;         String type;         int i;         while (acctNo >= 0) {             type = kb.next();             amount = kb.nextDouble();             i = find(accounts, acctNo);             if (i >= 0) {                 /* target account is found at position i of accounts   */                 /* transaction types: D for deposit and W for Withdraw */                 /* Assume tranasaction codes are correct               */                 /* Type your code here */                    }             else                 System.out.println("Eror: account not found");             acctNo = kb.nextInt();         }     }     public static void main(String[] args) {         ArrayList accounts = new ArrayList();         Scanner kb = new Scanner(System.in);         double amount;         int acctNo;         String acctType = kb.next();         while (!acctType.equals("q")) {             acctNo = kb.nextInt();             amount = kb.nextDouble();             if (acctType.equals("S"))                 accounts.add(new SavingsAccount(acctNo, amount));             else                 accounts.add(new CreditAccount(acctNo, amount));             acctType = kb.next();         }         transactions(accounts, kb);         display(accounts);     } } public interface Account {     public boolean deposit(double amount);     public boolean withdraw(double amount);     public void display();     public double getBalance();     public int getAcctNo(); } public class CreditAccount implements Account {          private double creditLimit;     private double balance;     private int acctNo;          public CreditAccount(int acctNo, double amount){     /* CreditAccount Balance. new caredit accounts */     /* start with a balance of 0" */     /* Type your code here */     }        @Override     public boolean withdraw(double amount){     /* Withdraws amount from the credit accout (i.e. balance=balance+amount) */     /* A withdraw that is more than credit limit is not accepted*/     /* returns true if withdrawal is accepted; otherwise retuen false */     /* Type your code here */     }          @Override     public  boolean deposit(double amount){     /* Deposits amount into the credit account (i.e. balance=balance-amount) */     /* A deposit that is more than balance is not accepted */     /* returns true if deposit is successful; otherwise retuen false */     /* Type your code here */     }          @Override     public double getBalance() {     /* returns account balance */     /* Type your code here */          }          @Override     public int getAcctNo(){     /* returns account number */     /* Type your code here */     }          @Override     public void display(){         System.out.println("Credit Account Number: " + acctNo + " Balance = "                 + balance + " limit = " + creditLimit);     } }   public class SavingsAccount implements Account {     private int acctNo;     private double balance;     public SavingsAccount(int acctNo, double amount) {     /* SavingsAccount Balance.   */     /* Type your code here */     }     @Override     public boolean withdraw(double amount) {     /* Withdraws amount from the savings accout (i.e. balance=balance-amount) */     /* A withdraw that is more than balance is not accepted*/     /* returns true if withdrawal is accepted; otherwise retuen false */     }     @Override     public boolean deposit(double amount) {     /* Deposits amount into the savings account (i.e. balance=balance+amount) */     /* returns true if deposit is successful; otherwise retuen false */     /* Type your code here */     }     @Override     public double getBalance() {     /* returns account balance */     /* Type your code here */     }     @Override     public int getAcctNo() {     /* returns account number */     /* Type your code here */     }     @Override     public void display() {         System.out.println("Savings Account Number: " + acctNo                 + " Balance = " + balance);     } }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

 

For example, the input:

S 1 100.00
C 2 200.00
S 5 500.00
C 4 20.00
q
1 D 50.00
2 W 250.00
2 W 50.00
5 W 450.00
5 W 200.00
2 D 50.00
2 D 100.00
4 W 10.00
-1
must generate the following output:

Error: withdrawal from account No.2 not allowed
Error: withdrawal from account No.5 not allowed
Error: deposit into account No.2 not allowed
Savings Account Number: 1 Balance = 150.0
Credit Account Number: 2 Balance = 0.0 limit = 200.0
Savings Account Number: 5 Balance = 50.0v Credit Account Number: 4 Balance = 10.0 limit = 20.0v

 

 

 

import java.util.ArrayList;
import java.util.Scanner;
 
public class LabProgram {


    public static int find(ArrayList<Account> accounts, int acctNo) {
        for (int i = 0; i < accounts.size(); i++)
            if (accounts.get(i).getAcctNo() == acctNo)
                return (i);
        return (-1);
    }

    public static void display(ArrayList<Account> accounts) {
        /* Displays account information for eaach account in accounts */
        /* Type your code here */

    }

    public static void transactions(ArrayList<Account> accounts, Scanner kb) {
        int acctNo = kb.nextInt();
        double amount;
        String type;
        int i;
        while (acctNo >= 0) {
            type = kb.next();
            amount = kb.nextDouble();
            i = find(accounts, acctNo);
            if (i >= 0) {
                /* target account is found at position i of accounts   */
                /* transaction types: D for deposit and W for Withdraw */
                /* Assume tranasaction codes are correct               */
                /* Type your code here */
  
                }
            else
                System.out.println("Eror: account not found");
            acctNo = kb.nextInt();
        }

    }

    public static void main(String[] args) {
        ArrayList<Account> accounts = new ArrayList<Account>();
        Scanner kb = new Scanner(System.in);
        double amount;
        int acctNo;
        String acctType = kb.next();
        while (!acctType.equals("q")) {
            acctNo = kb.nextInt();
            amount = kb.nextDouble();
            if (acctType.equals("S"))
                accounts.add(new SavingsAccount(acctNo, amount));
            else
                accounts.add(new CreditAccount(acctNo, amount));
            acctType = kb.next();
        }
        transactions(accounts, kb);
        display(accounts);
    }
}

public interface Account {
    public boolean deposit(double amount);
    public boolean withdraw(double amount);
    public void display();
    public double getBalance();
    public int getAcctNo();
}

public class CreditAccount implements Account {
    
    private double creditLimit;
    private double balance;
    private int acctNo;
    
    public CreditAccount(int acctNo, double amount){
    /* CreditAccount Balance. new caredit accounts */
    /* start with a balance of 0" */
    /* Type your code here */

    }
  
    @Override
    public boolean withdraw(double amount){
    /* Withdraws amount from the credit accout (i.e. balance=balance+amount) */
    /* A withdraw that is more than credit limit is not accepted*/
    /* returns true if withdrawal is accepted; otherwise retuen false */
    /* Type your code here */

    }
    
    @Override
    public  boolean deposit(double amount){
    /* Deposits amount into the credit account (i.e. balance=balance-amount) */
    /* A deposit that is more than balance is not accepted */
    /* returns true if deposit is successful; otherwise retuen false */
    /* Type your code here */

    }
    
    @Override
    public double getBalance() {
    /* returns account balance */
    /* Type your code here */
    
    }
    
    @Override
    public int getAcctNo(){
    /* returns account number */
    /* Type your code here */

    }
    
    @Override
    public void display(){
        System.out.println("Credit Account Number: " + acctNo + " Balance = "
                + balance + " limit = " + creditLimit);
    }
}

 

public class SavingsAccount implements Account {

    private int acctNo;
    private double balance;

    public SavingsAccount(int acctNo, double amount) {
    /* SavingsAccount Balance.   */
    /* Type your code here */

    }

    @Override
    public boolean withdraw(double amount) {
    /* Withdraws amount from the savings accout (i.e. balance=balance-amount) */
    /* A withdraw that is more than balance is not accepted*/
    /* returns true if withdrawal is accepted; otherwise retuen false */

    }

    @Override
    public boolean deposit(double amount) {
    /* Deposits amount into the savings account (i.e. balance=balance+amount) */
    /* returns true if deposit is successful; otherwise retuen false */
    /* Type your code here */

    }

    @Override
    public double getBalance() {
    /* returns account balance */
    /* Type your code here */

    }

    @Override
    public int getAcctNo() {
    /* returns account number */
    /* Type your code here */

    }

    @Override
    public void display() {
        System.out.println("Savings Account Number: " + acctNo
                + " Balance = " + balance);
    }
}

5.6 LAB: Accounts (Interfaces)
There are two types of Accounts: Savings Accounts and Credit Accounts. Both accounts implement the interface Account.
Given classes
• Class LabProgram contains the main method that based on input, creates a number of savings and credit accounts and adds them to
an arrayList. The main methd, then calls the method transactions that reads transaction records and applys them to corresponding
accounts. At the end of all transactions the main method calls method display that displlay account information for all accounts. (see
the samle input below for format of the input.)
• Class Savings Account implemets the interface Account and represents a saving account
• Class CreditAccount implemets the interface Account and represents a credit account
Your task is to complete the following methods:
• class CreditAccount
public CreditAccount (int acctNo, double amount) {
/* CreditAccount constructor
/* new credit accounts start with a balance of 0.0" */
public boolean withdraw (double amount) {
/* Invoked when a charge is posted to the credit account */
/* Withdraws amount from the credit accout (i.e. balance-balance+amount) */
}
}
}
public boolean deposit (double amount) {
/* Deposits amount into the credit account (i.e. balance-balance-amount) */
}
/* A withdrawal that is more than the credit limit is not accepted */
/* returns true of withdrawal is accepted; otherwise returns false */
public double getBalance () {
}
/* A deposit that is more than the balance is not accepted */
/* returns true of deposit is successful; otherwise returns false */
/* returns account balance */
public int getAcctNo () {
/* returns account number */
Transcribed Image Text:5.6 LAB: Accounts (Interfaces) There are two types of Accounts: Savings Accounts and Credit Accounts. Both accounts implement the interface Account. Given classes • Class LabProgram contains the main method that based on input, creates a number of savings and credit accounts and adds them to an arrayList. The main methd, then calls the method transactions that reads transaction records and applys them to corresponding accounts. At the end of all transactions the main method calls method display that displlay account information for all accounts. (see the samle input below for format of the input.) • Class Savings Account implemets the interface Account and represents a saving account • Class CreditAccount implemets the interface Account and represents a credit account Your task is to complete the following methods: • class CreditAccount public CreditAccount (int acctNo, double amount) { /* CreditAccount constructor /* new credit accounts start with a balance of 0.0" */ public boolean withdraw (double amount) { /* Invoked when a charge is posted to the credit account */ /* Withdraws amount from the credit accout (i.e. balance-balance+amount) */ } } } public boolean deposit (double amount) { /* Deposits amount into the credit account (i.e. balance-balance-amount) */ } /* A withdrawal that is more than the credit limit is not accepted */ /* returns true of withdrawal is accepted; otherwise returns false */ public double getBalance () { } /* A deposit that is more than the balance is not accepted */ /* returns true of deposit is successful; otherwise returns false */ /* returns account balance */ public int getAcctNo () { /* returns account number */
• ClassSavings Account
public Savings Account (int acctNo, double amount) {
/* Savings Account constructor. */
}
}
public boolean withdraw (double amount) {
/* Withdraws amount from the savings accout (i.e. balance-balance-amount) */
/* A withdrawal that is more than the balance is not accepted*/
/* returns true if withdrawal is accepted; otherwise returns false */
}
public boolean deposit (double amount) {
/* Deposits amount into the savings account (i.e. balance-balance+amount) */
/* returns true if deposit is successful; otherwise returns false */
}
public double getBalance () {
}
public int getAcctNo() {
}
/* returns account balance */
Class LabProgram:
}
/* returns account number */
public static void display (ArrayList<Account> accounts) {
/* Displays account information for each account in accounts */
public static void transactions (ArrayList<Account> accounts, Scanner kb) {
// This method is partially implmented. You must complete the following part
if (i >= 0) {
/* target account is found at position i of accounts
/* transaction types: D for deposit and W for Withdraw */
/* Assume tranasaction codes are correct
*/
Transcribed Image Text:• ClassSavings Account public Savings Account (int acctNo, double amount) { /* Savings Account constructor. */ } } public boolean withdraw (double amount) { /* Withdraws amount from the savings accout (i.e. balance-balance-amount) */ /* A withdrawal that is more than the balance is not accepted*/ /* returns true if withdrawal is accepted; otherwise returns false */ } public boolean deposit (double amount) { /* Deposits amount into the savings account (i.e. balance-balance+amount) */ /* returns true if deposit is successful; otherwise returns false */ } public double getBalance () { } public int getAcctNo() { } /* returns account balance */ Class LabProgram: } /* returns account number */ public static void display (ArrayList<Account> accounts) { /* Displays account information for each account in accounts */ public static void transactions (ArrayList<Account> accounts, Scanner kb) { // This method is partially implmented. You must complete the following part if (i >= 0) { /* target account is found at position i of accounts /* transaction types: D for deposit and W for Withdraw */ /* Assume tranasaction codes are correct */
Expert Solution
steps

Step by step

Solved in 6 steps with 5 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY