0% found this document useful (0 votes)
20 views19 pages

Harshanth Java

Uploaded by

harsharsanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views19 pages

Harshanth Java

Uploaded by

harsharsanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

23CSR306 JAVA PROGRAMMING

Assignment

Hotel Management Service

Submitted by

Roll Number :717823L319


Name : HARSANTH D Y

Department of Electronics and communication Engineering

KARPAGAM COLLEGE OF ENGINEERING


(Autonomous)

Myleripalayam Village, Othakkal Mandapam Post,


Coimbatore - 641032, Tamilnadu, India

SEPTEMBER – 2024
DEPARTMENT OF Electronics and communication Engineering
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 19
• 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 19
Page 3 of 19
Project Objective:
Create a console based Java application that would allow a user of a House Management System to perform the
following operations

• Create a new Rental Property into the system [Posting availability of a new property that is available
for rent]

• Find the details of all the rental properties that would satisfy the search criteria

Project Design:
A. Database Design:
a. Create Table [ To be done using sql commands, after logging-in as the new user that has been
created in above step ]

Table Name: RENTAL_TBL

Insert some sample records into the table:


PROPERTYID RENTALAMOU NOOFBEDROO LOCATION CITY
NT MS
CHE1101 20000 2 AnnaNagar Chennai
BEN1102 20000 2 HSR Bengaluru
CHE1103 8000 1 Tambaram Chennai
BEN1104 25000 2 HSR Bengaluru
CHE1105 12000 2 Annanagar Chennai

Sequence Name: RENTAL_SEQ

Sequence Minimum Max Incremental Start


Name Value Values value Value
Rental_seq 1000 9999 1 1000

B. System Design:
Name of the package Usage
com.wipro.hms.service This package will contain the class that displays the console menu and
takes the user input.
com.wipro.hms.bean This package will contain the bean class
com.wipro.hms.dao This package will contain the class that will do the database related
operations
com.wipro.hms.util This package will contain a class to establish database connection and
also another class that handles the user defined exception.

Page 4 of 19
Package: com.wipro.hms.util
Class Method and Variables Description
DBUtil DB connection class
public static Establish a connection to the
ConnectiongetDBConnection() database and return the
java.sql.Connection reference
InvalidCityException User defined Exception class
public String toString() Returns “INVALID CITY”

Package: com.wipro.hms.bean

Class Method and Variables Description


RentalPropertyBean Class
private float rentalAmount;
private int noOfBedRooms;
private String location;
private String city;
private String propertyId;
setters & getters Should create the getter and setter
methods for all the attributes mentioned
in the class

Package: com.wipro.hms.dao

Class Method and Variables Description


RentalPropertyDA DAO class
O
public String generatePropertyID(String This method should return the
city) propertyId which is auto
generated using sequence.
Format: First 3 letters of the
city in uppercase followed by
the 4 digit auto generated
number.
E.g. CHE1000 – if the city
name is Chennai

Page 5 of 19
public int This method inserts the bean’s
createRentalProperty(RentalPropertyBean properties into the rental_tbl and
bean) returns the count of the records
inserted
Note: The propertyId should be
auto generated first by invoking the
appropriate DAO method
public List<RentalPropertyBean> This method should return the list
findPropertyByCriteria(float of all the properties that satisfies
minRentalAmount,float the criteria given.
maxRentalAmount,RentalPropertyBean Note: The location and city are
bean) case insensitive
For e.g. the user may give location
and city in any case (upper/lower)
and it should return the list of
properties that matches the cases
irrespective of their case
Example: minRentalAmount=12000
maxRentalAmount=18000
noOfBedRooms=2
location=Adyar
city=Chennai
This function should return a list
that contains all the houses whose
rental amount lies between 12000
and 18000 with 2 bedrooms that are
available in Adyar, Chennai

Package: com.wipro.hms.service
Class Method and Variables Description
RentalPropertySer Main class
vice
public static void main(String[] The code that is needed to test your program
args) goes here. A sample code is shown
at the end of the document.

Page 6 of 19
public String • It returns “NULL VALUES IN
addRentalProperty(RentalPropert INPUT”
yBean bean) if city or location is null
• It returns “INVALID INPUT”
under the following conditions
➢ Length of city or location is 0
➢ No of bedrooms/Rental
amount is 0
• This method will call
validateCity method for validating
city. If city is not either Chennai
or Bengaluru (not case sensitive)
the method should return
“INVALID CITY”
In all other conditions this method
should call createRentalProperty
method of DAO and returns
“SUCCESS” if record is inserted
else returns “FAILURE” if the
record
cannot be inserted
public List<RentalPropertyBean> • This method takes all the values
getPropertyByCriteria(float received, creates a
minRentalAmount,float RentalPropertyBean Object and
maxRentalAmount,int initializes it with it
noOfBedRooms,String • It then invokes the
location,String city) findPropertyByCriteria method of
the DAO class and returns the list
received.

• The returned records should match


all the criteria provided by the user.

Page 7 of 19
public String • It returns “INVALID VALUES”
fetchRentalProperty(float under the following conditions
minRentalAmount,float ➢ minRentalAmount/maxRenta
maxRentalAmount,int l Amount is 0
noOfBedRooms,String ➢ maxRentalAmount is
location,String city) lesser than
minRentalAmount
➢ noOfBedrooms is less than
or equal to 0
➢ location/city is null
➢ length of location/city is 0
• This method will call
validateCity method for
validating city. If city is not
either Chennai or Bengaluru (not
case sensitive) the method
should return “INVALID
CITY”
• If none of the above conditions
are matching, it invokes
getPropertyByCriteria method of
this class and receives the list
• If there are no records in the
list received, this method will
return “NO MATCHING
RECORDS”
• Else this method would return a
string in the following format
RECORDS AVAILABLE:5
[ Here, 5 is
the size of the list received]
public void validateCity(String • This method will throw
city) throws InvalidCityException InvalidCityException if the
provided
city name is not either chennai or
bengaluru (case insensitive)

Page 8 of 19
Implementation:
Package : com.wipro.hms.bean
Class : RentalPropertyBean.java
Code :-
package com.wipro.hms.bean;
public class RentalPropertyBean {

private float rentalAmount;


private int noOfBedRooms;
private String location;
private String city;
private String propertyId;

public float getRentalAmount() {


return rentalAmount;
}
public void setRentalAmount(float rentalAmount) {
this.rentalAmount = rentalAmount;
}
public int getNoOfBedRooms() {
return noOfBedRooms;
}
public void setNoOfBedRooms(int noOfBedRooms) {
this.noOfBedRooms = noOfBedRooms;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getPropertyId() {
return propertyId;
}
public void setPropertyId(String propertyId) {
this.propertyId = propertyId;
}

@Override

Page 9 of 19
public String toString() {
return "RentalPropertyBean [rentalAmount=" + rentalAmount + ", noOfBedRooms=" +
noOfBedRooms + ", location="+ location + ", city=" + city + ", propertyId=" + propertyId + "]";
}
}

Package : com.wipro.hms.util
Class : InvalidCityException.java
Code :-
package com.wipro.hms.util;

public class InvalidCityException extends Exception {


public String toString() {
return "INVALID CITY";
}
}
Class : DBUtil.java
Code :-
package com.wipro.hms.util;

import java.sql.Connection;
import java.sql.DriverManager;
//import java.sql.ResultSet;
//import java.sql.ResultSet;
import java.sql.SQLException;
//import java.sql.Statement;

public class DBUtil {


public static Connection getDBConnection() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/hms","Gokul","admin");
//
return con;
}

catch(ClassNotFoundException e){
System.out.println(e);
}

Page 10 of 19
catch(SQLException e) {
System.out.println(e);
}
return null;

}
}

Package : com.wipro.hms.dao
Class : RentalPropertyDAO.java
Code :-
package com.wipro.hms.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import com.wipro.hms.bean.RentalPropertyBean;
import com.wipro.hms.util.DBUtil;

