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
- Each account type has fixed rate
- getInterest() returns balance * rate
- Rate stored as class constant
Related Inheritance exercises
- Practice Payment Processing System in Java
- Practice Vehicle Speed Calculator in Java
- Practice Multiple Interfaces in Java
Practice all Inheritance exercises · Run this idea in the Java compiler