public class Account { public Account() { balance = 0; } public double getBalance() { return balance;} public void withdraw(double amt) { balance -= amt; } public void deposit(double amt) { balance += amt; } private double balance; } public class FeeAccount extends Account { public FeeAccount (double fee) { super(); withdrawFee public double getFee O { return withdrawFee;} = fee; } public void withdraw(double amt) { super withdraw(amt + withdrawkee); } private double withdraWkee; } // main code Account a new Account(); %3D ReeAccount f = new FeeAccount (5); కెకs(500) Eadeposit(250); For the following statement sets, provide the output or state whether one of the statements is invalid. Answer each independently. a) System.out.println(augetfee() ); b) System.out.println(£getBalance()); c) Account b = f; bewithdraw ( 50); System.out RKintln(b.getBalance()); d) EeeAccount g = (ReeAccount) a; Luderosit(50); System.out.RKintln(g.getBalance()); e) Account b = f; EeeAccountg = (EeeAccount) b; kudeposit(100); System.out.RKintln(g.getBalance());

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

JAVA

```java
public class Account {
    public Account() { balance = 0; }
    public double getBalance() { return balance; }
    public void withdraw(double amt) { balance -= amt; }
    public void deposit(double amt) { balance += amt; }
    private double balance;
}

public class FeeAccount extends Account {
    public FeeAccount(double fee) {
        super();
        withdrawFee = fee;
    }
    public double getFee() { return withdrawFee; }
    public void withdraw(double amt) 
    { super.withdraw(amt + withdrawFee); }
    private double withdrawFee;
}

// main code 
Account a = new Account();
FeeAccount f = new FeeAccount(5);
a.deposit(500);
f.deposit(250);

For the following statement sets, provide the output or state whether 
one of the statements is invalid. Answer each independently.

a) System.out.println(a.getFee());

b) System.out.println(f.getBalance());

c) Account b = f;
   b.withdraw(50);
   System.out.println(b.getBalance());

d) FeeAccount g = (FeeAccount) a;
   g.deposit(50);
   System.out.println(g.getBalance());

e) Account b = f;
   FeeAccount g = (FeeAccount) b;
   b.deposit(100);
   System.out.println(g.getBalance());
```

### Explanation

This Java code defines two classes, `Account` and `FeeAccount`, with `FeeAccount` extending `Account`. 

**Class: `Account`:**
- A constructor initializing `balance` to 0.
- Methods:
  - `getBalance()`: Returns the current balance.
  - `withdraw(double amt)`: Deducts `amt` from the balance.
  - `deposit(double amt)`: Adds `amt` to the balance.
- Private variable `balance`.

**Class: `FeeAccount`:**
- Extends `Account`, adding a withdrawal fee.
- Constructor takes a fee as a parameter and initializes `withdrawFee`.
- Methods:
  - `getFee()`: Returns the withdrawal fee.
  - `withdraw(double amt)`: Deducts `amt` plus the fee from the balance.

**Main Code:**
- Creates two instances: 
  - `a` of type `Account`.
  - `f` of type `FeeAccount` initialized with a fee of 5.
- Deposits into `a` and `f`.

**Statement
Transcribed Image Text:```java public class Account { public Account() { balance = 0; } public double getBalance() { return balance; } public void withdraw(double amt) { balance -= amt; } public void deposit(double amt) { balance += amt; } private double balance; } public class FeeAccount extends Account { public FeeAccount(double fee) { super(); withdrawFee = fee; } public double getFee() { return withdrawFee; } public void withdraw(double amt) { super.withdraw(amt + withdrawFee); } private double withdrawFee; } // main code Account a = new Account(); FeeAccount f = new FeeAccount(5); a.deposit(500); f.deposit(250); For the following statement sets, provide the output or state whether one of the statements is invalid. Answer each independently. a) System.out.println(a.getFee()); b) System.out.println(f.getBalance()); c) Account b = f; b.withdraw(50); System.out.println(b.getBalance()); d) FeeAccount g = (FeeAccount) a; g.deposit(50); System.out.println(g.getBalance()); e) Account b = f; FeeAccount g = (FeeAccount) b; b.deposit(100); System.out.println(g.getBalance()); ``` ### Explanation This Java code defines two classes, `Account` and `FeeAccount`, with `FeeAccount` extending `Account`. **Class: `Account`:** - A constructor initializing `balance` to 0. - Methods: - `getBalance()`: Returns the current balance. - `withdraw(double amt)`: Deducts `amt` from the balance. - `deposit(double amt)`: Adds `amt` to the balance. - Private variable `balance`. **Class: `FeeAccount`:** - Extends `Account`, adding a withdrawal fee. - Constructor takes a fee as a parameter and initializes `withdrawFee`. - Methods: - `getFee()`: Returns the withdrawal fee. - `withdraw(double amt)`: Deducts `amt` plus the fee from the balance. **Main Code:** - Creates two instances: - `a` of type `Account`. - `f` of type `FeeAccount` initialized with a fee of 5. - Deposits into `a` and `f`. **Statement
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
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