23CSR306 JAVA PROGRAMMING
Assignment
TITLE:HOTEL BILL GENERATION
Submitted by
717823L121(HARISH R)
Department of Electronics and communication
KARPAGAM COLLEGE OF ENGINEERING
(Autonomous)
Myleripalayam Village, Othakkal Mandapam Post,
Coimbatore - 641032, Tamilnadu, India
OCTOBER– 2024
DEPARTMENT OF ELECTRONICS AND COMMUNICATION
VISION
To provide reliable and modern technology resources to the faculty and students to develop the
competence in Information Technology and to endure with the rapidly changing world to serve
the mankind.
MISSION
Imparting technical knowledge through innovative teaching and research for budding
professionals.
To equip the students with strong fundamentals, programming and problem solving skills
with an exposure to emerging technologies and inculcate leadership qualities with a
passion to serve society.
Programme Educational Objectives (PEOs)
PEO1:Graduates will be able to comprehend mathematics, science, engineering
fundamentals, laboratory and work-based experiences to formulate and solve problems in
the domain of Information Technology and acquire proficiency in Computer-based
engineering and the use of computational tools..
PEO2:Graduates will be prepared to communicate and work effectively on
multidisciplinary engineering projects and practicing the ethics of their profession.
PEO3:Graduates will realize the importance of self-learning and engage in lifelong
learning to become experts either as entrepreneurs or employees in the field to widen the
professional knowledge.
Program Outcomes
PO1: Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering problems.
PO2: Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics,
natural sciences, and engineering sciences.
PO3: Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
Page 1 of 12
PO4: Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.
PO5: Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities
with an understanding of the limitations.
PO6: The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
professional engineering practice.
PO7: Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need for
sustainable development.
PO8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
PO9: Individual and team work: Function effectively as an individual, and as a member or leader
in diverse teams, and in multidisciplinary settings.
PO10: Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive
clear instructions.
PO11: Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
PO12: Life-long learning: Recognize the need for, and have the preparation and ability to engage
in independent and life-long learning in the broadest context of technological change.
Program Specific Outcomes (PSO)
After successful completion of the program, graduates of B.E (CSE) will:
PSO-1 Ability to organize an IT infrastructure, secure the data and analyze the data analytic
techniques in the field of data mining, big data as to facilitate in solving problems.
PSO-2 Ability to analyze and design the system in the domain of Cloud and Internet of Things.
Page 2 of 12
<this page should be blank and landscape mode for pasting rubrics>
Page 3 of 12
Project Objective
Create a console based Java application that would allow the manager of
a hotel to calculate the total bill amount of the customer for the room booked.
Project Design
System Design:
Implementation
import java.text.SimpleDateFormat;
import java.util.Date;
class InvalidDataException extends Exception {
@Override
public String toString() {
return "Invalid Data";
}
}
class InvalidRoomTypeException extends Exception {
@Override
public String toString() {
return "Invalid Room Type";
}
Page 4 of 12
}
class Customer {
private String customerId;
private Date bookingDate;
private Date departureDate;
private String roomType;
private double billAmount;
public Customer(String customerId, Date bookingDate, Date
departureDate, String roomType) {
this.customerId = customerId;
this.bookingDate = bookingDate;
this.departureDate = departureDate;
this.roomType = roomType;
}
public String getCustomerId() {
return customerId;
}
public void setCustomerId(String customerId) {
this.customerId = customerId;
}
public Date getBookingDate() {
return bookingDate;
}
Page 5 of 12
public void setBookingDate(Date bookingDate) {
this.bookingDate = bookingDate;
}
public Date getDepartureDate() {
return departureDate;
}
public void setDepartureDate(Date departureDate) {
this.departureDate = departureDate;
}
public String getRoomType() {
return roomType;
}
public void setRoomType(String roomType) {
this.roomType = roomType;
}
public double getBillAmount() {
return billAmount;
}
Page 6 of 12
public void setBillAmount(double billAmount) {
this.billAmount = billAmount;
}
public double getTariffPerDay() {
if (roomType.equalsIgnoreCase("AC")) {
return 3725.00;
} else if (roomType.equalsIgnoreCase("Non-AC")) {
return 2250.00;
}
return 0.0;
}
@Override
public String toString() {
return "Customer id:" + customerId + "\nBill Amount:Rs." +
billAmount;
}
}
class Offer {
public double getOffer(String roomType, double billAmount) {
if (roomType.equalsIgnoreCase("AC")) {
if (billAmount > 10000) {
return 18;
} else if (billAmount > 5000) {
return 12;
}
} else if (roomType.equalsIgnoreCase("Non-AC")) {
Page 7 of 12
if (billAmount > 10000) {
return 3;
}
}
return 0;
}
}
class HotelBillService {
public String validateData(String customerId, Date bookingDate, Date
departureDate, String roomType)
throws InvalidDataException, InvalidRoomTypeException {
if (customerId == null || customerId.length() != 8) {
throw new InvalidDataException();
}
if (bookingDate.after(departureDate)) {
throw new InvalidDataException();
}
if (!roomType.equalsIgnoreCase("AC") &&
!roomType.equalsIgnoreCase("Non-AC")) {
throw new InvalidRoomTypeException();
}
return "Valid";
}
public int getDaysStayed(Date bookingDate, Date departureDate) {
long difference = departureDate.getTime() - bookingDate.getTime();
Page 8 of 12
return (int) (difference / (1000 * 60 * 60 * 24)); // Convert milliseconds to
days
}
public String calculateBill(String customerId, Date bookingDate, Date
departureDate, String roomType) throws Exception {
try {
String validation = validateData(customerId, bookingDate,
departureDate, roomType);
if (!validation.equals("Valid")) {
return validation;
}
Customer customer = new Customer(customerId, bookingDate,
departureDate, roomType);
int daysStayed = getDaysStayed(bookingDate, departureDate);
double tariffPerDay = customer.getTariffPerDay();
double billAmount = daysStayed * tariffPerDay;
double tax;
if (billAmount <= 5000) {
tax = 5;
} else if (billAmount <= 10000) {
tax = 10;
} else {
tax = 20;
Page 9 of 12
}
double totalBill = billAmount + (billAmount * tax / 100);
Offer offer = new Offer();
double offerPercentage = offer.getOffer(roomType, totalBill);
double finalBill = totalBill - (totalBill * offerPercentage / 100);
customer.setBillAmount(finalBill);
return customer.toString();
} catch (InvalidDataException | InvalidRoomTypeException e) {
return e.toString();
}
}
}
public class MainClass {
public static void main(String[] args) throws Exception {
SimpleDateFormat formatter = new
SimpleDateFormat("dd/MM/yyyy");
HotelBillService h = new HotelBillService();
Date bookingDate = formatter.parse("11/07/2017");
Date departureDate = formatter.parse("13/07/2017");
System.out.println(h.calculateBill("CC112233", bookingDate,
departureDate, "AC"));
}}
Page 10 of 12
Output
Page 11 of 12