Oop
Oop
1. PROGRAM 1:
public abstract class GeometricShape {
abstract void area();
int length, height;
2. PROGRAM 2:
3. PROGRAM 3:
abstract class BankAccount {
protected double balance;
@Override
public void deposit(double amount) {
balance += amount;
}
@Override
public void withdraw(double amount) {
if (balance >= amount) {
balance -= amount;
} else {
System.out.println("Insufficient funds for withdrawal.");
}
}
@Override
public void deposit(double amount) {
balance += amount;
}
@Override
public void withdraw(double amount) {
if (balance + overdraftLimit >= amount) {
balance -= amount;
} else {
System.out.println("Insufficient funds for withdrawal.");
}
}
}
class BankAccountManager {
public static void main(String[] args) {
SavingsAccount savingsAccount = new SavingsAccount(1000, 0.05);
CurrentAccount currentAccount = new CurrentAccount(500, 1000);
savingsAccount.deposit(500);
savingsAccount.withdraw(200);
savingsAccount.addInterest();
currentAccount.deposit(300);
currentAccount.withdraw(800);
4. PROGRAM 4:
abstract class Shape {
abstract double calculateArea();
abstract double calculatePerimeter();
}
@Override
double calculateArea() {
return Math.PI * Math.pow(radius, 2);
}
@Override
double calculatePerimeter() {
return 2 * Math.PI * radius;
}
}
@Override
double calculateArea() {
return 0.5 * base * height;
}
@Override
double calculatePerimeter() {
double hypotenuse = Math.sqrt(Math.pow(base, 2) + Math.pow(height,
2));
return base + height + hypotenuse;
}
}
OUTPUT:
Process finished