QuestionQuestion

You would submit 4 files, Vehicle.java, Car.java, Truck.java and FindPerimeter.java

Q1) In this question you will use the concepts of inheritance.

a) Write a class Vehicle.java that has the following states or global variables

private int number_of_wheels;

private String Make; //the make of the vehicle private String type; //the type of vehicle (car or truck) private int MPG; //mileage per gallon
Write a parameterized constructor for this class and a get method for all the states.

b) Write a class Car.java that extends Vehicle.java and has the following additional states (make sure you do not re-define the states or global variables that are already defined in Vehicle.java)
private boolean isConvertible; //whether the car is convertible or not

Write a parameterized constructor for this class (the constructor should also call the constructor of the Vehicle class using the super keyword) and a get method for the state (the parameterized constructor for this class would have a similar parameter list as that of Vehicle.java with an additional boolean parameter that initializes isConvertible )
Override the method getType() (you should have a getType() method in Vehicle.java) and within the body of the method simply return Make + “Car”; where you have to access the “Make” state of Vehicle using the getMake() method (don’t forget to use super).

c) Write a class Truck.java that extends Vehicle.java and has the following additional states (make sure you do not re-define the states or global variables that are already defined in Vehicle.java)

private boolean hasBackSeats; //whether the truck has back seats or not

Write a parameterized constructor for this class (the constructor should also call the constructor of the Vehicle class using the super keyword) and a get method for the state (the parameterized constructor for this class would have a similar parameter list as that of Vehicle.java with an additional boolean parameter that initializes hasBackSeats )
Override the method getType() (you should have a getType() method in Vehicle.java) and within the body of the method simply return Make + “Truck”; where you have to access the “Make” state of Vehicle using the getMake() method (don’t forget to use super).

Q2) Refer to FindArea class given in the notes. Your job is to design a similar class called FindPerimeter.java that calculates the perimeter of a square, a rectangle, a circle and a triangle. Your FindPerimeter.java should also have a main method that tests all your “perimeter” methods with dummy constant values (refer to the relevant main method given in the notes following the FindArea class)
Hint: Note each method has the same name. The parameters (not perimeters) are what differ. Consider how many sides you need to take in to find the perimeter of each shape.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

public class Car extends Vehicle {

    private boolean isConvertible; //whether the car is convertible or not

    /**
    * Write a parameterized constructor for this class (the constructor should
    * also call the constructor of the Vehicle class using the super keyword)
    * and a get method for the state (the parameterized constructor for this
    * class would have a similar parameter list as that of Vehicle.java with an
    * additional boolean parameter that initializes isConvertible )
    */
    public Car(boolean isConvertible, int number_of_wheels,
            String Make, String type, int MPG) {
       super(number_of_wheels, Make, type, MPG);
       this.isConvertible = isConvertible;
    }

    public boolean isConvertible() {
       return isConvertible;
    }

    /**
    * Override the method getType() (you should have a getType() method in
    * Vehicle.java) and within the body of the method simply return Make +
    * “Car”; where you have to access the “Make” state of Vehicle using the
    * getMake() method (don’t forget to use super).
    *
    * @return
    */

    @Override
    public String getType() {
       return super.getMake() + "Car";
    }
}...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$55.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats