About parameters: How exactly do they work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

About parameters: How exactly do they work?

public class something{ Private final char choiceofthree; Private static final char one = 'a'; Private static final char two ='b'; Private Static final char three='c'; //left out a lot Public something(char choiceofthree){ //choiceofthree is supposed to be one of the three characters }} new something - > char as input needed But: choiceofthree was supposed to == one, two or three Problem: no test and to changing since final Solution: different non final parameter in head, then test, then assigning to final variable choiceofthree Conflict: changed this code, requirements that were given to me by the teacher Was that the right thing to do or is there another way? If I call a constructor or method with parameters it always wants input. But how do I handle it if that input has to meet certain requirements? When calling it, is it just "OK, leave it, the method will then do it and what comes in first doesn't matter"? The task is a questionnaire, so most of the parameters/variables refer to user input.

11th Jan 2020, 10:48 AM
Alisa Jääkarhu
Alisa Jääkarhu - avatar
3 Answers
0
My question is: why put a reference to a final variable in the head of anything callable if the input is neither testable nor changeable yet at the same time has to meet certain requirements? What are the assumptions? A) is the user intelligent and doesn't assign a wrong value B) different variable is needed and it's a test with a rough guideline?
11th Jan 2020, 11:20 AM
Alisa Jääkarhu
Alisa Jääkarhu - avatar
0
OK, then I got that right and giving out the code like this probably was a test? I handled it with a second variable "cot" that replaced choiceofthree as parameter in the signature and isn't final. I then test "cot" for the requirements and if they're met, choiceofthree is assigned the value of "cot"
11th Jan 2020, 11:42 AM
Alisa Jääkarhu
Alisa Jääkarhu - avatar
0
maybe you could handle the possible user error with using an exception (try...catch)
11th Jan 2020, 1:30 PM
Nonea
Nonea - avatar