Question

1- Use inheritance to implement the following classes: A: A Car that is a Vehicle and...

1- Use inheritance to implement the following classes:
A: A Car that is a Vehicle and has a name, a max_speed value and an instance variable called the

number_of_cylinders in its engine. Add public methods to set and get the values of these variables. When a car is printed (using the toString method), its name, max_speed and number_of_cylinders are shown.
B: An Airplane that is also a vehicle and has a name, a max_speed value and an instance variable called the number_of_engines it has. Add public methods to set and get the values of these variables. When an airplane is printed (using the toString method), its name, max_speed and number_of_engines are shown.

C: Write a VehicleDemo.java class that does the following:

1- Creates an instance of a Car and an Airplane class.

2- Assign values to the name, speed, number_of_cylinders (for the Car object) and

number_of_engines (for the Airplane object) variables.

3- Compares which vehicle goes faster and prints the result.

4- Prints the instances of the car and airplane classes.

NEXT

2- Add the following changes to the above problem:
A: Make the Vehicle an abstract class and add the following abstract method to it:

double runningCost(int hour); Which receives the hours of operation as a parameter and returns the running cost of the vehicle. The Car and Airplane classes will implement this method as follows:

1- For the Car class, define a private double constant called

COST_PER_CYLINDER_PER_HOUR = 10.5. The runningCost of a Car will be equal to:

hours * COST_PER_CYLINDER_PER_HOUR * number_of_cylinders

2- For the Airplane class, define a private double constant called

COST_PER_ENGINE_PER_HOUR = 25.3. The runningCost of an Airplane will be equal to:

hours * COST_PER_ ENGINE _PER_HOUR * number_of_engines

B: Write an interface called maintainable, which has the following method:

double maintenanceCost(double costPerUnit); It receives the cost per unit of an engine or cylinder and returns the maintenance cost. The Car and Airplane classes will implement this interface as follows:
1- For the Car class, the maintenance cost of a Car will be equal to:

costPerUnit * number_of_cylinders

2- For the Airplane class, the maintenance cost of an Airplane will be equal to: costPerUnit * number_of_engines

C: Add a String toString() method to the Vehicle class. When a Vehicle is printed, its name and max_speed are shown. Also, the String toString() methods of the Car and Airplane classes will show the following:

1- When a car is printed, its name, max_speed, number_of_cylinders and

COST_PER_CYLINDER_PER_HOUR are shown.

2- When an airplane is printed, its name, max_speed, number_of_engines and COST_PER_

ENGINE _PER_HOUR are shown.

D: Write a VehicleDemo.java class that does the following:

1- Creates an instance of a Car and an instance of an Airplane class.

2- Assigns values to the name, max_speed and number_of_cylinders instance variables of the

Car object and the name, max_speed and number_of_engines instance variables of the

Airplane object.

3- Calls all the methods of the Car and Airplane objects that return the values of their instance

variables and prints the results.

4- Calls the runningCost(5) of the Car and Airplane objects and prints the result.

5- Calls the maintenanceCost (30.0) of the Car and maintenanceCost (250.0) of the Airplane

objects and prints the result.

6- Defines a reference variable of type Vehicle and assigns it to an instance of a Car class.

Example: Vehicle v1 = new Car(...);

7- Prints v1. Notice whether the toString() method of the Vehicle class is called or the toString()

method of the Car class. Explain why it has been the case. In Object Oriented paradigm, what is this called?

Homework Answers

Answer #1

Legacy is a programming build that product designers use to set up is-a connections between classifications. Legacy empowers us to get more-particular classes from more-nonexclusive ones. The more-particular class is a sort of the more-non specific classification. For instance, a financial records is a sort of record in which you can make stores and withdrawals. Additionally, a truck is a sort of vehicle utilized for pulling extensive things.

