I had a programme to write for college in Java. I have missed the class so I won't be getting marked on it but wanted to get it done as I have an exam next we. I am really stuck.
I have to create a costInsurance () method taking in the surcharges for 3 conditions yearBuilt, numberOfRooms and hasASpa.
I gave a shot at the ageSurcharge but have no idea if this is right or not?
public class Hotel{
private String name;
private String address;
private int yearBuilt;
private int numberOfRooms;
private boolean hasASpa;
public Hotel(String nameIn, String addressIn, int yearBuiltIn,int numberOfRoomsIn, boolean hasASpaIn){
this.name= nameIn;
this.address=addressIn;
this.yearBuilt = yearBuiltIn;
if(yearBuiltIn < 0)
yearBuilt =0;
numberOfRooms = numberOfRoomsIn;
if(numberOfRoomsIn <0)
numberOfRooms =0;
hasASpa= hasASpaIn;
}
public Hotel(){
String name ="";
String address="";
int yearBuilt= 0;
int numberOfRooms=0;
boolean hasASpa= false;
}
public void print(){
System.out.println("Hotel name is : " + name);
System.out.println("Hotel address is : " + address);
System.out.println("Hotel was built in :" + yearBuilt);
System.out.println("This hotel has a spa : " + hasASpa);
}
public int costInsurance( int ageSurcharge,int yearBuiltIn)
{
if((yearBuiltIn >1920) || (yearBuiltIn <1950)){
ageSurcharge = 1000;
System.out.println("Surcharge payable is :"+ ageSurcharge);
}else if((yearBuiltIn>1951) || (yearBuiltIn >1999)){
ageSurcharge =750;
System.out.println("Surcharge payable is : " + ageSurcharge);
}
else {
if ((yearBuiltIn>2000) || (yearBuiltIn <=2014));
ageSurcharge=500;
System.out.println("Surcharge payable is: " + ageSurcharge);
}
}
}