• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Unable to understand what exercise wants?

 
Ranch Hand
Posts: 43
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Guys!  I have a little confusion here. Can anyone explain what´s exercise wants from me ? The two last  sentence of the context is hard to understand.

Thanks !

Your task is to complete the program by writing two classes (SmallException and BigException) and two methods to the ownException class (printErrorReport and testValue). SmallException and BigException are individual exception classes deriving from Exception class. Both classes require a constructor that receives a String object as parameter. Parameter is used to relay an informative message with the exception. Parameter is relayed to the superclass constructor. printErrorReport method receives the exception as a parameter and prints the error report of the exception using getMessage method. testValue method receives the tested number as a parameter. If the number is lower than five, method throws the SmallException and parameter is the message: Value is lower than 5. If the number is higher than 10, method throws the BigException and parameter is the message: Value is higher than 10.

 
Sheriff
Posts: 7616
522
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You misunderstood more than just last 2 sentences.

Instructions wrote:SmallException and BigException are individual exception classes deriving from Exception class.


Keit Koppel wrote:


These type of exercises are arguable in their usefulness, but apparently they test whether students can follow the requirements and do exactly what is being asked.

You failed at least on 2 points here:
1. Can't spell words as they are being asked. Asked: SmallException Achieved: smallException

For the second point, try to read requirements once again and find what is wrong.
 
Liutauras Vilda
Sheriff
Posts: 7616
522
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And need to say, that your code doesn't even compile.

The suggestion regarding that is: try to compile code after every written 2 lines of code, if possible - after every single line. Some parts of the code require having 2 lines of code to compile, so I'd say optimum is 2 at the beginning.

That way you'd know you made a mistake at earlier rather than later. That way also easier to fix mistakes, because you have to deal with less of them. That is important.

Please try to implement only SmallException class and post it here so we could verify whether you can follow requirements in general.
 
Liutauras Vilda
Sheriff
Posts: 7616
522
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to revise class notes. I never experienced the cases were you could get something for homework, but you never discussed similar cases in class, or never implemented in class something very similar, or never been shown a slide how that could be done.

If you still feel that some of the parts you struggle to understand even what they mean - try first to revise the notes. If these are of no help - contact instructor and raise the point that information supplied during the class is not sufficient to achieve given homework assignments.
 
Liutauras Vilda
Sheriff
Posts: 7616
522
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Instructions wrote:exception classes deriving from Exception class.


Do you understand what "deriving" means in this context?
 
Liutauras Vilda
Sheriff
Posts: 7616
522
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Saloon Keeper
Posts: 7175
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I find it useful to break requirements into bullet points, it makes it easier to follow directions line by line. In general you shouldn't go to the next item on the list till you've completed the current item. One thing not clear here is mention of a "ownException" class. This does not begin with an upper case letter as all classes should. It doesn't mention that this is a class you should create. Were you provided this class?

