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
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...
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...
Goal:   Manage the inventory of objects sold in an online or brick and mortar store. If...
Goal:   Manage the inventory of objects sold in an online or brick and mortar store. If you can't implement all of the features of Project described in this document, implement what you can. Start by implementing the StockItem class, and its derived classes. Then add in the InventoryManager class later. In each case, the test files must be in separate classes. UML Diagram: Use Violet or other drawing software to draw the UML diagrams of each class that you use...
Create a class called Student. Include the following instance variables: name, address, phone, gpa Create all...
Create a class called Student. Include the following instance variables: name, address, phone, gpa Create all of the methods required for a standard user defined class: constructors, accessors, mutators, toString, equals Create the client for testing the Student class (5 points extra credit) Create another class called CourseSection (20 points extra credit) Include instance variables for: course name, days and times course meets (String), description of course, student a, student b, student c (all of type Student) Create all of...
Exercise 2 Write a class named Vehicle Holds make and model (strings) and year (int) Contains...
Exercise 2 Write a class named Vehicle Holds make and model (strings) and year (int) Contains this method: Vehicle(String make, String model, int year) { this.make = make; this.model = model; this.year = year; } Add getters and setters for each variable Write a class called FordMustang that extends the Vehicle class               Create instance of object               Pass variables               Print
4. Programming Problem: In this problem we will keep the Mechanism interface and the two classes...
4. Programming Problem: In this problem we will keep the Mechanism interface and the two classes Car and Computer from the previous problem. In addition, we will add a new class called Mechanic. We will also create a new TestMechanic class that will contain the main method. Create a class called Mechanic with following instance variable and constants: private int cost; public static int TEST_PRICE = 10; public static int REPAIR_PRICE = 50; Have a default constructor that will set...
Java Programming In this lab students continue to write programs using multiple classes. By the end...
Java Programming In this lab students continue to write programs using multiple classes. By the end of this lab, students should be able to Write classes that use arrays and ArrayLists of objects as instance variables Write methods that process arrays and ArrayLists of objects Write getter and setter methods for instance variables Write methods using object parameters and primitive types Question- class StringSet. A StringSet object is given a series of up to 10 String objects. It stores these...
The main goal is to implement two recursive methods, each is built to manipulate linked data...
The main goal is to implement two recursive methods, each is built to manipulate linked data structures. To host these methods you also have to define two utterly simplified node classes. 1.) Add a class named BinaryNode to the project. This class supports the linked representation of binary trees. However, for the BinaryNode class Generic implementation not needed, the nodes will store integer values The standard methods will not be needed in this exercise except the constructor 2.) Add a...
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName...
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName (a String), numSold (an integer that represents the number of that type of game sold), and priceEach (a double that is the price of each of that type of Game). I only want three instance variables!! The class should have the following methods: A constructor that has two parameter – a String containing the name of the Game and a double containing its price....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT