School Assignment

I have a school assignment due tomorrow and I have been stuck on the same damn test case for three days. Before anyone asks, I have gone to office hours and asked TAs however this is a new issue and now one is around. I am making an employee database and populating it based on a csv file which I cannot view. I have been able to do everything correctly so far and the file has no errors, however I cannot pass one of the test cases. The code has to find if an employee is apart of one or more departments(it is doing this, I have checked it many times). each department object has a date of joining, if an employee is apart of more than one department, then I need to find the time between the dates in days. I am adding all of the correct data to the correct lists, so I think its an issue with how I'm calculating the difference. Point is I am really stuck and would really appreciate some help as soon as possible. If anyone is available to hop in a call that would be preferable
142 Replies
JavaBot
JavaBot2mo ago
This post has been reserved for your question.
Hey @Runger! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
ayylmao123xdd
ayylmao123xdd2mo ago
if im reading it right you have to find the days between two department join dates yes
public long date_diff_value(String empId)
{
int idx = -1;

// Loops through the list of all employee objects
for (int i = 0; i < emp_obj_list.size(); i++)
{
// Checks whether the current empId matches the one found
if (emp_obj_list.get(i).get_emp_id().equals(empId))
{
idx = i;
break;
}
}
// return -1 if we do not find a match with the empId
if (idx == -1)
{
return -1;
}

ArrayList<Department> deps = emp_obj_list.get(idx).get_depLst();

// returns -1 if the employee is appointed in one department or less
if (deps.size() <= 1)
{
return -2;
}

LocalDate min = null, max = null;
for (int i = 0; i < deps.size(); i++)
{
LocalDate d = LocalDate.parse(deps.get(i).get_join_date());
if (min == null || d.isBefore(min))
min = d;
if (max == null || d.isAfter(max))
max = d;
}
return ChronoUnit.DAYS.between(min, max);
}
public long date_diff_value(String empId)
{
int idx = -1;

// Loops through the list of all employee objects
for (int i = 0; i < emp_obj_list.size(); i++)
{
// Checks whether the current empId matches the one found
if (emp_obj_list.get(i).get_emp_id().equals(empId))
{
idx = i;
break;
}
}
// return -1 if we do not find a match with the empId
if (idx == -1)
{
return -1;
}

ArrayList<Department> deps = emp_obj_list.get(idx).get_depLst();

// returns -1 if the employee is appointed in one department or less
if (deps.size() <= 1)
{
return -2;
}

LocalDate min = null, max = null;
for (int i = 0; i < deps.size(); i++)
{
LocalDate d = LocalDate.parse(deps.get(i).get_join_date());
if (min == null || d.isBefore(min))
min = d;
if (max == null || d.isAfter(max))
max = d;
}
return ChronoUnit.DAYS.between(min, max);
}
in the comment it says returns -1 if employee is appointed in one department but it returns -2
Runger
RungerOP2mo ago
yeah mb i just didnt change the value when i was testing something, I forgot to chang the comment but it should still work fine, unless it doesnt?
ayylmao123xdd
ayylmao123xdd2mo ago
idk just pointing it out i think theres something wrong with this part
LocalDate min = null, max = null;
for (int i = 0; i < deps.size(); i++)
{
LocalDate d = LocalDate.parse(deps.get(i).get_join_date());
if (min == null || d.isBefore(min))
min = d;
if (max == null || d.isAfter(max))
max = d;
}
LocalDate min = null, max = null;
for (int i = 0; i < deps.size(); i++)
{
LocalDate d = LocalDate.parse(deps.get(i).get_join_date());
if (min == null || d.isBefore(min))
min = d;
if (max == null || d.isAfter(max))
max = d;
}
give me a moment
Runger
RungerOP2mo ago
i was told not to change that class, but if somethings wrong, i will gladfully rewrite my own version of it because that class looks like it makes no sense
ayylmao123xdd
ayylmao123xdd2mo ago
oh so this one shouldnt be changed
public void print_cross_emp()
{
int record = 00;

for(int i = 0; i < emp_obj_list.size(); i++) // Loops through the employee object list
{
Employee temp = new Employee(emp_obj_list.get(i).get_fName(), emp_obj_list.get(i).get_lName());
Department dep = new Department(temp.get_fName(), temp.get_lName());

if (temp.get_depLst().size() > 1) // If the employee has more than one department, then print out the required statement
{
record++;
System.out.println("Record " + record + " found! " + temp.toString() + " Appointments found: \n");
for(int j = 0; j < temp.get_depLst().size(); j++)
{
System.out.println(dep.toString() + "\n");
}
}
}
}
public void print_cross_emp()
{
int record = 00;

for(int i = 0; i < emp_obj_list.size(); i++) // Loops through the employee object list
{
Employee temp = new Employee(emp_obj_list.get(i).get_fName(), emp_obj_list.get(i).get_lName());
Department dep = new Department(temp.get_fName(), temp.get_lName());

if (temp.get_depLst().size() > 1) // If the employee has more than one department, then print out the required statement
{
record++;
System.out.println("Record " + record + " found! " + temp.toString() + " Appointments found: \n");
for(int j = 0; j < temp.get_depLst().size(); j++)
{
System.out.println(dep.toString() + "\n");
}
}
}
}
so is this one that you can change
Runger
RungerOP2mo ago
yes i can 100% change that one
ayylmao123xdd
ayylmao123xdd2mo ago
and so the test fails here or in a different method as in
Runger
RungerOP2mo ago
i dont know where the test fails
ayylmao123xdd
ayylmao123xdd2mo ago
true does it work tho as in does it print the cross department for some employee
Runger
RungerOP2mo ago
nope
ayylmao123xdd
ayylmao123xdd2mo ago
what i mean is which method is responsible for printing this cross thing to the console cuz im guessing thats what the test checks
Runger
RungerOP2mo ago
see thats where i get confused, when the test case is called for the unique employees, it expected a statement to be outputted because it of course, prints a statement, but here it doesnt want a print statement which leads me questioning what function is the test case actually calling idk though ill change anything
ayylmao123xdd
ayylmao123xdd2mo ago
that cross thing in the last screenshot with the tests what exactly does it expect to print 'difference between cross appointments'
Runger
RungerOP2mo ago
i believe it is looking for the difference between the earliest start date and the latest start date of a given employee that is apart of more than one appointment
ayylmao123xdd
ayylmao123xdd2mo ago
// Finds the difference between dates for a given employee id
public void date_diff(String empId)
{
long date = date_diff_value(empId);

if (date == -1) // If the employee id is not found or is not apart of more than 1 department, print "employee not found!"
{
System.out.println("Employee not found!");
}
else if (date == -2)
{
System.out.println("Employee is not cross-appointed.");
}
else // Otherwise, print the difference between join dates of departments
{
System.out.println("Difference between cross-appointments (in days) is: " + date);
}


}
// Finds the difference between dates for a given employee id
public void date_diff(String empId)
{
long date = date_diff_value(empId);

if (date == -1) // If the employee id is not found or is not apart of more than 1 department, print "employee not found!"
{
System.out.println("Employee not found!");
}
else if (date == -2)
{
System.out.println("Employee is not cross-appointed.");
}
else // Otherwise, print the difference between join dates of departments
{
System.out.println("Difference between cross-appointments (in days) is: " + date);
}


}
so this method seems to fail
Runger
RungerOP2mo ago
probably this method uses the one given to me so I think there is an issue with that last one i just dont know what to change
ayylmao123xdd
ayylmao123xdd2mo ago
interesting do you have access to how the tests launch and the tests code like i just wanna check what it expects to print it says cross: 0 but i cant find that in code
Runger
RungerOP2mo ago
its done through moodle, all i get is a text document and i have to write code ive been writing it in my own IDE and pasting it over
ayylmao123xdd
ayylmao123xdd2mo ago
ok
Runger
RungerOP2mo ago
I think i found something, I just dont know how to fix it or why its happening. when i check the size of the department list for a specific employee(i managed to print out the csv file to find one employee that was cross appointed to two departments) it returns 0, so somewhere, some how, i think my list is being emptied
No description
ayylmao123xdd
ayylmao123xdd2mo ago
so that would mean the print methods are ok but there is no association between employee and department
Runger
RungerOP2mo ago
maybe when i put that same print statement inside the else statement and at the end of the for loop, it prints 2
ayylmao123xdd
ayylmao123xdd2mo ago
can you show where you put the prints
Runger
RungerOP2mo ago
yeah, give me one second
ayylmao123xdd
ayylmao123xdd2mo ago
also do you know by any chance if the first name and last name are unique in the csv like you dont have john doe 2 times i guess it should be unique
Runger
RungerOP2mo ago
so that is why i have a method called 'emp_exists' it checks if it is already there, and if it is then it doesnt add it to the employee object list(emp_obj_list) again but if its not there then it does add it. this part is working, the second test case checks this and passes but there are repeats in the csv file as some employees have more than one department and start date
Runger
RungerOP2mo ago
No description
Runger
RungerOP2mo ago
at the bottom of add_emp_data, i get a 0 when i print the size
Runger
RungerOP2mo ago
No description
Runger
RungerOP2mo ago
but when i print it here and check the 27th print, it is 2
No description
Runger
RungerOP2mo ago
oh wait nevermind no it isnt this is good i have found something else to figure out, progress
ayylmao123xdd
ayylmao123xdd2mo ago
this decrease and increase id thing is kinda weird to me
Runger
RungerOP2mo ago
same, i wasnt really sure what it wants me to do i figured as long as its not super relevant to the test case, i can figure it out once it does become relevant
ayylmao123xdd
ayylmao123xdd2mo ago
hmmmmm maybe thats the problem like it assigns the departments to the wrong id i would have to check more but its kinda weird that it decreases the id when it finds an employee
Runger
RungerOP2mo ago
yeah
ayylmao123xdd
ayylmao123xdd2mo ago
for(int j = 0; j < emp_obj_list.size(); j++)
{
String emp_fName = emp_obj_list.get(j).get_fName();
String emp_lName = emp_obj_list.get(j).get_lName();

if (temp.get_fName().equals(emp_fName) && temp.get_lName().equals(emp_lName))
{
Department dep2 = new Department(emp_rows.get(j).get(2), emp_rows.get(j).get(3));
temp.add_dept(dep2);
}
}
for(int j = 0; j < emp_obj_list.size(); j++)
{
String emp_fName = emp_obj_list.get(j).get_fName();
String emp_lName = emp_obj_list.get(j).get_lName();

if (temp.get_fName().equals(emp_fName) && temp.get_lName().equals(emp_lName))
{
Department dep2 = new Department(emp_rows.get(j).get(2), emp_rows.get(j).get(3));
temp.add_dept(dep2);
}
}
so this if there already is a department it just overrides it with that id yes gonna check spend a few min to analyze
Runger
RungerOP2mo ago
what this should be doing is adding another department to an existing employees department list
ayylmao123xdd
ayylmao123xdd2mo ago
so does it print the same value here
else // Otherwise, decrease the empId and add the department to the employee object
{
Employee.decrementEmpID();
// Find ALL locations that there is a repeating employee name and add ALL of the departments to that employee
for(int j = 0; j < emp_obj_list.size(); j++)
{
String emp_fName = emp_obj_list.get(j).get_fName();
String emp_lName = emp_obj_list.get(j).get_lName();

if (temp.get_fName().equals(emp_fName) && temp.get_lName().equals(emp_lName))
{
Department dep2 = new Department(emp_rows.get(j).get(2), emp_rows.get(j).get(3));
temp.add_dept(dep2);
//print here too
}
}
// print here
}
//print here
System.out.println(temp.get_fName() + " " + temp.get_lName());
date_diff(findEmpIdByName(temp.get_fName(), temp.get_lName()));
System.out.println("\n");
else // Otherwise, decrease the empId and add the department to the employee object
{
Employee.decrementEmpID();
// Find ALL locations that there is a repeating employee name and add ALL of the departments to that employee
for(int j = 0; j < emp_obj_list.size(); j++)
{
String emp_fName = emp_obj_list.get(j).get_fName();
String emp_lName = emp_obj_list.get(j).get_lName();

if (temp.get_fName().equals(emp_fName) && temp.get_lName().equals(emp_lName))
{
Department dep2 = new Department(emp_rows.get(j).get(2), emp_rows.get(j).get(3));
temp.add_dept(dep2);
//print here too
}
}
// print here
}
//print here
System.out.println(temp.get_fName() + " " + temp.get_lName());
date_diff(findEmpIdByName(temp.get_fName(), temp.get_lName()));
System.out.println("\n");
if you print the employee at the end of the loop and outside the well loop lmao i added another place where you can check inside the loop
Runger
RungerOP2mo ago
at the bottom is prints out that every employee is not cross appointed, so they only have 1 or less departments
ayylmao123xdd
ayylmao123xdd2mo ago
and inside the loop the top most print comment
Runger
RungerOP2mo ago
inside the loop it is the same lemme try the last one okay it seems to print the same thing as well so it must not be adding the departments properly that or its not checking correctly
ayylmao123xdd
ayylmao123xdd2mo ago
ok lets run some shenanigans now :GnuTrolling: can you do it so for testing purposes you create two departments for each employee random department values and just do that until you get people with 311 cross departments so the test passes to check whether its really the problem with saving departments or printing them
Runger
RungerOP2mo ago
yeah i can probably try that, i think it uses a random empID so im just gonna make it so that they all have 2 departments and 2 join dates that make 311 as the difference im kind of curious as what this will do
ayylmao123xdd
ayylmao123xdd2mo ago
yes
Runger
RungerOP2mo ago
OH SHIT I FIGURED IT OUT i know what its testing now its not looking for departments its looking for how many employees are cross appointed so CROSS=311 is NOT refering to the days between join dates but the number of employees that have 2 or more departments
ayylmao123xdd
ayylmao123xdd2mo ago
yes thats what i meant you need 311 employees with 2 or more dept and then if you ahrdcore that
Runger
RungerOP2mo ago
yes okay i got it now lemme keep testing i got an idea
ayylmao123xdd
ayylmao123xdd2mo ago
okok
Runger
RungerOP2mo ago
i got the test case to pass by hard coding it but i dont think it will hold for future test cases
ayylmao123xdd
ayylmao123xdd2mo ago
ok so its a problem with saving show code
Runger
RungerOP2mo ago
this is what i changed but i can share the enitre file if you want
No description
Runger
RungerOP2mo ago
here is the updated file
Runger
RungerOP2mo ago
and also the result
No description
ayylmao123xdd
ayylmao123xdd2mo ago
ok so its clearly something with this add emp data
Runger
RungerOP2mo ago
yeah
ayylmao123xdd
ayylmao123xdd2mo ago
hm
if(e == -1) // If the employee id doesn't exist, then add the employee to the employee object list
{
emp_obj_list.add(temp);
}
if(e == -1) // If the employee id doesn't exist, then add the employee to the employee object list
{
emp_obj_list.add(temp);
}
this part is interesting because it doesnt create a department here right so if its the first time looping the employee doesnt get assigned a department is that how its supposed to work
Runger
RungerOP2mo ago
im not sure, but it seems like it should be getting a department when its added to the list
ayylmao123xdd
ayylmao123xdd2mo ago
what if you add creating a department here oh wait yea try that like create department and add to temp maybe its gonna work cuz the otehr loop seems fine for the most part
Runger
RungerOP2mo ago
im checking that now it still outputs CROSS=0 something is going on with the adding of departments like when i forced the case to pass, i had three statements telling it to add a department
ayylmao123xdd
ayylmao123xdd2mo ago
o can you go back to that hardcore part and add a print in each of these three things and check which one it was calling
Runger
RungerOP2mo ago
yeah
ayylmao123xdd
ayylmao123xdd2mo ago
or with just a debugger idk whichever u want
Runger
RungerOP2mo ago
okay, so looking at the output(i printed the size of the list at each of the calls) it seems that this should be running properly, it calls the first two (one at the very begining and the second when adding to the list) and the size is correct and the third one is called when it is supposed to be called, so it looks like every thing should be good
ayylmao123xdd
ayylmao123xdd2mo ago
most important word should :GnuTrolling: actually now that im thinking i dont think this temp object is saved to any list
Runger
RungerOP2mo ago
oh yeah
ayylmao123xdd
ayylmao123xdd2mo ago
and maybe thats why i guess like you got this here right
public void print_cross_emp()
{
int record = 00;

for(int i = 0; i < emp_obj_list.size(); i++) // Loops through the employee object list
{
Employee temp = new Employee(emp_obj_list.get(i).get_fName(), emp_obj_list.get(i).get_lName());
Department dep = new Department(temp.get_fName(), temp.get_lName());

if (temp.get_depLst().size() > 1) // If the employee has more than one department, then print out the required statement
{
record++;
System.out.println("Record " + record + " found! " + temp.toString() + " Appointments found: \n");
for(int j = 0; j < temp.get_depLst().size(); j++)
{
System.out.println(dep.toString() + "\n");
}
}
}
}
public void print_cross_emp()
{
int record = 00;

for(int i = 0; i < emp_obj_list.size(); i++) // Loops through the employee object list
{
Employee temp = new Employee(emp_obj_list.get(i).get_fName(), emp_obj_list.get(i).get_lName());
Department dep = new Department(temp.get_fName(), temp.get_lName());

if (temp.get_depLst().size() > 1) // If the employee has more than one department, then print out the required statement
{
record++;
System.out.println("Record " + record + " found! " + temp.toString() + " Appointments found: \n");
for(int j = 0; j < temp.get_depLst().size(); j++)
{
System.out.println(dep.toString() + "\n");
}
}
}
}
like idk in the method add emp data it creates a temp employee and doesnt save it anywhere and here it loops through emp obj list and this dep thing is kinda weird cuz for every department in an employee it prints the first like the one initialized above the loop
Runger
RungerOP2mo ago
should i start adding to the emp_obj_list instead of an instance object?
ayylmao123xdd
ayylmao123xdd2mo ago
Employee temp = new Employee(emp_obj_list.get(i).get_fName(), emp_obj_list.get(i).get_lName());
Department dep = new Department(temp.get_fName(), temp.get_lName());