public class RentalPropertyDAO {


public String generatePropertyID(String city) {
String cityCode = city.substring(0, 3).toUpperCase();
Random random = new Random();
int randomNumber = 1000 + random.nextInt(9000);
return cityCode+randomNumber;
}

public int createRentalProperty(RentalPropertyBean bean) throws SQLException {


Connection con=DBUtil.getDBConnection();

try {
Statement s = con.createStatement();
int n=s.executeUpdate("insert into rental_tbl
values('"+generatePropertyID(bean.getCity())+"',"+bean.getRentalAmount()+","+bean.getNoOfBedRoo
ms()+",'"+bean.getLocation()+"','"+bean.getCity()+"')");
System.out.println(n+" Rows affected...");
} catch (SQLException e) {
System.out.println(e);
}
con.close();
Page 11 of 19
return 1;
}

public List<RentalPropertyBean> findPropertyByCriteria(float minRentalAmount,float


maxRentalAmount,RentalPropertyBean bean){
List<RentalPropertyBean> list=new ArrayList<RentalPropertyBean>();

try {
Connection con=DBUtil.getDBConnection();
Statement s = con.createStatement();
ResultSet rs=s.executeQuery("select * from rental_tbl where RentalAmount >
"+minRentalAmount+" and rentalamount < "+maxRentalAmount+" and
noofbedroom="+bean.getNoOfBedRooms()+" and location='"+bean.getLocation()+"' and
city='"+bean.getCity()+"'");
while(rs.next()) {
RentalPropertyBean a=new RentalPropertyBean();
a.setPropertyId(rs.getString(1));
a.setRentalAmount(rs.getFloat(2));
a.setNoOfBedRooms(rs.getInt(3));
a.setLocation(rs.getString(4));
a.setCity(rs.getString(5));
list.add(a);
}
con.close();
}catch (SQLException e) {
System.out.println(e);
}
return list;
}
}

Package : com.wipro.hms.service
Code :-
package com.wipro.hms.service;

import com.wipro.hms.util.DBUtil;
import com.wipro.hms.util.InvalidCityException;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

Page 12 of 19
import com.wipro.hms.bean.RentalPropertyBean;
import com.wipro.hms.dao.RentalPropertyDAO;

public class RentalPropertyService {


public void validateCity(String city) throws InvalidCityException {
String ben="bengaluru";
String che="chennai";
boolean c=che.equalsIgnoreCase(city);
boolean b=ben.equalsIgnoreCase(city);
if(c==b) {
throw new InvalidCityException();
}

public String addRentalProperty(RentalPropertyBean bean) throws SQLException {


String city=bean.getCity();
String loc=bean.getLocation();
if(city == null || loc == null) {
return "NULL VALUES IN INPUT";
}
else if(city.length()==0 || loc.length()==0 || bean.getNoOfBedRooms()==0 ||
bean.getRentalAmount()==0.0) {
return "INVALID INPUT";
}
else {
try {
validateCity(bean.getCity());
} catch (InvalidCityException e) {
System.out.println(e);
}
}
RentalPropertyDAO a=new RentalPropertyDAO();
int i;
i = a.createRentalProperty(bean);
if(i==1) {
return "SUCCESS";
}
return "FAILURE";
}

public List<RentalPropertyBean> getPropertyByCriteria(float minRentalAmount,float


maxRentalAmount,int noOfBedRooms,String location,String city) {
RentalPropertyBean a=new RentalPropertyBean();
a.setCity(city);
Page 13 of 19
a.setLocation(location);
a.setNoOfBedRooms(noOfBedRooms);
RentalPropertyDAO b=new RentalPropertyDAO();
List<RentalPropertyBean> list=new ArrayList<RentalPropertyBean>();
list=b.findPropertyByCriteria(minRentalAmount, maxRentalAmount, a);
return list;
}

public String fetchRentalProperty(float minRentalAmount,float maxRentalAmount,int


noOfBedRooms,String location,String city) {
try {
validateCity(city);
} catch (InvalidCityException e) {
return "INVALID CITY";
}

if(minRentalAmount == 0 || maxRentalAmount==0 ||
maxRentalAmount<minRentalAmount || noOfBedRooms<=0) {
return "INVALID VALUES";
}
else if(location==null || city==null || city.length()==0 ||location.length()==0) {
return "INVALID VALUES";
}
else{
List<RentalPropertyBean> list=new ArrayList<RentalPropertyBean>();
list=getPropertyByCriteria(minRentalAmount, maxRentalAmount,
noOfBedRooms, location, city);
if(list.size()==0) {
return "NO MATCHING RECORDS";
}
else {
for (RentalPropertyBean a : list) {
System.out.println(a.getPropertyId()+" "+a.getRentalAmount()+"
"+a.getNoOfBedRooms()+" "+a.getLocation()+" "+a.getCity());
}
return "RECORDS AVALAIBLE:"+list.size();
}
}
}

public static void main(String[] args) throws SQLException {


Scanner input=new Scanner(System.in);
System.out.println("---Hotel Management System---");
System.out.println("1--> Admin Access\n2--> Customer Access\nEnter the choice:");
int ch = input.nextInt();
if(ch==1) {
Page 14 of 19
System.out.println("Enter the Password :");
String pass=input.next();
if(pass.equalsIgnoreCase("admin")) {
System.out.println("1--> View Table\n2--> Update Table\nEnter the Choice:");
int c=input.nextInt();
if(c==1) {
Connection con=DBUtil.getDBConnection();
Statement s=con.createStatement();
ResultSet rs = s.executeQuery("select * from RENTAL_TBL");
while(rs.next()) {

System.out.println(rs.getString(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3)+"\t"+rs.getString(4)+"\t"+rs.
getString(5));
}
con.close();
}
else if(c==2) {
RentalPropertyBean a=new RentalPropertyBean();
System.out.println("Rental Amount :");
a.setRentalAmount(input.nextFloat());
System.out.println("No Of BedRooms :");
a.setNoOfBedRooms(input.nextInt());
System.out.println("Location :");
String s=input.next();
a.setLocation(s);
System.err.println("City :");
a.setCity(s);
RentalPropertyService R = new RentalPropertyService();
System.out.println(R.addRentalProperty(a));
}
else {
System.out.println("Invalid Choice");
}
}
else {
System.out.println("PERMISSION DENIED\nUNAUTHORIZED ENTRY");
}
}
else if(ch==2) {
System.out.println("Please Enter the Details to check the availability :");
System.out.println("City :");
String city=input.next();
System.out.println("Location :");
String loc=input.next();
System.out.println("No of Bedrooms :");
int br=input.nextInt();
Page 15 of 19
System.out.println("Minimum Rental Amount :");
int min=input.nextInt();
System.out.println("Maximum Rental Amount :");
int max=input.nextInt();
String result=new RentalPropertyService().fetchRentalProperty(min,max,br,loc,city);
System.out.println(result);
}
else {
System.out.println("Invalid Choice");
}
}
}

Page 16 of 19
Output Screenshots :

Page 17 of 19
Page 18 of 19

You might also like