i need to a sub class for the boat rental but i am not sure how to do it i will give the code and it needs to inherit to the parent class can somw help out
cltc72 0 Newbie Poster
/*****************************************************************
*Steven M Johnston
*AutoRental Class
*Prof Ganson
*Project 3
*
******************************************************************/
public class AutoRental extends VehicleRental
{
/*************************************************************
*
*declare start and end mileage variables
*
*************************************************************/
private int start_mileage;
private int end_mileage;
/**************************************************************
*
*Default Constructor
*
*Description: initializes all of the private data members of the
*auto rental class to zero
*
*Input:No inputs
*
*Ouput:No outputs or returned values
*
**************************************************************/
public AutoRental()
{
super();
this.start_mileage=0;
this. end_mileage=0;
}
/***************************************************************
*
* Overloaded Constructor
*
*Description: The overloaded constructor have parameters that are
*used to set the values of the private data members to the values
*passed to the method.
*
*Input: The customer id number of the renter
*and the manufacture of the vechile
*
*Output: no output or returned values in this method
*
***************************************************************/
public AutoRental(String manufacture, int IdNum)
{
super(IdNum,manufacture);
this.start_mileage=0;
this.end_mileage=0;
}
/***************************************************************
*
*compute fee method
*
*Description: compute the fee for rented car/auto
*
*Input: NONE
*
*Output: computed fee is returned to the call method as a double
*
***************************************************************/
public double computeFee()
{
double cost,fee;
int excess_mileage;
int mileage = end_mileage - start_mileage;
if(mileage > 1000)
{
excess_mileage = mileage-1000;
cost = excess_mileage * .15;
fee = 300.00 + cost;
return fee;
}
else
{
fee = 300.00;
return fee;
}
}
/***************************************************************
*
*Return Vehicle method
*
*Description: Sets the rentout to false and sets the end mileage
*
*Input: The end mileage
*
*Output: None
*
***************************************************************/
public void returnVehicle(int end_mileage)
{
this. end_mileage= end_mileage;
rentOut=false;
}
/***************************************************************
*
*rent vehicle method
*
*Description: sets start mileage to teh end mileage and end mileage to 0
*
*Input: The ID Number
*
*Output: None
*
***************************************************************/
public void rentVehicle(int IdNum)
{
setIdNum(IdNum);
start_mileage = end_mileage;
end_mileage=0;
rentOut=true;
}
/***************************************************************
*
*to String method
*
*Description: Print Information
*
*Input: NONE
*
*Output: NONE
*
***************************************************************/
public String toString()
{
String s,t;
double u;
if(rentOut==true)
{
t="out";
s="Manufacture: "+getManufacture()+"\n"+ "Rented to Customer #:"+
getIdNum() +"\n"+ "Status:"+ t +"\n\n";
}
else
{
t="in";
u=computeFee();
s="Manufacture: "+getManufacture()+"\n"+ "Last rented to Customer #"+
getIdNum() +"\n"+ "Status:"+ t +"\n"+"Cost:"+u+"\n\n";
}
return s;
}
}
public class TestRental
{
public static void main(String [] args)
{
//create array that will hold any rentable object
VehicleRental[] vr=new VehicleRental[3];
//create 3 rented objects of Auto and Boat
VehicleRental fordRental= new AutoRental("Ford", 1001);
VehicleRental chevyRental= new AutoRental("Chevy", 1234);
VehicleRental sailRental= new BoatRental("Pearson", 5678);
//assign objects to arrey elements
//This can be done because of the casting when objects were created
vr[0]= fordRental;
vr[1]= chevyRental;
vr[2]= sailRental;
//Print elements of arrey
for (int i=0; i<vr.length; i++)
System.out.println(vr[i]);
System.out.println("**************");
//Customers return some of their rented vehicles
//note taht teh chevyrental(vr[1]) has not been returned, see sample run
vr[0].returnVehicle(1200);
vr[2].returnVehicle(5);
//Print elements of Arrey
for (int i=0; i<vr.length; i++)
System.out.println(vr[i]);
System.out.println("**************");
// allow new customers to rent vehicles
// supply method with new customerID
vr[0]. rentVehicle(9999);
for (int i=0; i<vr.length; i++)
System.out.println(vr[i]);
System.out.println("**************");
//Customers return more of their rented vehicles
// These are auto rentals,so must supply method with amount of miles on auto
vr[0].returnVehicle(3500);
vr[1].returnVehicle(850);
for (int i=0; i<vr.length; i++)
System.out.println(vr[i]);
System.out.println("**************");
}
}
/*****************************************************************
*Project: Rental Agency
*Date Due:
*Prof: J. Ganson
******************************************************************/
public abstract class VehicleRental
{
// declare variables
private String manufacture;
private int IdNum;
public boolean rentOut;
// Method that inisalize the variables
public VehicleRental()
{
this.manufacture="none";
this.IdNum=0;
this.rentOut= true;
}
// Method with Default Constructors
public VehicleRental(int IdNum, String manufacture)
{
this.manufacture=manufacture;
this.IdNum=IdNum;
this.rentOut= true;
}
//Method to get Manufature
public String getManufacture()
{
return manufacture;
}
//Method to get ID Number
public int getIdNum()
{
return IdNum;
}
// Method too set RentOut
public void setRentOut(boolean ans)
{
rentOut=ans;
}
//Method to set ID Number
public void setIdNum(int CusId)
{
this.IdNum=CusId;
}
//
public abstract double computeFee();
public abstract void returnVehicle(int chargeable);
public abstract void rentVehicle(int IdNum);
}
Narue 5,707 Bad Cop Team Colleague
I don't download attachments. If your code is relatively short, post it. Anyway, what are you having problems with? Do you know how to derive from a base class? You're not really giving us much to work with here.
cltc72 0 Newbie Poster
i am not to sure how to write a sub class to inherit it from the main class there are no viruses in the code i check it and recheck it if someone can look at it. thanks
Narue 5,707 Bad Cop Team Colleague
>i am not to sure how to write a sub class to inherit it from the main class
class base {
// Stuff
}
class derived extends base {
// Stuff
}
It's really very simple, but I'm sure your book (you do have one, right?) will explain the details far better than I could in a short post.
>there are no viruses in the code i check it and recheck it
I'm not as worried about that as I am lazy. Why should I work harder to help you? I have no vested interest in your success, so you should at least put some effort into helping me help you.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.