Why? There is nothing to suggest that OP is using any JS.Mauro Trevigno wrote:I will recommend to do validation with Javascript. . . .
Campbell Ritchie wrote:
Why? There is nothing to suggest that OP is using any JS.Mauro Trevigno wrote:I will recommend to do validation with Javascript. . . .
Campbell Ritchie wrote:
Why? There is nothing to suggest that OP is using any JS.Mauro Trevigno wrote:I will recommend to do validation with Javascript. . . .
i should give a number from keyboard(userinput)
i should give a number from keyboard(userinput)
But 5 of it will be latinik albafet and to have 4 numbers (0 -9)
ekte spiriopoulos wrote:Hello , i have read exceptions but still i havent managed to understand what really and how to use them so i will make an explanation on my exercise if i understand it good .
i should give a number from keyboard(userinput) :String 9 length.But 5 of it will be latinik albafet and to have 4 numbers (0 -9).if the userinput is in right i will system.out this number if not i should make an exception * invalidNumberException.
* here what should i use ? method ? to create a class ? to make try { } catch{} .My mind here stuck
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
1) i can give a number(UserInput i use ) (scanner i dont know yet how to use it because i havent try with it)Les Morgan wrote:ekte,
Questions that amount to here is my assignment, please help me, rarely ever get the help you want, but specific questions usually get a quick and concise response. So let me break this down:
i should give a number from keyboard(userinput)
can you do that part? input from the keyboard? (quite often that is done using the Scanner class)
i should give a number from keyboard(userinput)
can you verify a Strings length? You can look up string methods in the String API
But 5 of it will be latinik albafet and to have 4 numbers (0 -9)
This is the, in my opinion, the more difficult part of the assignment. You will need to make a list of characters that you want to accept as input--make a String--so if I wanted to accept a-f and 0-4 , I would make the String "abcdef01234" and then check to see if each character in your input string is contained in your target String. This information is also contained in the String API.
So if any of your validations didn't pass, then you need to throw your Exception. You can look up Exception in the API also and see how to make a new Exception with your specific messages you want to have.
All of this needs to be wrappered in a new object of your design--a normal Java program.
So which part of this do you need help with?
ekte spiriopoulos wrote:Hello , i have read exceptions but still i havent managed to understand what really and how to use them so i will make an explanation on my exercise if i understand it good .
i should give a number from keyboard(userinput) :String 9 length.But 5 of it will be latinik albafet and to have 4 numbers (0 -9).if the userinput is in right i will system.out this number if not i should make an exception * invalidNumberException.
* here what should i use ? method ? to create a class ? to make try { } catch{} .My mind here stuck
i have lost it a little .I think to create an array of 5 int .And when array[0] will contain all characters from A-K. additional array[1] the same,array[2] //until array[5].Can it happen that somehow? i want userinput to give on the array[0] some of A-K .Is good my think?Campbell Ritchie wrote:ES: Why do you need an exception by that name? Have you looked through the different types of exception available to see whether there is something already available?
BR: Why did you suggest java.lang.Exception as the direct superclass of the new exception type? What is the drawback of that approach, which micht even make it an incorrect approach?
ES: Why can you make an int[] containing 'A', 'B' etc?
I am not sure I understand your question. You can of course check whether a char is in a certain range because a char is not a letter but a number. Do you want a 5‑element array containing values between 'A' and 'K' inclusive? Why do you want an array? What are you trying to do?ekte spiriopoulos wrote:. . . I think to create an array of 5 int .And when array[0] will contain all characters from A-K. additional array[1] the same,array[2] //until array[5].Can it happen that somehow? i want userinput to give on the array[0] some of A-K .Is good my think? . . .
Thats exactly i want to do to have the option for array[0] to have option between A-K and the others : array[1] to have A-K until array[5] its confusing.I need to use and userinput but i dont know where i could do that to have the choice between A-KCampbell Ritchie wrote:
I am not sure I understand your question. You can of course check whether a char is in a certain range because a char is not a letter but a number. Do you want a 5‑element array containing values between 'A' and 'K' inclusive? Why do you want an array? What are you trying to do?ekte spiriopoulos wrote:. . . I think to create an array of 5 int .And when array[0] will contain all characters from A-K. additional array[1] the same,array[2] //until array[5].Can it happen that somehow? i want userinput to give on the array[0] some of A-K .Is good my think? . . .
could you make an example what you mean? because i cant understand ( i have thought that it will be easy with array).Or do a similar example or send me an exercise if you could to understand what should i do in this caseCampbell Ritchie wrote:Why do you need that array of letters? It should be easy enough to fill by taking a 5‑letter input from the keyboard.
ekte spiriopoulos wrote:
could you make an example what you mean? because i cant understand ( i have thought that it will be easy with array).Or do a similar example or send me an exercise if you could to understand what should i do in this caseCampbell Ritchie wrote:Why do you need that array of letters? It should be easy enough to fill by taking a 5‑letter input from the keyboard.
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
i did this with exception but it doesnt work the exception when i press more than 60 .What I have wrongCampbell Ritchie wrote:ES: Why do you need an exception by that name? Have you looked through the different types of exception available to see whether there is something already available?
BR: Why did you suggest java.lang.Exception as the direct superclass of the new exception type? What is the drawback of that approach, which micht even make it an incorrect approach?
ES: Why can you make an int[] containing 'A', 'B' etc?
ekte spiriopoulos wrote:
i did this with exception but it doesnt work the exception when i press more than 60 .What I have wrongCampbell Ritchie wrote:ES: Why do you need an exception by that name? Have you looked through the different types of exception available to see whether there is something already available?
BR: Why did you suggest java.lang.Exception as the direct superclass of the new exception type? What is the drawback of that approach, which micht even make it an incorrect approach?
ES: Why can you make an int[] containing 'A', 'B' etc?
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
it worked now but its right now yes? i did it with exceptions not with IOexceptionLes Morgan wrote:That's because you never really throw an exception. You declare that an exception will be thrown in the method, but you never throw an exception. You need to make a false clause on your "if" statement and throw the exception there.
ekte spiriopoulos wrote:
i did this with exception but it doesnt work the exception when i press more than 60 .What I have wrongCampbell Ritchie wrote:ES: Why do you need an exception by that name? Have you looked through the different types of exception available to see whether there is something already available?
BR: Why did you suggest java.lang.Exception as the direct superclass of the new exception type? What is the drawback of that approach, which micht even make it an incorrect approach?
ES: Why can you make an int[] containing 'A', 'B' etc?
ekte spiriopoulos wrote:
it worked now but its right now yes? i did it with exceptions not with IOexceptionLes Morgan wrote:That's because you never really throw an exception. You declare that an exception will be thrown in the method, but you never throw an exception. You need to make a false clause on your "if" statement and throw the exception there.
ekte spiriopoulos wrote:
i did this with exception but it doesnt work the exception when i press more than 60 .What I have wrongCampbell Ritchie wrote:ES: Why do you need an exception by that name? Have you looked through the different types of exception available to see whether there is something already available?
BR: Why did you suggest java.lang.Exception as the direct superclass of the new exception type? What is the drawback of that approach, which micht even make it an incorrect approach?
ES: Why can you make an int[] containing 'A', 'B' etc?
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
he just say to do exceptions he doesnt care which one Anyway with this exception this worked .Thanks a lot and your adviceLes Morgan wrote:ekte,
you have 2 things wrong with your code: . . .
ekte spiriopoulos wrote:
he just say to do exceptions he doesnt care which one Anyway with this exception this worked .Thanks a lot and your adviceLes Morgan wrote:ekte,
you have 2 things wrong with your code: . . .
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
sorry i dont understand well what you want to tell me .I will start make better to do questions to understand things i have read exceptions and from book but maybe i have blanks in my head.So to confern some things.Campbell Ritchie wrote:Please don't quote the whole of the preceding post; that simply makes the thread longer. I have removed most of the quote.
We have an FAQ entitled, “It Doesn't Work Is Useless”. Maybe we should have one called “It Works Is Useless”, too . As LM has said, simply getting code to run does not mean there is anything good about it.
I am surprised if your instructor has given you such vague advice. You appear to have been told to create an InvalidNumberException. You were given some (I think not good) advice about how to create that. I suggested you do some looking around to find other Exceptions. Did you look through the tutorial which somebody gave you a link to? Now you appear to be using IOExceptions instead. Why? How did you get your teacher to tell you to use any kind of Exception?
No. That would only work in a simple case where you require the same response for all types of Exception. You would want a different response for an invalid number exception from an IO exception. In one case you might provide a new input, and in the other case you might have to check a network connection.ekte spiriopoulos wrote:. . .
1) I see from books and from links internet that exception replace ALL exceptions i mean arithmetik each.. is replace all if i use exception with nothing on it and there is no issue ,is this right?
You should probably not handle any exceptions in the main method; if an exception reaches the main method there is probably nothing you can do about it and you might as well simply propagate it. That assumes you have got the main method to a suitable size: one statement. You should handle all exceptions somewhere else. You should never throw an Exception and handle it inside the same method.2)i have a main ,the exceptions can i create inside in another class and to be inside in a method?After i can call it on my main(but there i will not have the try{}catch{} because i have it inside the method.I am right?
That question is really confusing because I think you have put all sorts of extraneous things in it, but I think it means, should you declare IndexOutOfBoundsException with a throws clause?3)if i dont use this exception and i want a name lets say an exception like that --> IndexOutOfBoundsException .I have a main class . I have a class Axn which i have this method and the name of my method is static void dAr(int a[]){ //here i have the try catch and inside the catch i have the name IndexOutOfBoundsException e and after a message with system.out}.Should i have the name static void dAr(int a[]) throws IndexOutOfBoundsException?or as i had previous?
You should always call an Exception class XYZException or ABCException or similar. The name should make it clear both that it is an Exception and also why it has occurred.4) Can i give on exceptions whatever name i want?this is right too?
Afraid not. You are declaring Exception which your method does not appear to throw at all. You are catching an Exception in the same place as you think it occurs. But I don't think that Exception can even occur there. The error message does not tell anybody what has done wrong. If you are the user, you will simply get a message. . . this is good right?
…and not know what it means. If you are programming, you will not know which part of the programming to correct.Error ....
ekte spiriopoulos wrote:i understand enough thanks a lot because something is my mind i didnt catch it well i bring a simple example Am i right? or i have understand it wrong?
So this arithmetic method i must replace it and to be in a different place(you mean class? )Campbell Ritchie wrote:Throwing the wrong Exception. You should throw an illegal argument exception; you should also explain in your documentation comments that only values ≥ 2 and ≤ 60 are permitted.
Once you throw that exception you should not catch it in the same place. Actually you should probably not catch that Exception at all.
i delete everything i start again because i lost it ..this i have it in main on the class in vehicle i have this 2 methods (one method and one method for exception) : hint : i am terrible wrong .The exception is the most difficult lesson ever .I have lost it at all.If it could be easy i want the steps for solve it ,example : 1) create a class 2) inside this create a method ..Something like that ,because i stuck i dont know what i am doing if is right or wrongCampbell Ritchie wrote:Throw a different Exception and do not catch it in the same method. When the Exception passes on to the other method, you will have to think what you can do about it there. If you get a complaint that the value was < 2 or > 60, can you do anything about it in that other method? Only you can work that out.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |