Bank Account Types in Java: Explanation & Practice

Different account types with interest

Problem summary

Create BankAccount hierarchy with Savings (5% interest) and Checking (1% interest).

Starter code

// BankAccount: balance, abstract getInterest()
// Savings: 5% annual interest
// Checking: 1% annual interest

public class Main {
    public static void main(String[] args) {
        // Test case 1: Savings with 10000
        // Print: Interest: <result>
    }
}

Expected output and test cases

  • Savings 10000 * 5%
    Interest: 500.0
  • Checking 10000 * 1%
    Interest: 100.0
  • Savings 5000
    Interest: 250.0

Hints

  1. Each account type has fixed rate
  2. getInterest() returns balance * rate
  3. Rate stored as class constant

Related Inheritance exercises

Practice all Inheritance exercises · Run this idea in the Java compiler