Computer Science, asked by Anonymous, 3 months ago

We want to store the information of different vehicles. Create a class named Vehicle with two data member named mileage and price. Create its two subclasses
*Car with data members to store ownership cost, warranty (by years), seating capacity and fuel type (diesel or petrol).
*Bike with data members to store the number of cylinders, number of gears, cooling type (air, liquid or oil), wheel type (alloys or spokes) and fuel tank size(in inches)
Make another two subclasses Audi and Ford of Car, each having a data member to store the model type. Next, make two subclasses Bajaj and TVS, each having a data member to store the make-type.
Now, store and print the information of an Audi and a Ford car (i.e. model type, ownership cost, warranty, seating capacity, fuel type, mileage and price.) Do the same for a Bajaj and a TVS bike.

Answers

Answered by coolistictrailer
1

Answer:

import java.util.*;

class Vehicle{

Scanner s=new Scanner(System.in);

int mileage = s.nextInt();

int price = s.nextInt();

}

class Car extends Vehicle{

 

int ownershipcost=s.nextInt();

int warranty=s.nextInt();

int seating_capacity=s.nextInt();

String fueltype=s.next();

}

class Bike extends Vehicle{

 

int cyclinders=s.nextInt();

String coolingtype=s.next();

int gears=s.nextInt();

String wheeltype=s.next();

int tanksize=s.nextInt();

}

class Audi extends Car{

String model=s.next();

void display(){

  System.out.println("model type is "+model);

  System.out.println("ownersip cost is "+ownershipcost);

  System.out.println("warranty is "+warranty);

  System.out.println("seating capacity is "+seating_capacity);

  System.out.println("fuel type is "+fueltype);

  System.out.println("mileage is "+mileage);

  System.out.println("price is "+price);

}

}

class Ford extends Car{

String model=s.next();

void display(){

  System.out.println("model type is "+model);

  System.out.println("ownersip cost is "+ownershipcost);

  System.out.println("warranty is "+warranty);

  System.out.println("seating capacity is "+seating_capacity);

  System.out.println("fuel type is "+fueltype);

  System.out.println("mileage is "+mileage);

  System.out.println("price is "+price);

}

}

class Bajaj extends Bike{

String type=s.next();

void display(){

System.out.println("Type is "+type);

 System.out.println("mileage is "+mileage);

  System.out.println("price is "+price);

  System.out.println("no. of cyclinders "+cyclinders);

  System.out.println("no. of gears "+gears);

  System.out.println("cooling type is"+coolingtype);

  System.out.println("wheel type"+wheeltype);

  System.out.println("tank size "+tanksize);

}

}

class TVS extends Bike{

String type=s.next();

void display(){

System.out.println("Type is "+type);

 System.out.println("mileage is "+mileage);

  System.out.println("price is "+price);

  System.out.println("no. of cyclinders "+cyclinders);

  System.out.println("no. of gears "+gears);

  System.out.println("cooling type is"+coolingtype);

  System.out.println("wheel type"+wheeltype);

  System.out.println("tank size "+tanksize);

}

}

public class Main{

public static void main(String args[]){

 Ford f=new Ford();

 Audi a=new Audi();

 Bajaj b=new Bajaj();

 TVS t=new TVS();

 f.display();

 a.display();

 b.display();

 t.display();

}

}

Explanation:

full script

hope this helps you

Answered by jiosuhail66
0

Answer:

Create two classes named Mammals and MarineAnimals. Create another class named BlueWhale which inherits both the above classes. Now, create a function in each of these classes which prints "I am mammal", "I am a marine animal" and "I belong to both the categories: Mammals as well as Marine Animals" respectively. Now, create an object for each of the above class and try calling

1 - function of Mammals by the object of Mammal

2 - function of MarineAnimal by the object of MarineAnimal

3 - function of BlueWhale by the object of BlueWhale

4 - function of each of its parent by the object of BlueWhale

Explanation:

Similar questions