diff --git a/src/Main.java b/src/Main.java index 50acee4ecf052554ffa768ad8ea85ae07fa0c852..e76e98712ad524235d8443790ff6873334a9081c 100644 --- a/src/Main.java +++ b/src/Main.java @@ -18,35 +18,42 @@ public class Main { // mahboobeCar.printDetails(); mahboobeCar.setPrice(40000); // mahboobeCar.printDetails(); - try { - mahboobeCar.setPrice(-10); - }catch (Exception e) { - System.out.println(e.getMessage()); - } - mahboobeCar.printDetails(); - try { - Car testCar = new Car("Toyota", "LR4", 2024, -50000); - testCar.printDetails(); - } catch (Exception e) { - System.out.println(e.getMessage()); - } - - Car carWithoutYear = new Car("Toyota", "LR4", 50000.0); - carWithoutYear.printDetails(); - Car test1 = new Car("Toyota", "LR4", 2024); - test1.printDetails(); - Car test2 = new Car("Tesla", "LR4"); - test2.printDetails(); - - ArrayList<Car> carList = new ArrayList<>(); - carList.add(mahboobeCar); - carList.add(test1); - carList.add(test2); - carList.add(new Car("Toyota", "list", 2024)); - - for (Car car : carList) { - car.printDetails(); - } +// try { +// mahboobeCar.setPrice(-10); +// }catch (Exception e) { +// System.out.println(e.getMessage()); +// } +// mahboobeCar.printDetails(); +// try { +// Car testCar = new Car("Toyota", "LR4", 2024, -50000); +// testCar.printDetails(); +// } catch (Exception e) { +// System.out.println(e.getMessage()); +// } + +// Car carWithoutYear = new Car("Toyota", "LR4", 50000.0); +// carWithoutYear.printDetails(); +// Car test1 = new Car("Toyota", "LR4", 2024); +// test1.printDetails(); +// Car test2 = new Car("Tesla", "LR4"); +// test2.printDetails(); +// +// ArrayList<Car> carList = new ArrayList<>(); +// carList.add(mahboobeCar); +// carList.add(test1); +// carList.add(test2); +// carList.add(new Car("Toyota", "list", 2024)); +// +// for (Car car : carList) { +// car.printDetails(); +// } + + SportCar sport_car1 = new SportCar("ferarri", "rx4", 2018, 100000, 50000, false); + sport_car1.printDetails(); + sport_car1.setPrice(400000); + sport_car1.printDetails(); + sport_car1.setHorsePower(6000); + sport_car1.printDetails(); // Exception Examples diff --git a/src/SportCar.java b/src/SportCar.java new file mode 100644 index 0000000000000000000000000000000000000000..3924049c75ede6a712fc92283a10424a69f7ce2e --- /dev/null +++ b/src/SportCar.java @@ -0,0 +1,30 @@ +public class SportCar extends Car { + private int horsePower; + private boolean turbo; + + public SportCar(String brand, String model, int year, double price, int horsePower, boolean turbo) { + super(brand,model, year, price); + this.horsePower = horsePower; + this.turbo = turbo; + } + + public int getHoursPower() { + return horsePower; + } + public void setHorsePower(int horsePower) { + this.horsePower = horsePower; + } + public boolean isTurbo() { + return turbo; + } + public void setTurbo(boolean turbo) { + this.turbo = turbo; + } + + @Override + public void printDetails() { + super.printDetails(); + System.out.println("Horsepower: " + horsePower + " Turbo mode: " + turbo); + } + +}