The function calendarFunc() takes input of two people's schedules of the day in the form of int arrays. (Eg. {0900,1300,1440,1540,1820,1910} denoting the person is busy from 9am-1pm, 2:40-3:40pm, 6:20-7:10pm) It finds the overlaps in their schedules and outputs at most three blocks of free time that they both have in common.
import java.util.*;
public class Main<Integer> implements CalendarFunc<Integer> {
ArrayList<Integer> PersonA = new ArrayList<Integer>();
ArrayList<Integer> PersonB = new ArrayList<Integer>();
ArrayList<Integer> BusyTime = new ArrayList<Integer>();
ArrayList<Integer> FreeTime = new ArrayList<Integer>();
public Main(ArrayList<Integer> PersonA, ArrayList<Integer> PersonB) {
this.PersonA = PersonA;
this.PersonB = PersonB;
}
@Override
public void removeSleepTime() {
// TODO removes sleeping blocks in FreeTime ArrayList
}
@Override
public void findUnion() {
// TODO return BusyTime, which is a union of all busy blocks
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
// TODO: Replace examples and use TDD development by writing your own tests
public class SolutionTest {
@Test
@SuppressWarnings("unchecked")
public static<Integer> void main(String[] args) {
//TODO takes in schedule blocks of Person A and B, make them into two arrayLists
Scanner s = new Scanner(System.in);
ArrayList<Integer> PerA = new ArrayList<Integer>();
ArrayList<Integer> PerB = new ArrayList<Integer>();
int count1 = 1;
int count2 = 1;
while(s.hasNext()){
System.out.println("Enter first person's schedule.");
System.out.println("Busy Block #"+ count1);
System.out.println("Start time "
+ "(Use military time, eg.0930): ");
Integer a1 = (Integer) s.nextLine();
System.out.println(a1);
System.out.println("End time "
+ "(Use military time, eg.1330): ");
Integer a2 = (Integer) s.nextLine();
System.out.println(a2);
PerA.add(a1);
PerA.add(a2);
count1++;
}
while(s.hasNext()){
System.out.println("Enter second person's schedule.");
System.out.println("Busy Block #"+ count2);
System.out.println("Start time "
+ "(Use military time, eg.0930): ");
Integer b1 = (Integer) s.nextLine();
System.out.println(b1);
System.out.println("End time "
+ "(Use military time, eg.1330): ");
Integer b2 = (Integer) s.nextLine();
System.out.println(b2);
PerB.add(b1);
PerB.add(b2);
count2++;
}
Main<Integer> c = new Main<Integer>(PerA, PerB);
c.findUnion();
c.removeSleepTime();
System.out.println(c.FreeTime);
}
}