Legacy can dive through various levels, prompting to perpetually particular classifications. For instance, Figure 1 demonstrates auto and truck acquiring from vehicle; station wagon acquiring from auto; and dump truck acquiring from truck. Bolts point from more-particular "tyke" classes (let down) to less-particular "parent" classifications

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
IN JAVA Inheritance Using super in the constructor Using super in the method Method overriding Write...
IN JAVA Inheritance Using super in the constructor Using super in the method Method overriding Write an application with five classes Vehicle, Car, Bus, Truck, and Tester class with main method in it. The following characteristics should be used: make, weight, height, length, maxSpeed, numberDoors, maxPassenges, isConvertable, numberSeats, maxWeightLoad, and numberAxels. Characteristics that are applicable to all vehicles should be instance variables in the Vehicle class. The others should be in the class(s) where they belong. Class vehicle should have...
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance:...
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance: ⦁   A base class called Pet ⦁   A mix-in class called Jumper ⦁   A Dog class and a Cat class that each inherit from Pet and jumper ⦁   Two classes that inherit from Dog: BigDog and SmallDog ⦁   One classes that inherit from Cat: HouseCat The general skeleton of the Pet, Dog, and BigDog classes will be given to you (see below, "Skeleton", but...
Java For this assignment you need to create at least 5 classes. 1.Create a vehicle class...
Java For this assignment you need to create at least 5 classes. 1.Create a vehicle class ( super class) 2,3. Create two sub classes ( car, bus , truck train or any) for vehicle class 4 Create a subclass (sportscar or schoolbus or Goodstrain or any) for car or bus You need to use the following atleast for one class. Use a protected variable Add constructor for superclass and subclass Override a method which displays a description about the vehicle...
The following is for a Java Program Create UML Class Diagram for these 4 java classes....
The following is for a Java Program Create UML Class Diagram for these 4 java classes. The diagram should include: 1) All instance variables, including type and access specifier (+, -); 2) All methods, including parameter list, return type and access specifier (+, -); 3) Include Generalization and Aggregation where appropriate. Java Classes description: 1. User Class 1.1 Subclass of Account class. 1.2 Instance variables __ 1.2.1 username – String __ 1.2.2 fullName – String __ 1.2.3 deptCode – int...
Write the program in java Implement a class Product. Create instance variables to store product name...
Write the program in java Implement a class Product. Create instance variables to store product name and price and supply the values through constructor. For example new Product(“Toaster’, 29.95). Create methods, getName, getPrice. Write a method productPrinter that prints the product name and its price after reducing it by $5. Create a main class and necessary constructs in the main class to run the Product class.
Choose any entity of your choice to represent a superclass. It must not be any of...
Choose any entity of your choice to represent a superclass. It must not be any of the following: - Human, Student, Vehicle, Person, Car, Animal, Book • Create a class for your entity with the following: - 3 instance variables - 3 instance methods - 2 of the instance methods must show overloading - A default constructor - A parameterized constructor that initializes all instance variables - Getters and setters for the instance variables - Method to print all the...
We encourage you to work in pairs for this challenge to create a Student class with...
We encourage you to work in pairs for this challenge to create a Student class with constructors. First, brainstorm in pairs to do the Object-Oriented Design for a Student class. What data should we store about Students? Come up with at least 4 different instance variables. What are the data types for the instance variables? Write a Student class below that has your 4 instance variables and write at least 3 different constructors: one that has no parameters and initializes...
Modify the Employee9C superclass so that is an abstract superclass with a constructor to set its...
Modify the Employee9C superclass so that is an abstract superclass with a constructor to set its variables (firstName and lastName). It should contain an abstract method called payPrint. Below is the source code for the Employee9C superclass: public class Employee9C {    //declaring instance variables private String firstName; private String lastName; //declaring & initializing static int variable to keep running total of the number of paychecks calculated static int counter = 0;    //constructor to set instance variables public Employee9C(String...
Java Programming COMP-228 LAB ASSIGNMENT #1 >> Apply the naming conventions for variables, methods, classes, and...
Java Programming COMP-228 LAB ASSIGNMENT #1 >> Apply the naming conventions for variables, methods, classes, and packages: - variable names start with a lowercase character for the first word and uppercase for every other word - classes start with an uppercase character of every word - packages use only lowercase characters - methods start with a lowercase character for the first word and uppercase for every other word Java Programming COMP-228 Exercise #1: [5 marks] Write a Java application using...
1. Circle: Implement a Java class with the name Circle. It should be in the package...
1. Circle: Implement a Java class with the name Circle. It should be in the package edu.gcccd.csis. The class has two private instance variables: radius (of the type double) and color (of the type String). The class also has a private static variable: numOfCircles (of the type long) which at all times will keep track of the number of Circle objects that were instantiated. Construction: A constructor that constructs a circle with the given color and sets the radius to...