I have an abstract class Rental...I have two more subclasses,SuiteRental and SimpleRoomRental that inherits Rental class. I have an ArraList in a third class Hotel (not connected with the others) that contains both objects SimpleRoomRental and SuiteRental.
So,I want to examine each object (propably with instance_of) but i can't create a Rental object (cause its abstract class).What type should I declare my 'k' object?!?
any ideas?
public void calculateTotalRentalFees (){
double price=0;
for (int i=0; i<rentals.size(); i++){
if (k instanceof SimpleRoomRental){
SimpleRoomRental y= new SimpleRoomRental();
price=price + y.calculateCost();
}else if(k instanceof SuiteRental){
SuiteRental z=new SuiteRental();
price=price + z.calculateCost();
}
}
}
Also I have an interface that contains calculateCost() method.
public interface Cost {
public interface Costs {
double calculateCost();
}
}
thank you for your time