Page 16 - KMK PREPSPM2 1819 ANSWER
P. 16
SULIT No. Matrik…………………………………….… No. Kad Pengenalan………………………….. SC015
(b) ParkRoyal Resort is a famous hotel located in Penang. The hotel provides
three (3) types of room. The table shows information for each type of room
with the deposit and rate per day.
Room Type Deposit (RM) Rental Rate per Day (RM)
Superior 100 300
Deluxe 500 700
Premier 900 1000
Based on the information given, write a complete Java program to calculate
the total payment, and balance payment after deposit paid. User needs to enter
the room type and number of day.
(Assume the guest only book one room.)
[4 marks]
import java.util.Scanner;
class ParkRoyalResort{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String rType;
int noDay;
double pay=0, bal=0;
rType=sc.next();
noDay=sc.nextInt();
if(rType.equals("Superior")){
pay = noDay * 300;
bal=pay-100;
}
else if(rType.equals("Deluxe")){
pay = noDay * 700;
bal=pay-500;
}
else if(rType.equals("Premier")){
pay = noDay * 1000;
bal=pay-900;
}
else
System.out.println("Invalid Room Type.");
System.out.println(pay);
System.out.println(bal);
}
}
END OF QUESTION PAPER
KERTAS SOALAN TAMAT
16 SULIT

