Question

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 constructor that initializes all its data. Classes Car, Bus, and Truck will have constructors which will reuse their parents constructor and provide additional code for initializing their specific data.

Class Vehicle should have toString method that returns string representtion of all vehicle data. Classes Car, Bus, and Truck will override inherited toString method from class vehicle in order to provide appropriate string representation of all data for their classes which includes inherited data from Vehicle class and their own data.

Class Tester will instantiate 1-2 objects from those four classes (at least five total) and it will display the information about those objects by invoking their toString methods.

Submit one word document with code for all five classes, picture of program run from blueJ, and picture of UML diagram.

Homework Answers

Answer #1
  Vehicle.java
 * A class that represents a vehicle.  It is a superclass of all of the
 * other classes that represent vehicles (Automobile, Motorcycle, Truck, 
 * and their subclasses).
 *
 * Fields and methods that all vehicles have in common are defined
 * here so that they can be inherited by the subclasses of this class.
 */

public class Vehicle {
    private String make;
    private String model;
    private int year;
    private int numWheels;
    private int mileage;
    private String plateNumber;
     
    /**
     * a constructor that takes the make, model, year, and number of wheels
    */
    public Vehicle(String make, String model, int year, int numWheels) {
        this.make = make;
        this.model = model;
        if (year < 1900) {
            throw new IllegalArgumentException();
        }
        this.year = year;
        this.numWheels = numWheels;
        this.mileage = 0;
        this.plateNumber = "unknown";
    }

    /*** basic accessors ***/
    
    public String getMake() {
        return this.make;
    }
    
    public String getModel() {
        return this.model;
    }
    
    public int getYear() {
        return this.year;
    }
    
    public int getNumWheels() {
        return this.numWheels;
    }
    
    public int getMileage() {
        return this.mileage;
    }
    
    public String getPlateNumber() {
        return this.plateNumber;
    }

 
    /*** mutators ***/ 
       public void setMileage(int newMileage) {
        if (newMileage < this.mileage) {
            throw new IllegalArgumentException();
        }
        this.mileage = newMileage;
    }
 
    public void setPlateNumber(String plate) {
        this.plateNumber = plate;
    }
    
    public String toString() {
        String str = this.make + " " + this.model;
        return str;
    }
}
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
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...
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 QUIZ Question 1 Which of the following is false about a "super" call in a...
JAVA QUIZ Question 1 Which of the following is false about a "super" call in a sub class's constructor? Select one: a. It must be the first statement in the constructor b. If you don't include it Java will c. If you don't include it you must have a 0 parameter constructor coded in the super class or no constructors coded at all in the super class d. The sub class constructor containing the super call and the called super...
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...
in JAVA Write a class Store which includes the attributes: store name and sales tax rate....
in JAVA Write a class Store which includes the attributes: store name and sales tax rate. Write another class encapsulating a Yarn Store, which inherits from Store. A Yarn Store has the following additional attributes: how many skeins of yarn are sold every year and the average price per skein. Code the constructor, accessors, mutators, toString and equals method of the super class Store and the subclass Yarn Store; In the Yarn Store class, also code a method returning the...
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 a class Store which includes the attributes: store name and sales tax rate. Write another...
Write a class Store which includes the attributes: store name and sales tax rate. Write another class encapsulating a Book Store, which inherits from Store. A Book Store has the following additional attributes: how many books are sold every year and the average price per book. Code the constructor, accessors, mutators, toString and equals method of the super class Store and the subclass Book Store; In the Book Store class, also code a method returning the average taxes per year....
JAVA Learning Objectives: To be able to code a class structure with appropriate attributes and methods....
JAVA Learning Objectives: To be able to code a class structure with appropriate attributes and methods. To demonstrate the concept of inheritance. To be able to create different objects and use both default and overloaded constructors. Practice using encapsulation (setters and getters) and the toString method. Create a set of classes for various types of video content (TvShows, Movies, MiniSeries). Write a super or parent class that contains common attributes and subclasses with unique attributes for each class. Make sure...
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...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT