3
Define a class with following specifications.
class name: Hotel
Member variables:
String name – stores name of customer name
long mobno – stores mobile number
int days – stores number of days customer stayed in hotel
int bill – stores customer bill
Member method:
void input() – input values using Scanner class methods only
void charge() – calculate bill as per the following criteria
| days | charge/day |
|---|---|
| first 3 days | 1000 Rs/ day |
| next 4 days | 900 Rs/day |
| > 7 days | 800 Rs/day |
bill = bill + gst (18% of bill)
void print() - Display customer name, mobile number and bill.
Invoke all the above methods in main method with the help of an object.
Show SolutionHide Solution↓
import java.util.Scanner;
class Hotel {
String name;
long mobno;
int days;
int bill;
void input() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter customer name: ");
name = sc.nextLine();
System.out.print("Enter mobile number: ");
mobno = sc.nextLong();
System.out.print("Enter number of days stayed: ");
days = sc.nextInt();
}
void charge() {
if (days <= 3) {
bill = days * 1000;
} else if (days <= 7) {
bill = (3 * 1000) + (days - 3) * 900;
} else {
bill = (3 * 1000) + (4 * 900) + (days - 7) * 800;
}
bill += bill * 0.18;
}
void print() {
System.out.println("Customer Name : " + name);
System.out.println("Mobile Number : " + mobno);
System.out.println("Total Bill : Rs " + bill);
}
public static void main(String[] args) {
Hotel h = new Hotel();
h.input();
h.charge();
h.print();
}
}
