Java source code files must end with the. The Java source file name must match the public class name in the program.Return (super.toString() + "\n Depreciation\t:"+ depreciation +"\n Selling Price \t:"+ price()) Sell_price = super.price() - depreciation Public Sale(String vehnum,String make,String model, double p, double depval) Result += "\n\tDriver Cost: "+driver_cost+"\n\tFinal cost: "+final_cost Public void setDriverCost(double s_driver)ĭouble final_cost = driver_cost + super.price() Super(l_n,v_make,v_model,v_price,no_of_day, r_p_d) Public Bus(String l_n, String v_make, String v_model, double v_price, int no_of_day, double r_p_d, double dri_cost) Result += "\nRetal Info: "+"\n\tNumber of Days: "+number_of_days_for_rental+"\n\tRate per day: "+rate_per_day+"\n\tTotal: "+price() Return number_of_days_for_rental*rate_per_day Public Rental(String l_n, String v_make, String v_model, double v_price, int no_of_day, double r_p_d) Result = "License # : "+ license_number+ "\nVehicle Name : "+getVehicleName()+"\nPrice : "+price Public Vehicle(String l_n, String v_make, String v_model, double v_price)
Modify your code to use the setDriverCost method to set the cost for driver for the element at position 2 to $15,000. Modify your code to use the setDepreciation method to set the depreciation value for the element at position 0 using the rate 20%.ģ. Write a driver class with a main method which creates an array with the data from the following table and displays the array contents.Ģ. Override the price method in each subclass so that price is calculated correctly for each type of vehicle.ġ. A method named setDriverCost which accepts the driver’s cost and sets this value on the object. A constructor that a vehicle’s number, a make, a model, price, number of days for rental, the rate per day and driver cost. Declarations of all attributes that a rental bus has which are not already declared in the parent class. Write the class Bus to represent a bus on rental. The rental price of the vehicle is calculated as number of days times the rate. A constructor that accepts a vehicle’s number, a make, a model, price, number of days for rental and the rate per day. Declarations of all attributes that a rental vehicle has which are not already declared in the parent class.
This class is also a subclass of the Vehicle class. Write the class Rental to represent a vehicle to be rented.
A toString method that formats its returned value in the following manner: A method called setDepreciation that accepts the percentage rate, calculates the depreciation value (which is rate * price of vehicle) and set this attribute on the object. A constructor that accepts (as parameters) a vehicle’s number, a make, a model, price and depreciation value (in that order). Declarations of all attributes that vehicle on sale has which are not already declared in the parent class. Write the class Sale as a subclass of Vehicle. A toString method which returns a string in the following format: A method named price that returns the price of the vehicle.
An accessor method named getVehicleName that returns the vehicle’s name in the form make, model (e.g. A constructor that gets (as parameters) a vehicle’s number, a make, a model and price (in that order).
These will be those attributes that all vehicles have. Declarations for all attributes that belong in this class. Write the class Vehicle to represent a motor vehicle.
It rents two types of vehicles – Bus and Car.Įvery vehicle has a license number, a make, a model and price. COMP1161 Motors both sells and rents vehicles.