1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Furkat [3]
3 years ago
11

Create a program that simulates a race between several vehicles. Design and implement an inheritance hierarchy that includes Veh

icle as an abstract superclass and several subclasses
Computers and Technology
1 answer:
Amanda [17]3 years ago
6 0

Answer:

Explanation:

The following program is written in Java. Since there was not much information provided in the question I created a Vehicle superclass with a couple of subclasses for the different types of vehicles (motorcycle, sedan, truck). Each one having its own unique attributes. The vehicle class also has an attribute for the position of the vehicle in the race.

class Vehicle {

   int year, wheels, position;

   public Vehicle(int year, int wheels, int position) {

       this.year = year;

       this.wheels = wheels;

       this.position = position;

   }

   public int getYear() {

       return year;

   }

   public void setYear(int year) {

       this.year = year;

   }

   public int getWheels() {

       return wheels;

   }

   public void setWheels(int wheels) {

       this.wheels = wheels;

   }

   public int getPosition() {

       return position;

   }

   public void setPosition(int position) {

       this.position = position;

   }

}

class Motorcycle extends Vehicle {

   String manufacturer;

   double speed;

   public Motorcycle(int year, int wheels, int position) {

       super(year, wheels, position);

   }

   public Motorcycle(int year, int wheels, int position, String manufacturer, double speed) {

       super(year, wheels, position);

       this.manufacturer = manufacturer;

       this.speed = speed;

   }

   public String getManufacturer() {

       return manufacturer;

   }

   public void setManufacturer(String manufacturer) {

       this.manufacturer = manufacturer;

   }

   public double getSpeed() {

       return speed;

   }

   public void setSpeed(double speed) {

       this.speed = speed;

   }

}

class Sedan extends Vehicle {

   int passengers;

   String manufacturer;

   double speed;

   public Sedan(int year, int wheels, int position) {

       super(year, wheels, position);

   }

   public Sedan(int year, int wheels, int position, int passengers, String manufacturer, double speed) {

       super(year, wheels, position);

       this.passengers = passengers;

       this.manufacturer = manufacturer;

       this.speed = speed;

   }

   public int getPassengers() {

       return passengers;

   }

   public void setPassengers(int passengers) {

       this.passengers = passengers;

   }

   public String getManufacturer() {

       return manufacturer;

   }

   public void setManufacturer(String manufacturer) {

       this.manufacturer = manufacturer;

   }

   public double getSpeed() {

       return speed;

   }

   public void setSpeed(double speed) {

       this.speed = speed;

   }

}

class Truck extends Vehicle {

   int passengers;

   String manufacturer;

   double speed;

   public Truck(int year, int wheels, int position) {

       super(year, wheels, position);

   }

   public Truck(int year, int wheels, int position, int passengers, String manufacturer, double speed) {

       super(year, wheels, position);

       this.passengers = passengers;

       this.manufacturer = manufacturer;

       this.speed = speed;

   }

   public int getPassengers() {

       return passengers;

   }

   public void setPassengers(int passengers) {

       this.passengers = passengers;

   }

   public String getManufacturer() {

       return manufacturer;

   }

   public void setManufacturer(String manufacturer) {

       this.manufacturer = manufacturer;

   }

   public double getSpeed() {

       return speed;

   }

   public void setSpeed(double speed) {

       this.speed = speed;

   }

}

You might be interested in
Given a Student class, create a class with following characteristics:
Kay [80]

Answer:

ssume that,

Maximum “students” count can be 10.

*Driver Class*

*Solution class*

import java.util.*;

class Student {

private String name;

private int rollNo;

public String getName() {}

public void setName(String name) {}

public int getRollNo() {}

public void setRollNo(int rollNo) {}

};

class ClassRoom {

private int i;

private Student[] students;

public void addStudent(String name, int rollNo) {}

public Student[] getAllStudents() {}

};

8 0
3 years ago
What is renewable energy
Marat540 [252]
Renewable energy is energy that is collected from renewable resources, which are naturally replenished on a human timescale, such as sunlight, wind, rain, tides, waves, and geothermal heat.
8 0
3 years ago
Asking yourself questions can help you think of what to _____, in order to get answers.
Olenka [21]
Ask your self questions can help you think of what to measure, in order to get answers.
8 0
3 years ago
Make a hierarchical directory structure under /root that consists of one directory containing three subdirectories.
Alika [10]
You can make a hierarchical directory structure under /root that consists of one directory containing subdirectories  by using cd and mkdir
the mkdir command created the directories while the cd command changes which directory you're currently in
5 0
2 years ago
Three reasons why users attach speakers to their computers.
ZanzabumX [31]

Answer:

Iv'e answered this question 2 times already lol. The purpose of speakers is to produce audio output that can be heard by the listener. Speakers are transducers that convert electromagnetic waves into sound waves. The speakers receive audio input from a device such as a computer or an audio receiver.

Explanation: I hope this helps!

8 0
3 years ago
Other questions:
  • What do you click to create a new presentation in Normal view? A. Section B. Blank Presentation C. Layout D. New Slide
    14·2 answers
  • What is the difference between HTML and CSS? * 1. CSS is a markup language unlike HTML. 2. HTML is a backend technology and CSS
    12·2 answers
  • Which of the following consists of electronic components that store instructions?
    10·1 answer
  • Why you should care about copyright
    13·1 answer
  • Which of the following commands would instruct OSPF to advertise ONLY the 192.168.10.0/24 network in Area 0?
    13·1 answer
  • A project manager type a document and print it he is using
    14·1 answer
  • Which of the following is a good precaution to take when making online purchases? (1 point)
    15·1 answer
  • What device provides ports to allow a laptop to easily connect to a full-sized monitor, keyboard, ac power adapter, and other pe
    11·1 answer
  • Write a function findWithinThreshold that identifies the elements of a given array that are inside a threshold value. Takes the
    13·1 answer
  • Consider that a man is watching a picture of a Black Horse. He receives an external stimulus from input channel. Man gains some
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!