boys im kind of fucked here, this assignment is due tomorrow and I have been stuck on the same god damn test case for 3 days now. its not really a specific issue with the code itself and i have checked ALL of the possible issues and it just wont pass the damn test case. if anyone and i mean ANYONE wants to hop in a call and just look at the fucking mess of code i have it would be GREATLY APPRECIATED.
#Coding assignment for school
1 messages · Page 1 of 1 (latest)
<@&987246584574140416> please have a look, thanks.
Send the problem
i can send a screen shot of the question and what the output is but it would be much easier to explain it in a call i think
this is the code I have done, this project is being done through a website called moodle so I dont have the csv file needed to run it externally so i have to run it on the website. but the code looks the same
I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.
honestly it doesn't seem too bad just needs data parsing
But I have a feel you wrote this coding using AI
BROTHER WHATTTTT
am I mistaken
i have spent the past week and a half working on this code dudee im fucking tweaking
i wish i could use ai but i dont know what question to ask it in order for it to help me
its all in one file but there are seperate classes, also on the website moodle they cant make other files, its just one file with seperate classes
Yeah we use moodle too mb
its confusing to use so ive just been using another IDE and then copy and pasting the code
also what is data parsing?
parsing csv file
example:
John Doe 20
Jane Doe 17
Bob Doe 30
In order to read and work with that data, we create a simple Person class:
public class Person {
private final String firstName;
private final String lastName;
private final int age;
// Constructor, getter omitted
}
We want to read the file line by line, so we add a method parseLine to the Person class that, given a line, creates the corresponding Person:
public static Person parseLine(String line) {
String[] data = line.split(" ");
String firstName = data[0];
String lastName = data[1];
int age = Integer.parseLine(data[2]);
return new Person(firstName, secondName, age);
}
We read the file line by line, call parseLine and collect the resulting people into a List:
// Stream solution
List<Person> persons = Files.lines(Paths.get("myFile.txt"))
.map(Person::parseLine)
.collect(Collectors.toList());
// Classic solution
List<String> lines = Files.readAllLines(Paths.get("myFile.txt"));
List<Person> persons = new ArrayList<>();
for (String line : lines) {
persons.add(Person.parseLine(line));
}
We could now easily work with that data, for example increasing the age of John:
persons.get(0).setAge(25);
For updating the file, we add a toLine() method to Person:
public String toLine() {
return String.join(" ", firstName, lastName, String.valueOf(age));
}
Lastly, we create a list of the lines we want to write:
List<String> lines = persons.stream()
.map(Person::toLine)
.collect(Collectors.toList());
and write them back to the file:
Files.write(Paths.get("myFile.txt"), lines);
zabuzard • used /tag id: parseLine
·
(almost csv but u get the idea)
Yeah I didn't see the existing code b4
fair
theres a lot and its messy
all of the data is going where it needs to go but i think that my department list isnt being filled correctly, i just dont know how to fix it or where its going wrong
I see some problems
you re-init the lists
do java if (dpNames == null) { dpNames = new ArrayList<String>(); } if (dpIds == null) { dpIds = new ArrayList<Integer>(); } instead
oh man
thats really obvious now that im looking at it
i knew it was being emptied at some point and i didnt know why
I feel you implemented this whole class wrong
You are trying to make a singleton but you arent?
I would sort of seperate the logic
i dont know what a singleton is
ohh okay
I don't wanna make this more complex for no reason
i actually wanna know as much as I can because my lectures are just talking about the same stuff i learned in high school
Ok so if this was me
I would really just seperate everything
Nothing would be static
yeah i would too, but the class types are specified unfortunatly
oh yeah I forgot that mb
💀 this design is so bad they should let students design it
private static ArrayList<Integer> dpIds; // maintains a list of department IDs
private static ArrayList<String> dpNames; // maintains a list of department names - dpIds.get(i) corresponds to dpNames.get(i)```
I would most likely just DI this into classes
excuse my ignorance but what does DI stand for
also 1 more flaw I noticed
got it
You never write ArrayList<Integer> dpIds
Just do List<Integer>
But behind scenes it is an ArrayList
1 thing but it is more of a preference
public int get_dep_ip() {
return depId;
}``` is fine
i like putting the brackets on the line after because for me it is easier to see where the method starts and ends
like I said preference
does everything else look fine?
I can get slightly brutal if you want
go for it
I am not gonna say anything on design issues because we are incredibly handicapped by the question itself
real
are you asked to put these comments
yes
bruh
no one really puts comments like these
these are incredibly useless
if you really want to put an actual java doc
thats just me because in my frantic attempts to fix things, i forgot what other things did
and wanted to make sure i didnt for get them
I would maybe do
/**
* Increments and returns the next department ID.
*
* @return the next unique department ID
*/
public static int getNextDepID()
{
dpId++;
return dpId;
}````
you know that does actually look better
it is better.
/**
* Constructs a Department object with the specified name and join date.
* If a department with the given name already exists, uses its existing ID.
* Otherwise, creates a new unique ID for this department.
*
* @param depName the name of the department
* @param joinDate the date of joining in YYYY-MM-DD format
*/
public Department(String depName, String joinDate)
{```
you get the idea?
once im done getting this thing to actually work ill see about changing the comments because this stuff is crazy messy and stupid to read
are you explicitly told to put comments and java docs everywhere?
no one really puts docs on toString
idk i wrote most of the comments at like 2am last night
yes
public Department(String depName, String joinDate)
Department dep2 = new Department(emp_rows.get(j).get(2), emp_rows.get(j).get(3));
I have a feel this is putting employ name
should be 3 and 4?
nvm its correct
mb mb
emp_rows is a list of first names(0), last names(1), department name(2) and join date(3) i did not write the code to get that it was given to me
okay, well thanks for the help, i posted the question in another server and it seems they found something
nothing static should be your main goal.
subjective
@sage galleon How is your code currently? Do all tests pass, or is it still 1 test that fail
the number of day between first and last test
answer their question
If you do static code, you failed in your structure somehow and you will feel it later on.
It will be in twisted logic, or in weird bug.
i found out that it was testing for the number of employees who are cross appointed NOT how many days between certain start dates
Sometimes libraries require you to have static fields, they failed doesn't mean I failed
so i hard coded the correct response to see what would happen and thats where we are now
Create an instant from the dates
and calculate the difference in day between them.
Instant start = Instant.parse("2025-10-01T00:00:00Z");
Instant end = Instant.parse("2025-10-10T00:00:00Z");
long daysBetween = Duration.between(start, end).toDays();
The hard part is parsing your dates.
i think thats already happening but its using localDate
and i cant change that unfortunatly
what is the format of the dates in the csv?
yyyy-mm-dd