Computer Applications
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.
Java
Java Classes
10 Likes
Answer
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();
}
}Output

Answered By
6 Likes
Related Questions
Consider the following array and answer the questions given below:
char ch [ ] = { ‘A’, ‘%’, ‘y’, ‘@’, ‘7’, ‘p’};(a) How many bytes does the array occupy?
(b) What is the output of the statement Character.isDigit(ch[4])?
class perform { int m; String name; perform(int x, String y) { m=x; name=y; } void print() { System.out.print(name + " " + m); } public static void main() { perform ob1=new perform(95 , "Xavier"); ob1.print(); } }(a) Give the output of the code given above.
(b) Name the type of the constructor used.
Define a class to accept values into a 3x3 integer array and print the product of each row elements.
Example:
3 1 2 4 2 1 5 1 2 Output:
Row 0 – 6
Row 1 – 8
Row 2 – 10Define a class to overload the method transform as follows:
int transform(int n) – to return the sum of the digits of the given number
Example: n = 458
output : 17void transform(String s) – to convert the given String to upper case and print
Example: if S = “Blue”
Output : BLUEvoid transform (char ch) – to print the character ch in 3 rows and 3 columns using nested loops.
Example: if ch = ‘@’
Output :@@@ @@@ @@@