ahamed210

Vehicle_system

Nov 28th, 2021
795
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. package vehicleinfo;
  3. import CarInfo.Car;
  4. import BikeInfo.Bike;
  5. import Common.Engines;
  6. public class Main {
  7.     public static void main(String[] args) {
  8.         Engines injin = new Engines(150, 38.5);
  9.         Bike bike = new Bike("Yamaha", "FZ-S", "Lite_Green", "ABS", injin);
  10.         bike.show();
  11.         bike.showSpeed();
  12.         bike.accelarate(10);
  13.         bike.showSpeed();
  14.         bike.maxaccelarate();
  15.         bike.showSpeed();
  16. //        bike.accelarate(20);
  17. //        bike.showSpeed();
  18.         bike.breaking(20);
  19.         bike.showSpeed();
  20.         bike.breaking();
  21.         bike.showSpeed();
  22.        
  23.         Car c = new Car("Tesla", "Electric", "White", 1, 2, injin);
  24.         c.show();
  25.     }
  26. }
  27.  
  28.  
  29. package Common;
  30.  
  31. public class Vehicle {
  32.     protected String company, model, color;
  33.     protected double speed = 0;
  34.     protected Engines engine;
  35.     public Vehicle(String company, String model, String color, Engines engine){
  36.         this.color = color;
  37.         this.company = company;
  38.         this.model = model;
  39.         this.engine = engine;
  40.         //this.speed = speed;
  41.     }
  42.    
  43.     public void show1(){
  44.         System.out.println("\nCompany : " + company + "\nModel : " + model + "\nColor : " + color + "\n");
  45.         engine.print();
  46.     }
  47.    
  48.     public void accelarate(int rate){
  49.         if(speed == 0) speed = 10;
  50.         //if(speed < maxSpeed)
  51.         speed += ((speed*rate)/100.0);
  52.     }
  53.    
  54.     public void breaking(int rate){
  55.         if(speed <= 0) speed = 0;
  56.         else speed -= ((speed*rate)/100.0);
  57.     }
  58.    
  59.     public void breaking(){
  60.         speed = 0;
  61.     }
  62. }
  63.  
  64.  
  65.  
  66. package Common;
  67. public class Engines {
  68.     private int cc;
  69.     private double milage;
  70. //    public void setMilage(double milage){
  71. //        this.milage = milage;
  72. //    }
  73. //    public void setCC(int cc){
  74. //        this.cc = cc;            
  75. //    }
  76. //    public int getNumberCC(){
  77. //        return cc;
  78. //    }
  79. //    public double getmilage(){
  80. //        return milage;
  81. //    }
  82.    
  83.     public Engines(int cc, double milage){
  84.         this.cc = cc;
  85.         this.milage = milage;
  86.     }
  87.    
  88.     public void print(){
  89.         System.out.println("Milage and CC : " + milage + " " + cc);
  90.     }
  91. }
  92.  
  93.  
  94. package CarInfo;
  95.  
  96. import Common.Engines;
  97. import Common.Vehicle;
  98.  
  99. public class Car extends Vehicle{
  100.     private int num_of_seat = 0, num_of_door = 0;
  101.     final protected double maxSpeed = 180.0;
  102.     //private Engines engine;
  103.     //Engines engine = new Engines();
  104.     public Car(String company, String model, String color, int num_of_seat, int num_of_door, Engines engine){
  105.         super(company, model, color, engine);
  106.         this.num_of_door = num_of_door;
  107.         this.num_of_seat = num_of_seat;
  108. //        engine.setCC(cc);
  109. //        engine.setMilage(milage);
  110.     }
  111.    
  112.     public void show(){
  113.         show1();
  114.         System.out.println("Number of Door : "  + num_of_door + "\nNumber of seats : "  + num_of_seat + "\n");
  115.         //engine.print();
  116.     }
  117.    
  118.     public void maxaccelarate(){
  119.         speed = maxSpeed;
  120.     }
  121.    
  122.     public void showSpeed(){
  123.         System.out.println("Current Speed : " + speed);
  124.     }
  125. }
  126.  
  127.  
  128. package BikeInfo;
  129. import Common.Engines;
  130. import Common.Vehicle;
  131. public class Bike extends Vehicle{
  132.     private String break_type = "";
  133.     //private Engines engine;
  134.     final protected double maxSpeed = 180.0;
  135.     //Engines engine = new Engines();
  136.     public Bike(String company, String model, String color, String break_type, Engines engine){
  137.         super(company, model, color, engine);
  138.         this.break_type = break_type;
  139. //        engine.setCC(cc);
  140. //        engine.setMilage(milage);
  141.     }
  142.    
  143.     public void show(){
  144.         show1();
  145.         System.out.println("Break type : "  + break_type + "\n");
  146.         //engine.print();
  147.     }
  148.    
  149.     public void maxaccelarate(){
  150.         speed = maxSpeed;
  151.     }
  152.    
  153.     public void showSpeed(){
  154.         System.out.println("Current Speed : " + speed);
  155.     }
  156. }
  157.  
RAW Paste Data