From ee64d6dada934c6bbed62938d5f9491c6fd4bd40 Mon Sep 17 00:00:00 2001 From: PopescuGeorge1 <> Date: Wed, 13 Jan 2021 08:51:15 +0200 Subject: [PATCH] Singleton implementation - used a Lazy initialization pattern on Hotel class - made variables private --- .classpath | 5 +++++ .project | 17 +++++++++++++++++ Project.java | 15 +++++++++++++-- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 .classpath create mode 100644 .project diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..ac37fb2 --- /dev/null +++ b/.classpath @@ -0,0 +1,5 @@ + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..d2344b6 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + Hotel-Management-Project-Java + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Project.java b/Project.java index 9a2bc7d..cd26a2d 100755 --- a/Project.java +++ b/Project.java @@ -90,8 +90,19 @@ class holder implements Serializable class Hotel { - static holder hotel_ob=new holder(); - static Scanner sc = new Scanner(System.in); + + private static Hotel s_hotel=null; + private static holder hotel_ob; + private static final Scanner sc = new Scanner(System.in); + + private Hotel() {} + + public static Hotel getHotel() { + if(s_hotel==null) + s_hotel=new Hotel(); + return s_hotel; + } + static void CustDetails(int i,int rn) { String name, contact, gender;