fork download
  1.  
  2. interface Vehicle {
  3. void displayDetails();
  4. double calculateRent(int days);
  5. }
  6.  
  7. interface ExtraFeature {
  8. void showFeature();
  9. }
  10.  
  11. class Car implements Vehicle, ExtraFeature {
  12. public void displayDetails() {
  13. System.out.println("Vehicle: Car");
  14. System.out.println("Rent per day: 2000 Tk");
  15. }
  16.  
  17. public double calculateRent(int days) {
  18. return days * 2000;
  19. }
  20.  
  21. public void showFeature() {
  22. System.out.println("Feature: Air Conditioning Available");
  23. }
  24. }
  25.  
  26. class Bike implements Vehicle, ExtraFeature {
  27. public void displayDetails() {
  28. System.out.println("Vehicle: Bike");
  29. System.out.println("Rent per day: 800 Tk");
  30. }
  31.  
  32. public double calculateRent(int days) {
  33. return days * 800;
  34. }
  35.  
  36. public void showFeature() {
  37. System.out.println("Feature: Helmet Available");
  38. }
  39. }
  40.  
  41. class RentalManager {
  42. Vehicle processVehicle(Vehicle vehicle) {
  43. return vehicle;
  44. }
  45. }
  46.  
  47. public class Main {
  48. public static void main(String[] args) {
  49. RentalManager manager = new RentalManager();
  50.  
  51. Vehicle v1 = manager.processVehicle(new Car());
  52. Vehicle v2 = manager.processVehicle(new Bike());
  53.  
  54. v1.displayDetails();
  55. System.out.println("Total Rent: " + v1.calculateRent(3) + " Tk");
  56. ((ExtraFeature) v1).showFeature();
  57.  
  58. System.out.println();
  59.  
  60. v2.displayDetails();
  61. System.out.println("Total Rent: " + v2.calculateRent(3) + " Tk");
  62. ((ExtraFeature) v2).showFeature();
  63. }
  64. }
  65.  
Success #stdin #stdout 0.14s 37360KB
stdin
Standard input is empty
stdout
Vehicle: Car
Rent per day: 2000 Tk
Total Rent: 6000.0 Tk
Feature: Air Conditioning Available

Vehicle: Bike
Rent per day: 800 Tk
Total Rent: 2400.0 Tk
Feature: Helmet Available