diff --git a/Al.java b/Al.java new file mode 100644 index 0000000..227d7d6 --- /dev/null +++ b/Al.java @@ -0,0 +1,135 @@ +package logic; +import java.util.Arrays; + + public class Al + { + private static final int INITIAL_CAPACITY = 5; + private int size ; + private String[] elementData ; + + + public Al() { + + this.elementData= new String[INITIAL_CAPACITY]; + for(int i=0;this.elementData[i]!=null;i++) + size=i+1; + } + + + public void add(String name) { + + if ( size == elementData.length) { + ensureCapacity(); // increase current capacity of list, make it + // double. + } + + this.elementData[size++] = name; + } + + public String remove(String in) { + + int j=0,flag=1; + for( j=0;j25||gflat<1));//condition for while loop + this.flatNumber=Integer.toString(gflat); + } + + @Override + public String toString() {//for displaying + return "\nGuest Name: "+ name +"\t\tPhone no: "+ phoneNumber +" FlatNo: "+ flatNumber +" Date & Time: "+ formattedDate +" \n"; + + } + +} diff --git a/HashMap.java b/HashMap.java new file mode 100644 index 0000000..ca71312 --- /dev/null +++ b/HashMap.java @@ -0,0 +1,101 @@ +package logic; +import java.util.*; + + +public class HashMap { + @SuppressWarnings("unchecked") + LinkedList[] hashmap = new LinkedList[2]; + int size=0;//size==hashmap.length() !=hashmap.length + public HashMap() { + + } + public int getIndex(Key key) {//getter method for Index + return key.hashCode(); + } + + public int size() {//method that returns size + return size; + } + + @SuppressWarnings("unchecked") + public void resize() { + LinkedList[] oldhashmap = hashmap; + hashmap = new LinkedList[size*2];//Creating a new LinkedList of double size + size = 0; + for(int i=0;i=hashmap.length) { + resize();//call to resize function when threshold is reached + } + int ix=getIndex(key)%hashmap.length; + if(hashmap[ix]==null) { + hashmap[ix] = new LinkedList<>();//creating a new LinkedList + hashmap[ix].add(new Entry(key, value)); + size++; //Increasing size after adding elements + return; + } + else { + for(Entry entry : hashmap[ix]) { + if(entry.key.equals(key)) { + entry.value = value;//updating value + //size++; + return; + } + } + hashmap[getIndex(key)%hashmap.length].add(new Entry(key, value));//adding elements without replacement + //no size++ because we are adding a node to the existing linked list at [ix] calculated + //and not adding a diff linked list + return; + } + + } + + public Value get(Key key) { + int ix= getIndex(key)%this.hashmap.length; + if(this.hashmap[ix] ==null) { + return null; + } + + for(int j=0;j[] hashmap2 = new LinkedList[2]; + int size=0;//size==hashmap.length() !=hashmap.length + public HashMap2() { + + } + public int getIndex(Key2 key2) { + return key2.hashCode()&0x7FFFFFFF; + } + + public int size() { + return size; + } + + + public void resize() { + LinkedList[] oldhashmap2 = hashmap2; + hashmap2 = new LinkedList[size*2]; + size = 0; + for(int i=0;i=hashmap2.length) { + resize(); + } + int ix=getIndex(key2)%hashmap2.length; + if(hashmap2[ix]==null) { + hashmap2[ix] = new LinkedList<>(); + hashmap2[ix].add(new Entry2(key2, value2)); + size++; + return; + } + else { + for(Entry2 entry2 : hashmap2[ix]) { + if(entry2.key2.equals(key2)) { + entry2.value2 = value2; + //size++; + return; + } + } + hashmap2[getIndex(key2)%hashmap2.length].add(new Entry2(key2, value2)); + //no size++ because we are adding a node to the existing linked list at [ix] calculated + //and not adding a diff linked list + return; + } + + } + + public Value2 get(Key2 key2) { + int ix= getIndex(key2)%this.hashmap2.length; + if(this.hashmap2[ix] ==null) { + return null; + } + + for(int j=0;j We plan to make our project Graphical User Interface so that it would be more user friendly.We would like to add some more functionalities in the code. + +Note: Please make sure you open the text files in the project folder and not in the source folder.You may get a File not found exception if you open it in the src folder. diff --git a/Residents data.txt b/Residents data.txt new file mode 100644 index 0000000..96b504e --- /dev/null +++ b/Residents data.txt @@ -0,0 +1,73 @@ +FlatNumber#Name#PhoneNumber +1#Shrirang Pai#9856457645 +$#Rucha Pai#8769804563 +$#Supriya Pai#9837984704 +$#Ruta Pai#8769804563 +2#Veena Sathe#9763490332 +$#Mohan Sathe#9878676555 +$#Savita Sathe#9878909991 +3#Abhilasha Halbe#7654678975 +$#Aditya Halbe#7765654443 +$#Sangeeta Halbe#7768909876 +4#Ajit Bhavsar#91344368780 +$#Parth Bhavsar#91344368780 +$#Jayashri Bhavsar#9850443387 +$#Gauri Bhavsar#9088876652 +5#Chaitrali Joshi#9876656786 +$#Vivek Joshi#9087634225 +$#Sanjana Joshi#9234516785 +6#Shreya Marathe#9864567342 +$#Deepak Marathe#8875643221 +$#Ashwinee Marathe#8897098884 +7#Atharva Sharma#9678546332 +$#Richa Sharma#9611235670 +$#Divya Sharma#9678546332 +8#Parth Pal#8096754345 +9#Palak Mishra#7098564567 +$#Raj Mishra#8767765551 +10#Viraj Kaushal#8867545567 +$#Priyank Kaushal#9780554270 +11#Tirtha Vinchurkar#9405577350 +$#Shaun Vinchurkar#9405577350 +$#Dipali Vinchurkar#7756433251 +12#Chirag Hegde#9518511725 +$#Soham Hegde#9233421998 +$#Beena Hegde#9213321119 +13#Aditya Bhardwaj#9270768930 +$#Abhikrit Bhardwaj#9276554731 +$#Abhimanyu Bhardwaj#9270768930 +14#Abhishek Kapoor#8806865404 +$#Aishwarya Kapoor#9088776213 +$#Aaradhya Kapoor#8806865404 +15#Jenny Desouza#9886755448 +16#Virat Deshpande#7786546678 +$#Anushka Deshpande#7779654331 +$#Vamika Deshpande#7786546678 +17#Pritam Singh#9976875463 +$#Deepika Singh#9987665443 +18#Prashanth Pichai#9088766532 +$#Divya Pichai#9122354673 +19#Mukhesh Pol#9988097654 +$#Nita Pol#9987766721 +20#Amrita Ghatge#9655456221 +$#Mukta Ghatge#9655456221 +$#Vilas Ghatge#9655456221 +21#Ankita Sardeshmukh#8966545361 +$#Mihir Sardeshmukh#9122123321 +22#Ojas Kulkarni#7765564321 +$#Suvarna Kulkarni#9777644331 +$#Isha Kulkarni#9332221245 +23#Payal Naik#7657467890 +$#Sandesh Naik#9088879865 +$#Ketaki Naik#9876889990 +24#Pushkar Garde#7654321123 +25#Raunak Salve#9212232189 +$#Simran Salve#8790665443 +$#Rohan Salve#9866775554 +$#Shaunak Salve#9212232189 +$# + + + + + diff --git a/SocietyEntrance.java b/SocietyEntrance.java new file mode 100644 index 0000000..46a6425 --- /dev/null +++ b/SocietyEntrance.java @@ -0,0 +1,273 @@ +package logic; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class SocietyEntrance +{ + + public static void main(String[] args) throws IOException + { + + String code1 = "M64@27";// entry code for residents(assuming only residents know it) + String code2 = "F96@16";// entry code for house helpers + String code3 = "S82@99";// entry code for chairman(assuming only he knows it) + int ch = 0; + Scanner sc = new Scanner(System.in); + + String ec = "\0"; //accepted entry code + int count = 0; + int count1 = 0; + Al flatNos = new Al(); + Al2 values = new Al2(); //objects of Value class-family members and their phone nos + Al hnames_type = new Al(); //househelper's names and types + AlAl fnos = new AlAl(); //arraylist of flat nos arraylists (house helpers) + HashMap map = new HashMap(); + HashMap2 map2 = new HashMap2(); + File file = new File("Entry Records.txt"); + FileWriter fw = new FileWriter(file,true); //appends to the already existing file + + FileToAl obj = new FileToAl(); + try + { + obj.loadData(flatNos, values, hnames_type, fnos); + } + catch (FileNotFoundException e) { + System.out.println("File not found."); + e.printStackTrace(); + } + createMap(flatNos, values, map); + createMap2(hnames_type, fnos, map2); + do + { + ch = menu(); + switch (ch) + { + case 1: //Resident Entry + count = 0; + + do + { + System.out.println("Enter the code: "); + ec = sc.nextLine(); + if (!ec.equals(code1)) + { + if(count==2) { + System.out.println("No more attempts left.\nEntry Denied."); + break; + } + System.out.println( + "Sorry, the code you entered is wrong. You have " + (2 - count) + " attempt(s) left"); + count++; + } + } + while (!ec.equals(code1) && count < 3); // 3 attempts + if (ec.equals(code1)) { + System.out.println("Welcome!!!\nYou can enter!"); + } + break; + + case 2: //House helper Entry + count1 = 0; + Scanner sc1 = new Scanner(System.in); + do { + + System.out.println("Enter the code: "); + ec = sc1.nextLine(); + if (!ec.equals(code2)) { + if(count1==2) { + System.out.println("No more attempts left.\nEntry Denied."); + break; + } + System.out.println( + "Sorry, the code you entered is wrong. You have " + (2 - count1) + " attempt(s) left"); + count1++; + } + } + while (!ec.equals(code2) && count1 < 3); // 3 attempts + + if (ec.equals(code2)) // + { + String h_name; + Key2 key2 = new Key2(); + int h_ch;//accepting house helper name and type + System.out.println("Now Enter your name"); + h_name = sc1.nextLine(); + do + { + System.out.println("\t\t\t\t\tType of House-Helper :" + "\n \t\t\t\t\t\t1. Maid" + "\n \t\t\t\t\t\t2. Milkman" + "\n \t\t\t\t\t\t3. Driver" + + "\n\t\t\t\t\t\t 4. Newspaper Vendor" + "\n \t\t\t\t\t\t5. Garbage Collector"); + + System.out.println("Choose an option from above"); + h_ch = sc1.nextInt(); + switch (h_ch) { + case 1: + key2.hname_type = (h_name + "-Maid"); + break; + case 2: + key2.hname_type = (h_name + "-Milkman"); + break; + case 3: + key2.hname_type = (h_name + "-Driver"); + break; + case 4: + key2.hname_type = (h_name + "-Newspaper vendor"); + break; + case 5: + key2.hname_type = (h_name + "-Garbage collector"); + break; + default: + System.out.println("Enter valid option"); + break; + } + } + while (ch < 1 && ch > 5); + + boolean found1=false; + for(int i=0;i 5); + return ch; + } + + public static void createMap(Al flatNos, Al2 values, HashMap map) + { //Mapping flat nos to resident data + for (int i = 0; i < flatNos.getSize(); i++) + { + Key key = new Key(); + key.flatNumber = flatNos.getString(i); + map.put(key, values.getValues(i)); + } + } + + public static String permission(Guest g) // getting permission from resident + { + Scanner sc = new Scanner(System.in); + String approved; + System.out.println( + g.getName() + " wants to meet you.\nEnter '1' if the person is your guest, else enter any other key"); + approved=sc.nextLine(); + return approved; + } + + public static void createMap2(Al hnames_type, AlAl fnos, HashMap2 map2) + { //Mapping house helpers to flat nos they work in + for (int i = 0; i < hnames_type.getSize(); i++) + { + Key2 key2 = new Key2(); + key2.hname_type = hnames_type.getString(i); + map2.put(key2, fnos.getValues2(i)); + } + + } +} diff --git a/Value.java b/Value.java new file mode 100644 index 0000000..44b2e62 --- /dev/null +++ b/Value.java @@ -0,0 +1,52 @@ +package logic; + +import java.util.Objects; + +public class Value { + + private Al familyMembers;//ArrayList for Names of Family Members + private Al phoneNumbers;//ArrayList for Phone Numbers of Family Members + + public Value(Al familyMembers, Al phoneNumbers) {//parameterized constructor + this.familyMembers = familyMembers; + this.phoneNumbers = phoneNumbers; + } + + public Value() {//default constructor + this.familyMembers = null; + this.phoneNumbers = null; + } + + public Al getFamilyMembers() { + return familyMembers; + } + + public Al getPhoneNumbers() { + return phoneNumbers; + } + + + + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof Value)) { + return false; + } + Value other = (Value) obj; + return Objects.equals(familyMembers, other.familyMembers) && Objects.equals(phoneNumbers, other.phoneNumbers); + } + + @Override + public String toString() {//Used for Displaying the information of the family + return "Value [familyMembers=" + familyMembers + ", phoneNumbers=" + phoneNumbers + "]"; + } + + + +} + + diff --git a/Value2.java b/Value2.java new file mode 100644 index 0000000..32fa151 --- /dev/null +++ b/Value2.java @@ -0,0 +1,33 @@ +package logic; + +import java.util.Objects; + +public class Value2 { + public Al hfnos; + + public Value2(Al hfnos) {//parameterized constructor + this.hfnos = hfnos; + } + + public Value2() {//default constructor + this.hfnos = null; + } + + + public Al getHfnos() { + return hfnos; + } + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof Value2)) { + return false; + } + Value2 other = (Value2) obj; + return Objects.equals(hfnos, other.hfnos);//returning boolean value + } + + +}