Your task is to complete the program by:
  • writing two classes (SmallException and BigException)
  • and two methods to the ownException class (printErrorReport and testValue).
  • SmallException and BigException are individual exception classes deriving from Exception class.
  • Both classes require a constructor that receives a String object as parameter.
  • Parameter is used to relay an informative message with the exception.
  • Parameter is relayed to the superclass constructor.
  • printErrorReport method receives the exception as a parameter and prints the error report of the exception using getMessage method.
  • testValue method receives the tested number as a parameter.
  • If the number is lower than five, method throws the SmallException and parameter is the message: Value is lower than 5.
  • If the number is higher than 10, method throws the BigException and parameter is the message: Value is higher than 10.
  •  
    Marshal
    Posts: 69411
    276
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Carey Brown wrote:. . . mention of a "ownException" class. . . .

    If that is anything like the lab exercises I used to have to do, it might mean that OP was supposed to create OwnException last week and now has to enhance it with those two methods. Otherwise OwnException might have been provided ready‑made.
    It might seem a rather trivial example with < 5 and > 10, but I think it is a useful introduction to inheritance with Exceptions. One of the places where inheritance is still very useful.
     
    Keit Koppel
    Ranch Hand
    Posts: 43
    Eclipse IDE Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I work my code a little and got these kind of results. I miss something I know ...


     
    Carey Brown
    Saloon Keeper
    Posts: 7175
    65
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    1) It won't compile.
    2) You seem to be throwing braces in randomly without knowing why you're doing it.
    3) printErrorReport method receives the exception as a parameter and prints the error report of the exception using getMessage method.
     
    Carey Brown
    Saloon Keeper
    Posts: 7175
    65
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Where is the "OwnException" class mentioned in the requirements?

    See how few braces you can use and get it to compile.

    SmallException and BigException are on the right track except for the braces.
     
    Carey Brown
    Saloon Keeper
    Posts: 7175
    65
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Liutauras Vilda wrote:And need to say, that your code doesn't even compile.

    The suggestion regarding that is: try to compile code after every written 2 lines of code, if possible - after every single line. Some parts of the code require having 2 lines of code to compile, so I'd say optimum is 2 at the beginning.

    That way you'd know you made a mistake at earlier rather than later. That way also easier to fix mistakes, because you have to deal with less of them. That is important.

    Please try to implement only SmallException class and post it here so we could verify whether you can follow requirements in general.

     
    Keit Koppel
    Ranch Hand
    Posts: 43
    Eclipse IDE Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I fix my code a little . I'm confused about the error report point. Can anybody give me some hints?

     
    Liutauras Vilda
    Sheriff
    Posts: 7616
    522
    Mac OS X VI Editor BSD Linux
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    No positive changes.

    You didn't take advice of placing braces correctly - that is not hard to get right, so really no excuse. If you don't understand what the braces do and what the purpose of them is, most likely this exercise is too advance for you. Why is too advance I don't know, possibly that you missed lots of classes or similar reasons.

    Please go and read this thread once again and find what you are missing.
     
    Carey Brown
    Saloon Keeper
    Posts: 7175
    65
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You would probably be better off using the Java style where matching braces are placed vertically, one over the other. It is much easier to line up matching braces this way.
     
    Carey Brown
    Saloon Keeper
    Posts: 7175
    65
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Carey Brown wrote:One thing not clear here is mention of a "ownException" class. This does not begin with an upper case letter as all classes should. It doesn't mention that this is a class you should create. Were you provided this class?

     
    Keit Koppel
    Ranch Hand
    Posts: 43
    Eclipse IDE Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Carey Brown wrote:

    Carey Brown wrote:One thing not clear here is mention of a "ownException" class. This does not begin with an upper case letter as all classes should. It doesn't mention that this is a class you should create. Were you provided this class?



    The ownException class is already created by the creator of the excersises my part is add more classes and methods like the exercise wants from me .
     
    Keit Koppel
    Ranch Hand
    Posts: 43
    Eclipse IDE Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    How is it possible to add two methods to the ownException class when I can't change the ownException class. This is under the questionmark right now.
     
    Carey Brown
    Saloon Keeper
    Posts: 7175
    65
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Carey Brown wrote:

  • printErrorReport method receives the exception as a parameter and prints the error report of the exception using getMessage method.
  • testValue method receives the tested number as a parameter.
  • If the number is lower than five, method throws the SmallException and parameter is the message: Value is lower than 5.
  • If the number is higher than 10, method throws the BigException and parameter is the message: Value is higher than 10.
  • These all need to be a part of the OwnException class or some other class that you create. The requirements are a bit vague on this so I'm assuming it is the OwnException class. Can you modify it?
     
    Keit Koppel
    Ranch Hand
    Posts: 43
    Eclipse IDE Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Carey Brown wrote:

    Carey Brown wrote:

  • printErrorReport method receives the exception as a parameter and prints the error report of the exception using getMessage method.
  • testValue method receives the tested number as a parameter.
  • If the number is lower than five, method throws the SmallException and parameter is the message: Value is lower than 5.
  • If the number is higher than 10, method throws the BigException and parameter is the message: Value is higher than 10.
  • These all need to be a part of the OwnException class or some other class that you create. The requirements are a bit vague on this so I'm assuming it is the OwnException class. Can you modify it?


    I can´t changet the ownException class which is already made by the person who create this excersises. I assume that I must create another ownException class then.
     
    Campbell Ritchie
    Marshal
    Posts: 69411
    276
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I think the bits you quoted about < 5 and > 10 are instructions about when to throw an exception and what argument to pass to its constructor. I think the bit about two additional methods means the OwnException.java file needs to be modified.
     
    Carey Brown
    Saloon Keeper
    Posts: 7175
    65
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Keit Koppel wrote:I can´t changet the ownException class which is already made by the person who create this excersises. I assume that I must create another ownException class then.


    If you make another class don't end the class name with the word "Exception". By Java convention these are reserved  for classes that inherit from Java's Exception class.
     
    Campbell Ritchie
    Marshal
    Posts: 69411
    276
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I still think OP has misunderstood the exercise and OwnException should be an exception class and it should be possible to amend it. I can guess what OwnException looks like:-
     
    Liutauras Vilda
    Sheriff
    Posts: 7616
    522
    Mac OS X VI Editor BSD Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Instructions wrote:Your task is to complete the program by writing two classes (SmallException and BigException) and two methods to the ownException class (printErrorReport and testValue).


    Well, instructions sound pretty clear to me. However, since it is spelled ownException (first lower case) - there might be the case that you made your own interpretation of instructions and decided to improvise, which also often happens with students.

    Keit Koppel wrote:I can´t changet the ownException class which is already made by the person who create this excersises.


    That is something inconsistent with what you posted as the instructions at the beginning, isn't it?

    I'd say delete all the code you have and go back to your teacher and get the exact instructions first. What is the point of solving something if it isn't clear what to do even?
     
    Keit Koppel
    Ranch Hand
    Posts: 43
    Eclipse IDE Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    This is the whole code of the excerisise. I try to but the printErrorReport and testvalue method to the ownException class but eclipse give me some errors. I try to figure out where I can put them.

     
    Campbell Ritchie
    Marshal
    Posts: 69411
    276
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    How much of that code did you write yourself and how much were you given?
    Why are BigException and SmallException apparently inner classes? And OwnException appears to be an inner class in ownException Didn't you tell Eclipse to create those classes separately?
    Don't catch input mismatch exceptions. Use the method shown here, which can be relied upon never to throw an input mismatch exception.
    You are not doing anything in the testValue method called from line 22, and that method doesn't declare that it might throw any Exceptions, so the catch block can never be executed. That is why you are getting those errors.
     
    Keit Koppel
    Ranch Hand
    Posts: 43
    Eclipse IDE Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Campbell Ritchie wrote:How much of that code did you write yourself and how much were you given?
    Why are BigException and SmallException apparently inner classes? And OwnException appears to be an inner class in ownException Didn't you tell Eclipse to create those classes separately?
    Don't catch input mismatch exceptions. Use the method shown here, which can be relied upon never to throw an input mismatch exception.
    You are not doing anything in the testValue method called from line 22, and that method doesn't declare that it might throw any Exceptions, so the catch block can never be executed. That is why you are getting those errors.



    My part is line 33 till to the end .
     
    Liutauras Vilda
    Sheriff
    Posts: 7616
    522
    Mac OS X VI Editor BSD Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Keit Koppel wrote:My part is line 33 till to the end .


    1. I must say it is getting annoying gradually.

    2. OwnException - you don't need that one, because there is created ownException by the instructor (who also needs to revise Java naming conventions).

    3. Small and Big exceptions shouldn't be inner classes of ownException class which is written by the instructor.
    3.1 There shouldn't be no-arg constructors in them - mainly because it isn't specified in requirements.

    4. You need to implement methods printErrorReport(), testValue() from/within the ownException class. That is why they are there and that is why instructions are saying so to implement them, basically that is the point of exercise.
     
    Greenhorn
    Posts: 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Here is the Code
    Probably I'm taking the same very badly organized course but with extra knowledge I've managed to solve that task
     
    Campbell Ritchie
    Marshal
    Posts: 69411
    276
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Welcome to the Ranch

    I am afraid that line 62  is incorrect.
     
    Self destruct mode activated. Instructions for deactivation encoded in this tiny ad.
    Devious Experiments for a Truly Passive Greenhouse!
    https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
      Bookmark Topic Watch Topic
    • New Topic