Skip to content
135 changes: 135 additions & 0 deletions Al.java
Original file line number Diff line number Diff line change
@@ -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;j<size;j++) {
if(elementData[j].equals(in)) {
flag=0;
break;
}
}
if(flag==0)
{
String removedElement = elementData[j];
for (int i = j; i <= size ; i++) {
elementData[i] = elementData[i + 1];
}
size--; // reduce size of ArrayListCustom after removal of element.

return removedElement;
}
else return null;
}

private void ensureCapacity() {
int newIncreasedCapacity = elementData.length * 2;
elementData = Arrays.copyOf(elementData, newIncreasedCapacity);
}

public void display() {
int i=0;
int flag=0;
if(size==1) {
System.out.println(elementData[i] + ".");}

else {
for ( i = 0; i < size; i++) {

if(i==0)
{
System.out.print(elementData[i] + " ");
}
else
{
for(int j=0;j<i;j++)
{
if(elementData[i].equals(elementData[j]))
{
flag=1;
break;
}

}
if(flag==0)
{
System.out.print(elementData[i] +" ");
}
}
flag=0;

}
}
}



public String getElementData(int i) {
return elementData[i];
}


@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + Arrays.hashCode(elementData);
result = prime * result + size;
return result;
}


@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Al)) {
return false;
}
Al other = (Al) obj;
if (!Arrays.equals(elementData, other.elementData)) {
return false;
}
if (size != other.size) {
return false;
}
return true;
}


public int getSize() {
return size;
}

public String getString(int i){
return elementData[i];
}

}
40 changes: 40 additions & 0 deletions Al2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package logic;
import java.util.Arrays;

public class Al2 {
private static final int INITIAL_CAPACITY = 5;
private int size ;
private Value[] values ;

public Al2()
{
this.values= new Value[INITIAL_CAPACITY];
for(int i=0;this.values[i]!=null;i++)
size=i+1;
}


public void add(Value obj) {

if ( size == values.length) {
ensureCapacity(); // increase current capacity of list, make it double.
}

this.values[size++] = obj;
}




private void ensureCapacity() {
int newIncreasedCapacity = values.length * 2;
values = Arrays.copyOf(values, newIncreasedCapacity);//increase size of ArrayList
}

public Value getValues(int i) {
return values[i];

}
}


36 changes: 36 additions & 0 deletions AlAl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package logic;

import java.util.Arrays;

public class AlAl {
private static final int INITIAL_CAPACITY = 5;
private int size ;
private Value2[] values2 ;//***

public AlAl() {

this.values2= new Value2[INITIAL_CAPACITY];
for(int i=0;this.values2[i]!=null;i++)
size=i+1;
}


public void add(Value2 obj) {

if ( size == values2.length) {
ensureCapacity(); //calling function to double size
}

this.values2[size++] = obj;
}

private void ensureCapacity() {
int newIncreasedCapacity = values2.length * 2;// increase current capacity of list, make it double.
values2 = Arrays.copyOf(values2, newIncreasedCapacity);
}

public Value2 getValues2(int i) {
return values2[i];

}
}
11 changes: 11 additions & 0 deletions Entry Records.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Guest Name: Jayesh Joshi Phone no: 7894561354 FlatNo: 5 Date & Time: 22-05-2021 , 22:14:54

Guest Name: Aditi Kamlakar Phone no: 7894561235 FlatNo: 10 Date & Time: 22-05-2021 , 22:17:05

Guest Name: Samiksha Patil Phone no: 9876543215 FlatNo: 8 Date & Time: 22-05-2021 , 23:12:55

Guest Name: Gauri Kulkarni Phone no: 7894561235 FlatNo: 19 Date & Time: 22-05-2021 , 23:13:53

Guest Name: Abhishek Upase Phone no: 9547863245 FlatNo: 1 Date & Time: 22-05-2021 , 23:57:23

Guest Name: Aasawari Joshi Phone no: 7412546325 FlatNo: 23 Date & Time: 27-05-2021 , 22:23:09
22 changes: 22 additions & 0 deletions Entry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package logic;

public class Entry
{
public Key key;
public Value value;
public Entry(Key key, Value value)//parameterized constructor
{
this.key = key;
this.value = value;
}

public Key getKey() //getter function for Key
{
return key;
}
public Value getValue() //getter function for Value
{
return value;
}

}
23 changes: 23 additions & 0 deletions Entry2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package logic;

public class Entry2
{
public Key2 key2;
public Value2 value2;

public Entry2(Key2 key2, Value2 value2) //Parameterized constructor
{
this.key2 = key2;
this.value2 = value2;
}

public Key2 getKey2() //getter function for Key2
{
return key2;
}
public Value2 getValue2() //getter function for Value2
{
return value2;
}

}
78 changes: 78 additions & 0 deletions FileToAl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package logic;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class FileToAl
{

public void loadData(Al flatNos, Al2 values, Al hnames_type,AlAl fnos) throws FileNotFoundException
{
File f = new File("Residents data.txt");
File f2 = new File("Househelpers data.txt");
Scanner sc = new Scanner(f);
Scanner sc2 = new Scanner(f2);

//Reading and storing residents data
do
{
String temp="\0";
String temp2="$"; //To group the data of a flat no.
String record = sc.nextLine();
Scanner scr = new Scanner(record);
//String temp3;
scr.useDelimiter("#"); //For separating names and phone nos in a line scanned from file
temp=scr.next(); //scanning next line till delimiter (reads flat no)
while(!temp.equals(temp2))
{ //creating new object for every flat no.
flatNos.add(temp);
Al fm = new Al();
Al pn = new Al();

Value obj = new Value(fm,pn);
obj.getFamilyMembers().add(scr.next());
obj.getPhoneNumbers().add(scr.next());

record = sc.nextLine();
scr= new Scanner(record);
scr.useDelimiter("#");
temp=scr.next(); //scanning next line till delimiter (reads flat no)
if(temp.equals(temp2))
{ // To add the data of all family members in same object
while(sc.hasNext() && temp.equals(temp2))
{
obj.getFamilyMembers().add(scr.next());
obj.getPhoneNumbers().add(scr.next());
record = sc.nextLine();
scr= new Scanner(record);
scr.useDelimiter("#");
temp=scr.next();
}
}
values.add(obj); //Adding to values arraylist

}
scr.close();
} while(sc.hasNext());
sc.close();

//Reading and storing house helpers data
while(sc2.hasNext())
{
String record = sc2.nextLine();
Scanner scr2 = new Scanner(record);
scr2.useDelimiter("#"); //For separating names and flat nos in a line scanned from file
hnames_type.add(scr2.next()); //scanning and adding house helper's name & type
Al hf = new Al();
Value2 hfnos= new Value2(hf);
hfnos.getHfnos().add(scr2.next()); //scanning and adding flat nos the house helper works in same arraylist
while(scr2.hasNext())
{
hfnos.getHfnos().add(scr2.next());
}
fnos.add(hfnos);
scr2.close();
}
sc2.close();

}
}
Loading