Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Exception class in invalid

+8 votes
asked May 22, 2022 by לויט יהודה רובי (500 points)

https://onlinegdb.com/BuOWrpoJj

I'm working on exceptions and have a few errors on the same concept. Can someone please explain to me why isn't it working and how to fix it? thank you.

1 Answer

0 votes
answered May 22, 2022 by Peter Minarik (84,720 points)
edited May 23, 2022 by Peter Minarik

Check this out.

The following should help:

//import Exceptions.*;
import Exceptions.TooManyGradesException;
import Exceptions.GradeOutOfBoundException;
import Exceptions.GohstStudentException;
import Exceptions.NoGradesException;

It's pretty late here, I'll hit the bed. But the above should help you to move forward.

Good luck!

Update

I've got a bit of time now. :)

Apply the above change to the Classroom.java file. Also, add the following import:

import java.util.Arrays;

There's a problem with the NoGradesException.java file as well. Do not throw an exception there, instead call the constructor of the base class:

super("this student doesn't have a grade");

Packages...

I'm not a Java developer. But it seems like working with packages makes life complicated in OnlineGDB. If you use packages (apply the above fixes first), the compiler will be unable to initialize the Main class as it won't find all the dependencies (the Exceptions package). I don't know how to fix it. Most online resources talk about fixing your project, but we don't really have a project file here. Maybe it needs a compilation flag?

Anyway, a simple workaround is not to use packages when using OnlineGDB.

After this (and removing all the import Exceptions.?????) your code should run.

commented May 22, 2022 by לויט יהודה רובי (500 points)
I think I haven't understood you correctly with something written twice:

 "You can rename the class to something else (e.g. TooManyException2, do the constructor and the file too) and see if you still have the same problem. Magically, there will be a 2nd file with the same name. Rename it as well, fix your code and make sure only one such class exists."

Or is it that it didn't work?
commented May 23, 2022 by Peter Minarik (84,720 points)
That was my previous comment which I have updated to the one you saw above. Just ignore that old comment. :)
commented May 23, 2022 by לויט יהודה רובי (500 points)
I have checked it. it still doesn't work. although, it shows one mistake less when I wrote:

"import Exceptions.TooManyGradesException;"

the others didn't do anything.

"import Exceptions.GradeOutOfBoundException;
import Exceptions.GohstStudentException;
import Exceptions.NoGradesException;"
commented May 23, 2022 by Peter Minarik (84,720 points)
I've added an UPDATE section to the answer. Check it out.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...