if (temp.get_depLst().size() > 1) // If the employee has more than one department, then print out the required statement
{
record++;
System.out.println("Record " + record + " found! " + temp.toString() + " Appointments found: \n");
for(int j = 0; j < temp.get_depLst().size(); j++)
{
System.out.println(dep.toString() + "\n");
}
}
Employee temp = new Employee(emp_obj_list.get(i).get_fName(), emp_obj_list.get(i).get_lName());
Department dep = new Department(temp.get_fName(), temp.get_lName());

if (temp.get_depLst().size() > 1) // If the employee has more than one department, then print out the required statement
{
record++;
System.out.println("Record " + record + " found! " + temp.toString() + " Appointments found: \n");
for(int j = 0; j < temp.get_depLst().size(); j++)
{
System.out.println(dep.toString() + "\n");
}
}
check this here first i think like i think it should print each department not dep each time you have some department idk tho rn it prints the same department over and over
Runger
RungerOP2mo ago
yeah thats another thing i have to get to
ayylmao123xdd
ayylmao123xdd2mo ago
yea check that here first
Runger
RungerOP2mo ago
im just gonna go grab some water real quick, ill be back in like 2 minutes and ill try that out okay so im just gonna try and use the emp_obj_list directly instead of using temp?
ayylmao123xdd
ayylmao123xdd2mo ago
first fix this part
public void print_cross_emp()
{
int record = 00;

for(int i = 0; i < emp_obj_list.size(); i++) // Loops through the employee object list
{
Employee temp = new Employee(emp_obj_list.get(i).get_fName(), emp_obj_list.get(i).get_lName());
Department dep = new Department(temp.get_fName(), temp.get_lName());

if (temp.get_depLst().size() > 1) // If the employee has more than one department, then print out the required statement
{
record++;
System.out.println("Record " + record + " found! " + temp.toString() + " Appointments found: \n");
for(int j = 0; j < temp.get_depLst().size(); j++)
{
//this keeps printing the same department over and over
//Department dep = new Department(temp.get_fName(), temp.get_lName());
System.out.println(dep.toString() + "\n");
}
}
}
}
public void print_cross_emp()
{
int record = 00;

for(int i = 0; i < emp_obj_list.size(); i++) // Loops through the employee object list
{
Employee temp = new Employee(emp_obj_list.get(i).get_fName(), emp_obj_list.get(i).get_lName());
Department dep = new Department(temp.get_fName(), temp.get_lName());

if (temp.get_depLst().size() > 1) // If the employee has more than one department, then print out the required statement
{
record++;
System.out.println("Record " + record + " found! " + temp.toString() + " Appointments found: \n");
for(int j = 0; j < temp.get_depLst().size(); j++)
{
//this keeps printing the same department over and over
//Department dep = new Department(temp.get_fName(), temp.get_lName());
System.out.println(dep.toString() + "\n");
}
}
}
}
Runger
RungerOP2mo ago
okay
ayylmao123xdd
ayylmao123xdd2mo ago
also can you add some print here to check if there is actually any employee with more than one department
if (temp.get_depLst().size() > 1) // If the employee has more than one department, then print out the required statement
{
System.out.println("test");
record++;
System.out.println("Record " + record + " found! " + temp.toString() + " Appointments f
if (temp.get_depLst().size() > 1) // If the employee has more than one department, then print out the required statement
{
System.out.println("test");
record++;
System.out.println("Record " + record + " found! " + temp.toString() + " Appointments f
if it doesnt print at all then yea it doesnt grab the departments from the list and i think if it wont print here then i might know the actual cause now
Runger
RungerOP2mo ago
i dont think it will print because im not sure if thats the method being called yeah, it didnt print
ayylmao123xdd
ayylmao123xdd2mo ago
interesting and you checked the cross 311 test yes
Runger
RungerOP2mo ago
yes
ayylmao123xdd
ayylmao123xdd2mo ago
hmmmmm
public void print_cross_emp()
{
System.out.println("test");
int record = 00;

for(int i = 0; i < emp_obj_list.size(); i++) // Loops through the employee object list
{
Employee temp = new Employee(emp_obj_list.get(i).get_fName(), emp_obj_list.get(i).get_lName());
Department dep = new Department(temp.get_fName(), temp.get_lName());

if (temp.get_depLst().size() > 1) // If the employee has more than one department, then print out the required statement
{
record++;
System.out.println("Record " + record + " found! " + temp.toString() + " Appointments found: \n");
for(int j = 0; j < temp.get_depLst().size(); j++)
{
System.out.println(dep.toString() + "\n");
}
}
}
}
public void print_cross_emp()
{
System.out.println("test");
int record = 00;

for(int i = 0; i < emp_obj_list.size(); i++) // Loops through the employee object list
{
Employee temp = new Employee(emp_obj_list.get(i).get_fName(), emp_obj_list.get(i).get_lName());
Department dep = new Department(temp.get_fName(), temp.get_lName());

if (temp.get_depLst().size() > 1) // If the employee has more than one department, then print out the required statement
{
record++;
System.out.println("Record " + record + " found! " + temp.toString() + " Appointments found: \n");
for(int j = 0; j < temp.get_depLst().size(); j++)
{
System.out.println(dep.toString() + "\n");
}
}
}
}
can you a test at the top to see if its being called at all
Runger
RungerOP2mo ago
i dont think it is but yeah sure, its worth a try still didnt print i think its only calling add_emp_data
ayylmao123xdd
ayylmao123xdd2mo ago
ok so remind me did it print any departments here
// here temp departments
System.out.println(temp.get_fName() + " " + temp.get_lName());
date_diff(findEmpIdByName(temp.get_fName(), temp.get_lName()));
// here temp departments
System.out.println(temp.get_fName() + " " + temp.get_lName());
date_diff(findEmpIdByName(temp.get_fName(), temp.get_lName()));
Runger
RungerOP2mo ago
no, that just printed the first and last name of the employee and then "Employee is not cross-appointed" for every single one
ayylmao123xdd
ayylmao123xdd2mo ago
no i meant when you added the print for temp get dept list size
Runger
RungerOP2mo ago
okay hold on no
ayylmao123xdd
ayylmao123xdd2mo ago
you got 0 or some other number
Runger
RungerOP2mo ago
when I changed print_cross_emp()?
ayylmao123xdd
ayylmao123xdd2mo ago
no i mean like you did here but instead of emp2 temp.get dep list size what does it print always 0 or 1
Runger
RungerOP2mo ago
up there is was only ever printing 0 i tried it again and it is only printing 1
ayylmao123xdd
ayylmao123xdd2mo ago
Department dep2 = new Department(emp_rows.get(j).get(2), emp_rows.get(j).get(3));
temp.add_dept(dep2);
System.out.println(temp.get_depLst().size() + "case2");
}
}
}
System.out.println(temp.get_depLst().size() + "case3");
System.out.println(temp.get_fName() + " " + temp.get_lName());
date_diff(findEmpIdByName(temp.get_fName(), temp.get_lName()));
System.out.println("\n");
}
System.out.println(emp_obj_list.size() + " unique employees added to the database.");
}
Department dep2 = new Department(emp_rows.get(j).get(2), emp_rows.get(j).get(3));
temp.add_dept(dep2);
System.out.println(temp.get_depLst().size() + "case2");
}
}
}
System.out.println(temp.get_depLst().size() + "case3");
System.out.println(temp.get_fName() + " " + temp.get_lName());
date_diff(findEmpIdByName(temp.get_fName(), temp.get_lName()));
System.out.println("\n");
}
System.out.println(emp_obj_list.size() + " unique employees added to the database.");
}
so if you ran this case3 always prints 1 yes and case2 printed 1 too or 2 i forgot or case2 never prints
Runger
RungerOP2mo ago
case 3 prints 1 and seems to be constant with all the employees and case 2 does print sometimes but it also prints 1 and it still says the employee is not cross appointed
ayylmao123xdd
ayylmao123xdd2mo ago
case2 should technically always print 2 or more
Runger
RungerOP2mo ago
yeah
ayylmao123xdd
ayylmao123xdd2mo ago
because at the top of the method you got the first add department
Runger
RungerOP2mo ago
No description
Runger
RungerOP2mo ago
this is the output or some of it
ayylmao123xdd
ayylmao123xdd2mo ago
im wondering why case2 prints 1
Runger
RungerOP2mo ago
so i had changed that so that is was adding when i was adding the temp to the emp_obj_list, i added it back in at the top and ran it again and now when ever there is a case 2, both case 2 and 3 print 2 but they are still not cross appointed
ayylmao123xdd
ayylmao123xdd2mo ago
so 2 departments but not cross appointed can you show code
Runger
RungerOP2mo ago
No description
Runger
RungerOP2mo ago
No description
ayylmao123xdd
ayylmao123xdd2mo ago
so you named dep to dep3 and now it works wt f lmao i mean now it pritns 2 departments
Runger
RungerOP2mo ago
yeah its still not passing the test case for some reason though i wonder if something is happening once it exits the loop
ayylmao123xdd
ayylmao123xdd2mo ago
uhhh interesting
public void date_diff(String empId)
{
long date = date_diff_value(empId);

if (date == -1) // If the employee id is not found or is not apart of more than 1 department, print "employee not found!"
{
System.out.println("Employee not found!");
}
else if (date == -2)
{
System.out.println("Employee is not cross-appointed.");
}
else // Otherwise, print the difference between join dates of departments
{
System.out.println("Difference between cross-appointments (in days) is: " + date);
}


}
public void date_diff(String empId)
{
long date = date_diff_value(empId);

if (date == -1) // If the employee id is not found or is not apart of more than 1 department, print "employee not found!"
{
System.out.println("Employee not found!");
}
else if (date == -2)
{
System.out.println("Employee is not cross-appointed.");
}
else // Otherwise, print the difference between join dates of departments
{
System.out.println("Difference between cross-appointments (in days) is: " + date);
}


}
can you add something here to check whether the employee id here and in the add emp data is actually the same
Runger
RungerOP2mo ago
yeah sure the IDs are the same
ayylmao123xdd
ayylmao123xdd2mo ago
ok ig ill just run it locally to test
Runger
RungerOP2mo ago
wait they are different when they have 2 or more departments
ayylmao123xdd
ayylmao123xdd2mo ago
huh now thats interesting
Runger
RungerOP2mo ago
maybe thats why its messing up
ayylmao123xdd
ayylmao123xdd2mo ago
most likely tbh what if you change date diff
Runger
RungerOP2mo ago
i think when they have more than 1 department, when I am giving the id to date_diff, i am giving the id from when they first appeared in the list
ayylmao123xdd
ayylmao123xdd2mo ago
date_diff(temp.get_emp_id());
date_diff(temp.get_emp_id());
to this because previously it was checking by first name and last name
Runger
RungerOP2mo ago
okay we have change the ids are the same but instead of "employee is not cross-appointed" it says "employee not found"
ayylmao123xdd
ayylmao123xdd2mo ago
wait how do you actually grab the employee id nvm its generated
Runger
RungerOP2mo ago
it basically just numbers the employees from 0001 - 1000 it also seems that when the employee id isnt found, the id number isn't increased, which means it repeats the id sometimes
ayylmao123xdd
ayylmao123xdd2mo ago
yea somethings wrong with this id thing adding department seems to be ok then
Runger
RungerOP2mo ago
yeah
ayylmao123xdd
ayylmao123xdd2mo ago
maybe its because it loops by dict size and by default the employee id is 0 and if it finds an employee that isnt in the objects yet it gives it 0 again or something
Runger
RungerOP2mo ago
i think that everytime i make a new employee object, i am making a new id, so i need to make sure that when an employee already exists, im not changing the id
ayylmao123xdd
ayylmao123xdd2mo ago
oh yea because you got this
public Employee(String fName, String lName)
{
empId = getNextEmpId();

set_fName(fName);
set_lName(lName);

depLst = new ArrayList<Department>();
}
public Employee(String fName, String lName)
{
empId = getNextEmpId();

set_fName(fName);
set_lName(lName);

depLst = new ArrayList<Department>();
}
maybe here you need the uhhhh find emp id by name method like if that first name and last name is already registered you assign the same id but if not you get the next id i guess
Runger
RungerOP2mo ago
ah okay i got it one sec
ayylmao123xdd
ayylmao123xdd2mo ago
idk im guessing lmao
Runger
RungerOP2mo ago
arent we all i think i might need to put a check in when im adding the departments, like if the employee already exists, search by the name and revert the id to the old one
ayylmao123xdd
ayylmao123xdd2mo ago
perhaps like i think this employee id is messing most of the code
Runger
RungerOP2mo ago
seems like it
ayylmao123xdd
ayylmao123xdd2mo ago
try with fixing the employee id first ig and then department
Runger
RungerOP2mo ago
yeah
ayylmao123xdd
ayylmao123xdd2mo ago
did it work
Madjosz
Madjosz2mo ago
Wow 300+ messages. You really want that silver helper role.
Runger
RungerOP2mo ago
still trying to figure it out
ayylmao123xdd
ayylmao123xdd2mo ago
can you give me like some test data so i can run the code locally
Runger
RungerOP2mo ago
like a file similar to the csv file?
ayylmao123xdd
ayylmao123xdd2mo ago
i wanted to fill emp rows with data so i can run the add emp data so i need some rows for that ig
Runger
RungerOP2mo ago
i dont really know what the file looks like, but this is the closest thing i have. its just a print out of what is read from the given file. the first number is skipped and not added to emp_rows. i also added the current version of the file
ayylmao123xdd
ayylmao123xdd2mo ago
ok im just gonna steal that part u sent and see if its gonna recognize it ok i made it work basically the problem was that you were inserting an employee each time to the list instead of finding an employee in the list first if it exists so the fix is search for employee in the object list if it exists add the department from the line lol simple fix let me paste the code
Runger
RungerOP2mo ago
Thanks so much
JavaBot
JavaBot2mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Runger
RungerOP2mo ago
I just got kicked out of the room I was in because it was booked for a lab so I’m in the middle of heading back to my house
ayylmao123xdd
ayylmao123xdd2mo ago
public void add_emp_data() {
for (int i = 0; i < dict_size(); i++) {
Employee e = null;
if (emp_exists(emp_rows.get(i).get(1), emp_rows.get(i).get(2)) != -1) {
int finalI = i;
Employee employee = emp_obj_list.stream().filter(o -> Objects.equals(o.get_emp_id(), findEmpIdByName(emp_rows.get(finalI).get(1), emp_rows.get(finalI).get(2)))).findFirst().orElse(null);
e = employee;
Employee.decrementEmpID();
// Find ALL locations that there is a repeating employee name and add ALL of the departments to that employee
Department dep = new Department(emp_rows.get(i).get(3), emp_rows.get(i).get(4));
employee.add_dept(dep);
}
else {
Employee temp = new Employee(emp_rows.get(i).get(1), emp_rows.get(i).get(2));
e = temp;
Department dep = new Department(emp_rows.get(i).get(3), emp_rows.get(i).get(4));
temp.add_dept(dep);
emp_obj_list.add(temp);
}
System.out.println(e.get_depLst().size() + "case3");
System.out.println(e.get_depLst());
System.out.println(e.get_fName() + " " + e.get_lName());
date_diff(e.get_emp_id());
System.out.println("\n");
}
System.out.println(emp_obj_list.size() + " unique employees added to the database.");
}
public void add_emp_data() {
for (int i = 0; i < dict_size(); i++) {
Employee e = null;
if (emp_exists(emp_rows.get(i).get(1), emp_rows.get(i).get(2)) != -1) {
int finalI = i;
Employee employee = emp_obj_list.stream().filter(o -> Objects.equals(o.get_emp_id(), findEmpIdByName(emp_rows.get(finalI).get(1), emp_rows.get(finalI).get(2)))).findFirst().orElse(null);
e = employee;
Employee.decrementEmpID();
// Find ALL locations that there is a repeating employee name and add ALL of the departments to that employee
Department dep = new Department(emp_rows.get(i).get(3), emp_rows.get(i).get(4));
employee.add_dept(dep);
}
else {
Employee temp = new Employee(emp_rows.get(i).get(1), emp_rows.get(i).get(2));
e = temp;
Department dep = new Department(emp_rows.get(i).get(3), emp_rows.get(i).get(4));
temp.add_dept(dep);
emp_obj_list.add(temp);
}
System.out.println(e.get_depLst().size() + "case3");
System.out.println(e.get_depLst());
System.out.println(e.get_fName() + " " + e.get_lName());
date_diff(e.get_emp_id());
System.out.println("\n");
}
System.out.println(emp_obj_list.size() + " unique employees added to the database.");
}
the code is mega ugly rn but you can clean it up and for this data uh cant paste all
emp_rows.add(new ArrayList<>(Arrays.asList("28", "Armani", "Bean", "Law", "2020-04-05")));
emp_rows.add(new ArrayList<>(Arrays.asList("46", "Armani", "Bean", "Biology", "2000-08-10")));
emp_rows.add(new ArrayList<>(Arrays.asList("28", "Armani", "Bean", "Law", "2020-04-05")));
emp_rows.add(new ArrayList<>(Arrays.asList("46", "Armani", "Bean", "Biology", "2000-08-10")));
Difference between cross-appointments (in days) is: 7178
Difference between cross-appointments (in days) is: 7178
oh yea btw department id keeps showing me 0
dpNames = new ArrayList<String>();
dpIds = new ArrayList<Integer>();

for (int i = 0; i < dpNames.size(); i++) {
String index = dpNames.get(i);

if (index.equals(depName)) // finds the department id
{
depId = dpIds.get(i);
} else // creates a new id and adds the name
{
int newId = getNextDepID();
dpIds.add(newId);

dpNames.add(depName);
}
}
dpNames = new ArrayList<String>();
dpIds = new ArrayList<Integer>();

for (int i = 0; i < dpNames.size(); i++) {
String index = dpNames.get(i);

if (index.equals(depName)) // finds the department id
{
depId = dpIds.get(i);
} else // creates a new id and adds the name
{
int newId = getNextDepID();
dpIds.add(newId);

dpNames.add(depName);
}
}
because here its looping over an empty list
Runger
RungerOP2mo ago
I’ll copy it once I’m able to get back on my computer
ayylmao123xdd
ayylmao123xdd2mo ago
but that shouldnt be needed for the test to pass oh yea i changed the employee exists to take first name and last name for arguments instead of the whole class but u need to change like 3 lines there
JavaBot
JavaBot2mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?