ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2021 ICSE Computer Science Paper



Share with a Friend

Solved 2021 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Class & Object Based Program - Hotel Bill Calculation - ICSE 2021 Computer Science

Question 4
Design a class Hotel with the following description:

Member variables:
String name – to store the name of the customer
long mno – to store the mobile number of the customer
double bill – to store the bill amount
double gst – to store the GST amount
double st – to store the service tax
double tamt – to store the total amount to be paid by the customer

Member methods:
void accept() – to accept customer’s name, mobile number and bill amount.
void calculate() – to calculate GST, service tax and total amount to be paid by the customer.
gst = 18% on bill
st = 12.5% on bill
tamt = bill + gst + st

void display() – to display the customer’s name, mobile number, GST, service tax and total amount.
Write a main() method to create an object and invoke the above member methods.

import java.util.Scanner; class Hotel{ String name; long mno; double bill; double gst; double st; double tamt; public void accept(){ Scanner in = new Scanner(System.in); System.out.print("Customer name: "); name = in.nextLine(); System.out.print("Mobile number: "); mno = Long.parseLong(in.nextLine()); System.out.print("Bill: "); bill = Double.parseDouble(in.nextLine()); } public void calculate(){ gst = 18.0 / 100 * bill; st = 12.5 / 100 * bill; tamt = bill + gst + st; } public void display(){ System.out.println("Customer's name: " + name); System.out.println("Mobile number: " + mno); System.out.println("GST: " + gst); System.out.println("Service tax: " + st); System.out.println("Total amount: " + tamt); } public static void main(String[] args){ Hotel obj = new Hotel(); obj.accept(); obj.calculate(); obj.display(); } }

Output

 
 OUTPUT 1: 
Customer name: Anand Rao
Mobile number: 1234567890
Bill: 350
Customer's name: Anand Rao
Mobile number: 1234567890
GST: 63.0
Service tax: 43.75
Total amount: 456.75


 OUTPUT 2: 
Customer name: Ajay Sharma
Mobile number: 1234567890
Bill: 250
Customer's name: Ajay Sharma
Mobile number: 1234567890
GST: 45.0
Service tax: 31.25
Total amount: 326.25