From 4469f17cf2c7b5e6b23f4d6038410e5b8ac872f6 Mon Sep 17 00:00:00 2001 From: Srushti Chiddarwar Date: Sun, 30 May 2021 16:10:40 +0530 Subject: [PATCH] Hostel Management --- .../Hostel-Management-main/Admin.java | 209 ++++++++++ .../Hostel-Management-main/Attendance.java | 27 ++ .../Hostel-Management-main/README.md | 53 +++ .../Hostel-Management-main/Room.java | 31 ++ .../Hostel-Management-main/Student.java | 356 ++++++++++++++++++ .../SubmitAttendance.java | 23 ++ .../Hostel-Management-main/UseHostel.java | 68 ++++ 7 files changed, 767 insertions(+) create mode 100644 Hostel Management/Hostel-Management-main/Admin.java create mode 100644 Hostel Management/Hostel-Management-main/Attendance.java create mode 100644 Hostel Management/Hostel-Management-main/README.md create mode 100644 Hostel Management/Hostel-Management-main/Room.java create mode 100644 Hostel Management/Hostel-Management-main/Student.java create mode 100644 Hostel Management/Hostel-Management-main/SubmitAttendance.java create mode 100644 Hostel Management/Hostel-Management-main/UseHostel.java diff --git a/Hostel Management/Hostel-Management-main/Admin.java b/Hostel Management/Hostel-Management-main/Admin.java new file mode 100644 index 0000000..a2c61d0 --- /dev/null +++ b/Hostel Management/Hostel-Management-main/Admin.java @@ -0,0 +1,209 @@ +package definition; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.LinkedHashSet; +public class Admin { + LinkedHashSet hs ; + Room r= new Room() ; + SubmitAttendance sa=new SubmitAttendance(); + public Admin(LinkedHashSet hs,Room r, SubmitAttendance sa) + { + this.hs=hs; + this.r=r ; + this.sa=sa; + } + public boolean login() throws IOException + { + String name="a"; + String pass="a"; + String u_name; + String u_pass; + InputStreamReader isr=new InputStreamReader(System.in); + BufferedReader br=new BufferedReader(isr); + System.out.println("Enter username"); + u_name=br.readLine(); + System.out.println("Enter password"); + u_pass=br.readLine(); + if(u_name.compareTo(name)==0 && u_pass.compareTo(pass)==0) + { + return true; + } + else + { + return false; + } + } + public int menu() throws IOException + { + int choice=0; + do + { + InputStreamReader isr=new InputStreamReader(System.in); + BufferedReader br=new BufferedReader(isr); + System.out.println("Enter your choice"); + System.out.println("1.Display all records"); + System.out.println("2.Display vacancy"); + System.out.println("3.Display attendance"); + System.out.println("4.Search record"); + System.out.println("5.Fee paid status"); + System.out.println("0. Exit"); + try + { + choice=Integer.parseInt(br.readLine()); + } + catch(NumberFormatException e) + { + System.out.println("Please enter a valid number"); + choice=-1; + } + }while(choice < 0 || choice > 5 ); + return choice; + } + public void call_menu() throws IOException + { + InputStreamReader isr=new InputStreamReader(System.in); + BufferedReader br=new BufferedReader(isr); + int choice =0 ; + int flag=0; + int id=0; + do + { + choice = menu(); + switch(choice) + { + case 1: + if (hs.isEmpty()) + { + System.out.println("No records found"); + break ; + } + for(Student b:hs) + { + System.out.println(b.id+" "+b.name+" "+b.roomno+" "+b.fees+" "+b.mobile_no); + } + break ; + case 2: + r.displayAllRoomDetails(); + break ; + case 3 : + if (hs.isEmpty()) + { + System.out.println("No records found"); + break ; + } + System.out.println("Enter id: "); + flag=0; + do + { + try + { + id=Integer.parseInt(br.readLine()); + flag=1; + } + catch(NumberFormatException e) + { + System.out.println("Invalid id"); + System.out.println("Please enter correct id again"); + } + }while(flag!=1); + + sa.bdisplayAttendance(id); + break ; + case 4: + if (hs.isEmpty()) + { + System.out.println("No records found"); + break ; + } + System.out.println("Enter id: "); + flag=0; + do + { + try + { + id=Integer.parseInt(br.readLine()); + flag=1; + } + catch(NumberFormatException e) + { + System.out.println("Invalid id"); + System.out.println("Please enter correct id again"); + } + }while(flag!=1); + displayById(id); + break; + case 5: + if (hs.isEmpty()) + { + System.out.println("No records found"); + break ; + } + int fchoice=0; + do + { + System.out.println("Enter choice:\n1: Students who have paid the fees"); + System.out.println("2: Students who have not paid the fees"); + try + { + fchoice=Integer.parseInt(br.readLine()); + } + catch(NumberFormatException e) + { + System.out.println("Please enter a valid number"); + fchoice=-1; + } + }while(fchoice < 1 || fchoice > 2 ); + displayFeeStatus(fchoice); + break; + case 0: + break ; + } + }while(choice!=0); + } + + public void displayById(int id_check) + { + int flag=0; + for(Student b:hs) + { + if(id_check==b.id) + { + System.out.println(b.id+" "+b.name+" "+b.roomno); + System.out.println("Total fees 1,00,000\nFees paid : "+b.fees+" Fees remaining :"+(100000-b.fees)); + flag=1; + break ; + } + } + if(flag!=1) + { + System.out.println("Record not found"); + } + } + + public void displayFeeStatus(int fchoice) + { + if(fchoice==1) + { + System.out.println("Name\tStatus"); + for(Student b:hs) + { + if(b.fees==100000f) + { + System.out.println(b.name+"\tPaid"); + } + } + } + else if(fchoice==2) + { + System.out.println("Name\tTotal Fees\tFees Paid\tFees Remaining"); + for(Student b:hs) + { + if(b.fees!=100000f) + { + System.out.println(b.name+"\t1,00,000\t"+b.fees+"\t\t"+(100000-b.fees)); + } + } + } + } +} \ No newline at end of file diff --git a/Hostel Management/Hostel-Management-main/Attendance.java b/Hostel Management/Hostel-Management-main/Attendance.java new file mode 100644 index 0000000..b42706f --- /dev/null +++ b/Hostel Management/Hostel-Management-main/Attendance.java @@ -0,0 +1,27 @@ +package definition; +import java.util.ArrayList; + +public class Attendance { + ArrayList att1= new ArrayList(); + + public void giveAttendance(int date) + { + att1.add(date); + } + + public void display() + { + int i=0; + for(i=1;i<=31;i++) + { + if(att1.contains(i)) + { + System.out.println("Day: "+(i)+" Record: Present"); + } + else + { + System.out.println("Day: "+(i)+" Record: Absent"); + } + } + } +} diff --git a/Hostel Management/Hostel-Management-main/README.md b/Hostel Management/Hostel-Management-main/README.md new file mode 100644 index 0000000..d2074c3 --- /dev/null +++ b/Hostel Management/Hostel-Management-main/README.md @@ -0,0 +1,53 @@ +# Hostel-Management +For the past few years, the number of educational institutions is increasing rapidly. Thereby the number of hostels is also increasing for the accommodation of the students +studying in this institution. And hence there is a lot of strain on the person who is running the hostel and software is not usually used in this context. +This particular project deals with the problems of managing a hostel and avoids the problems which occur when carried manually. Hence reduces the load on the person +handling this. It deals with the following problems: + +• Time consuming + +• Human error + +• Slow process + +• Poor quality + +• Data inconsistency + +• The process of maintaining records of students is manual and time-consuming + +• Maintaining attendance and fee status is difficult + +• Checking vacancy in a hostel is a bit tedious if all the process is handwritten + +• Getting a summary of all records is also not possible in a traditional record-keeping system + +• The chances of occurring errors are more. So the records must be accurate, informative, and dynamically updated. + +We have designed a Hostel Management System which can be used by Hostels for keeping a track of all the students present in the hostel. +Nowadays, all the records in hostels are handwritten and maintained in registers which is not feasible in the long run. If you want to look for a record of a specific student +you would have to spend hours looking through papers. + +We have made work tremendously easier, all you have to do is to enter the id of the student and all the details will be displayed to you within a second. +We have accomplished this by using data structures, algorithms, and numerous input validations. + +Data Structures Used: +LinkedHashSet: + +We wanted Fast searching and Insertion, also we had a large amount of data and we wished to maintain insertion order. +So we went for LinkedHashSet which has a O(1) time complexity. + + +ArrayList: +Java ArrayList class uses a dynamic array for storing the elements. It is like an array, but there is no size limit. +We can add or remove elements anytime . Methods of arraylist are non-synchronized which implies at a time multiple threads are allowed and hence provides high performance + +Sites/Books used for reference: + +GeeksForGeeks +StackOverflow +Big JAVA +W3Schools +Tutorialspoint +Javatpoint +JAVA Documentation diff --git a/Hostel Management/Hostel-Management-main/Room.java b/Hostel Management/Hostel-Management-main/Room.java new file mode 100644 index 0000000..6012f92 --- /dev/null +++ b/Hostel Management/Hostel-Management-main/Room.java @@ -0,0 +1,31 @@ +package definition; +public class Room +{ + int arr[] =new int[10] ; + public Room() + { + + } + public boolean allot(int roomno) + { + if(arr[roomno-1]<3) + { + arr[roomno-1]++; + return true; + } + else if(arr[roomno-1]>=3) + { + System.out.println("Sorry, this room is full. Please enter another room no"); + } + return false; + } + public void displayAllRoomDetails() + { + System.out.println("Room No No of occupants Vacancy"); + for(int i=0 ;i<10 ;i++) + { + System.out.println((i+1)+"\t "+arr[i]+"\t "+(3-arr[i])); + } + } + +} \ No newline at end of file diff --git a/Hostel Management/Hostel-Management-main/Student.java b/Hostel Management/Hostel-Management-main/Student.java new file mode 100644 index 0000000..868b203 --- /dev/null +++ b/Hostel Management/Hostel-Management-main/Student.java @@ -0,0 +1,356 @@ +package definition; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.LinkedHashSet; + +public class Student { + + int id; + static int roll_no; + String name; + int roomno; + float fees; + String password; + long mobile_no; + public SubmitAttendance sa = new SubmitAttendance(); + int arr[] = new int[10]; + LinkedHashSet hs; + Room r= new Room() ; + public Student() + { + + } + public Student(LinkedHashSet hs,Room r) { + this.hs=hs ; + this.r=r ; + + } + + public static int getRollNo() { + return roll_no ; + } + public static void setRollNo() { + roll_no++; + } + public int menu() throws IOException + { + int choice=0; + do + { + InputStreamReader isr=new InputStreamReader(System.in); + BufferedReader br=new BufferedReader(isr); + System.out.println("Enter your choice"); + System.out.println("1.Create new record"); + System.out.println("2.Access your record"); + System.out.println("0. Exit"); + try + { + choice=Integer.parseInt(br.readLine()) ; + } + catch(NumberFormatException e) + { + System.out.println("Please enter a valid number"); + choice=-1; + } + }while(choice < 0 || choice > 2 ); + return choice ; + } + public void call_menu() throws IOException + { + int choice=0; + do + { + choice=menu(); + switch(choice) + { + case 1: + if(Student.roll_no==30) + { + System.out.println("Hostel Full"); + return; + } + addrecord(); + break; + case 2: + verifyLogin(); + break ; + } + }while(choice!=0) ; + } + public void verifyLogin() throws IOException + { + InputStreamReader isr=new InputStreamReader(System.in); + BufferedReader br=new BufferedReader(isr); + int id1=0; + int flag=0; + String pass; + System.out.println("Enter id:"); + try + { + id1=Integer.parseInt(br.readLine()) ; + } + catch(Exception e) + { + System.out.println("Invalid id "); + verifyLogin(); + return; + } + + + System.out.println("Enter password:"); + pass=br.readLine(); + if(!hs.isEmpty()) + { + for(Student b:hs) + { + if(id1==b.id) + { + flag=1; + if(pass.compareTo(b.password)==0) + { + System.out.println("Welcome "+b.name); + sub_call_menu(b.id); + } + else + { + System.out.println("Invalid password"); + } + } + } + if(flag!=1) + { + System.out.println("No such record exists"); + } + } + else + { + System.out.println("No records present"); + } + } + public int sub_menu() throws IOException + { + int choice=0; + do + { + InputStreamReader isr=new InputStreamReader(System.in); + BufferedReader br=new BufferedReader(isr); + System.out.println("Enter your choice"); + System.out.println("1.Display profile"); + System.out.println("2.Give attendance"); + System.out.println("3.Display attendance of the month"); + System.out.println("4.Pay Fees"); + System.out.println("0.Exit"); + try + { + choice=Integer.parseInt(br.readLine()) ; + } + catch(NumberFormatException e) + { + System.out.println("Please enter a valid number"); + choice=-1; + } + }while(choice < 0 || choice > 4 ); + return choice ; + } + public void sub_call_menu(int id) throws IOException + { + int choice=0; + do + { + choice=sub_menu(); + switch(choice) + { + case 1: + display_profile(id); + break ; + case 2: + attendance(id); + break ; + case 3: + System.out.println("Attendance of the month is:"); + sa.bdisplayAttendance(id); + break; + case 4: + payFees(id); + break; + } + }while(choice!=0) ; + } + public void addrecord() throws IOException + { + InputStreamReader isr=new InputStreamReader(System.in); + BufferedReader br=new BufferedReader(isr); + int flag=0; + Student b=new Student(); + System.out.println("Enter your name:"); + b.name=br.readLine(); + System.out.println("Enter your room number:"); + do + { + try + { + b.roomno=Integer.parseInt(br.readLine()) ; + while(b.roomno>10 || b.roomno<1 ||r.allot(b.roomno)!=true) + { + System.out.println("Please enter a valid roomno between 1 and 10"); + b.roomno=Integer.parseInt(br.readLine()); + } + flag=1; + } + catch(NumberFormatException e) + { + System.out.println("Invalid room number"); + System.out.println("Please enter your correct roomno again"); + } + }while(flag!=1); + System.out.println("Enter fees that you have paid:"); + flag=0; + do + { + try + { + b.fees=Float.parseFloat(br.readLine()); + while(b.fees>100000 || b.fees<0) + { + System.out.println("Enter fees less than 10000 and non negative"); + b.fees=Float.parseFloat(br.readLine()); + } + flag=1; + } + catch(Exception e) + { + System.out.println("Invalid fees"); + System.out.println("Please enter your correct fees again"); + } + }while(flag!=1); + flag=0; + String mobno; + System.out.println("Enter mobile number"); + do + { + try + { + mobno=br.readLine(); + b.mobile_no=Long.parseLong(mobno); + + while(true) + { + if(b.mobile_no>=1000000000 && mobno.length()==10) + { + break; + } + else + { + System.out.println("Please enter a valid 10 digit mobile no greater than 0"); + mobno=br.readLine(); + b.mobile_no=Long.parseLong(mobno); + } + } + flag=1; + } + catch(NumberFormatException e) + { + System.out.println("Invalid mobile number"); + System.out.println("Please enter your correct mobile number again"); + } + }while(flag!=1); + System.out.println("Enter password"); + b.password=br.readLine(); + for(Student i:hs) + { + if(i.mobile_no==b.mobile_no) + { + System.out.println("Record already present"); + return; + } + } + Student.setRollNo(); + b.id=Student.getRollNo(); + hs.add(b); + System.out.println("Record added successfully! Your id is: "+b.id); + } + + public void display_profile(int id_check) + { + for(Student b:hs) + { + if(id_check==b.id) + { + System.out.println("Id: "+b.id+"\nName: "+b.name+"\nRoom number: "+b.roomno); + System.out.println("Total fees: 1,00,000"); + System.out.println("Fees paid: "+b.fees+"\nFees remaining: "+(100000-b.fees)); + System.out.println("Mobile No: "+b.mobile_no+"\n"); + break ; + } + } + } + + public void attendance(int id) throws IOException + { + InputStreamReader isr=new InputStreamReader(System.in); + BufferedReader br=new BufferedReader(isr); + int date=0; + System.out.println("Enter today's date"); + try + { + date=Integer.parseInt(br.readLine()) ; + while(date>31 || date<1) + { + System.out.println("Please enter a valid date"); + date=Integer.parseInt(br.readLine()) ; + } + } + catch(Exception e) + { + System.out.println("Invalid date"); + System.out.println("Please enter the correct date again"); + attendance(id); + return; + } + sa.bgetAttendance(id, date); + } + + public void payFees(int id) throws IOException + { + InputStreamReader isr=new InputStreamReader(System.in); + BufferedReader br=new BufferedReader(isr); + float amount=0.0f; + System.out.println("Enter amount to be paid"); + try + { + amount=Float.parseFloat(br.readLine()); + } + catch (Exception e) + { + System.out.println("Please enter correct amount"); + payFees(id); + return; + } + for(Student b:hs) + { + if(id==b.id &&(amount+ b.fees)<=100000.0 && (amount>=0.0)) + { + b.fees=b.fees+amount; + System.out.println(b.fees); + System.out.println("Amount paid successfully!"); + break; + } + else if(id==b.id && b.fees==100000.0) + { + System.out.println("Your total fees already completed"); + break; + } + else if((100000.0-b.fees)=0.0)) + { + System.out.println("Please check your fees status"); + break; + } + else if(amount<0.0&&b.id==id) + { + System.out.println("Enter amount correctly"); + break; + } + } + } +} diff --git a/Hostel Management/Hostel-Management-main/SubmitAttendance.java b/Hostel Management/Hostel-Management-main/SubmitAttendance.java new file mode 100644 index 0000000..97a0f43 --- /dev/null +++ b/Hostel Management/Hostel-Management-main/SubmitAttendance.java @@ -0,0 +1,23 @@ +package definition; + +public class SubmitAttendance { + Attendance[] a = new Attendance[10]; + + public SubmitAttendance() + { + int i=0; + for(i=0;i<10;i++) + { + a[i]=new Attendance(); + } + } + public void bgetAttendance(int id, int date) + { + a[id].giveAttendance(date); + } + + public void bdisplayAttendance(int id) + { + a[id].display(); + } +} diff --git a/Hostel Management/Hostel-Management-main/UseHostel.java b/Hostel Management/Hostel-Management-main/UseHostel.java new file mode 100644 index 0000000..f2b759a --- /dev/null +++ b/Hostel Management/Hostel-Management-main/UseHostel.java @@ -0,0 +1,68 @@ +package client; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.LinkedHashSet; + +import definition.Admin; +import definition.Room; +import definition.Student; +public class UseHostel +{ + public static void main(String args[]) throws IOException + { + int cho=0; + Room r= new Room(); + LinkedHashSet hs=new LinkedHashSet(); + Student b1=new Student(hs,r); + Admin ad=new Admin(hs,r,b1.sa); + do + { + cho=main_menu() ; + switch(cho) + { + case 0: + System.out.println("Exiting! Have a great day ahead!"); + break; + case 1: + boolean status1 = ad.login(); + if(status1==true) + { + ad.call_menu(); + } + else + { + System.out.println("Invalid login"); + } + break; + case 2: + b1.call_menu(); + break; + } + }while(cho!=0) ; + } + public static int main_menu() throws IOException + { + int cho=0 ; + do + { + InputStreamReader isr=new InputStreamReader(System.in); + BufferedReader br=new BufferedReader(isr); + System.out.println("Enter choice "); + System.out.println("1. Admin"); + System.out.println("2. Student"); + System.out.println("0. Exit"); + try + { + cho=Integer.parseInt(br.readLine()) ; + } + catch(NumberFormatException e) + { + System.out.println("Please enter a valid number"); + cho=-1; + } + }while(cho < 0 || cho > 2 ); + return cho ; + + } +} \ No newline at end of file