Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- Product tab[]=new Product[6];
- Vehicle first=new Vehicle(100000,"suzuki","vitara");
- Vehicle second=new Vehicle(25000,"mercedes","w123");
- Car third=new Car(300,"fiat","ducato","dostawczy");
- Car fourth=new Car(300,"daewoo","nubira","sedan");
- Motorcycle fifth=new Motorcycle(203,"kawasaki","ninja","m");
- Motorcycle sixth=new Motorcycle(200, "suzuki", "burgman", "m");
- tab[0]=first; tab[1]=second; tab[2]=third; tab[3]=fourth; tab[4]=fifth; tab[5]=sixth;
- Vehicle tmp;
- for(int i=2;i<6;i++){
- tmp=(Vehicle)tab[i];
- System.out.println(tmp.getBrand()+" "+tmp.getModel()+" "+tmp.getPrice()+" "+tmp.calculateBargainPrice());
- }
- }
- }
- //1.
- class Product {
- double price;
- public Product(double price){
- this.price=price;
- }
- public double calculateBargainPrice(){
- return price;
- };
- public double getPrice(){
- return price;
- }
- }
- //2.
- class Vehicle extends Product{
- String brand;
- String model;
- public Vehicle(double price,String brand,String model){
- super(price);
- this.brand=brand;
- this.model=model;
- }
- public double calculateBargainPrice(){
- return this.getPrice()*0.95;
- }
- public String getBrand(){
- return brand;
- }
- public String getModel(){
- return model;
- }
- public void setModel(String model){
- this.model=model;
- }
- public void setBrand(String brand){
- this.brand=brand;
- }
- }
- //3.
- class Car extends Vehicle{
- String carBody;
- public Car(double price, String brand, String model,String carBody){
- super(price, brand, model);
- this.carBody=carBody;
- }
- public double calculateBargainPrice(){
- return this.getPrice()*0.85;
- }
- public String getCarBody(){
- return carBody;
- }
- public void setCarBody(String carBody){
- this.carBody=carBody;
- }
- }
- //4.
- class Motorcycle extends Vehicle{
- private String typeOfDrive;
- public Motorcycle(double price, String brand, String model, String typeOfDrive){
- super(price, brand, model);
- this.typeOfDrive=typeOfDrive;
- }
- public double calculateBargainPrice(){
- return this.getPrice()*0.9;
- }
- public String getTypeOfDrive(){
- return typeOfDrive;
- }
- public void settypeofDrive(String typeOfDrive){
- this.typeOfDrive=typeOfDrive;
- }
- //5.
- class Product {
- double price;
- public Product(double price){
- this.price=price;
- }
- public double calculateBargainPrice(){
- return price;
- }
- public double getPrice(){
- return price;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement