i failed and now i need to take a resit exam. This question was on the final exam and i feel like similar one will come on resit exam. We cant use our computers on the exam we have to write everything on paper so that was big issue i couldnt understand if im doing it wrong or right. Please be kind while answering because im new at java and i dont want to lose my hope i need to pass.
(i cant remember %100 but this was the main idea)
Q: In this question write two methods. First method should take two random variables. And second method should compare those two random variables and gives the result as higher one.
My solution:
import acm.program.*;
import acm.util.RandomGenerator;
public class RandomGenereratorBaby extends ConsoleProgram {
public RandomGenerator rgen = RandomGenerator.getInstance();{
int x = rgen.nextInt(0,9);
int y = rgen.nextInt(0,9);
}
public char BiggerOneWins (int x, int y){
if(x>=y){
return (char) (x) ;
}else{
return (char) (y);
}
}}
Please help me.
So my interpretation of the question says the method should be taking in the variables and storing them, not making some random numbers. So my solution would look something like this
I've also changed the return type to
intas returning ascharseemed a little odd. This is my interpretation of the question and the answer I would give. I hope that helps