Hi! I tried doing this, but i created an array for the questions and another one for the answers. At 12:13 I put it inside a for loop so i could do "new Questions(questionsarray[i], answersarray[i])" but then i can't do the "takeTest(questions)" part cause it doesn't recognize the questions variable. I tried inicializing it in other ways but there's always an error. How should i do it, any advice? Thanks
Hi Mike! You are doing absolutely amazing. Please keep up. I am going through all your tutorials however for this one I have a question. Would this be an example of abstraction or encapsulation? Under which OOPs principle this falls under? And how?
Does anybody know why if we use "==" instead of equals it doesn't work? It works with other strings, but for some reason (even though they print the same character) answer is not == questions[i].answer
Hi Mike, Great work with your Java tutorials. I was just wondering why you chose double quote for the answer a ("a") instead of single quotes ('a') since 'a' is a character.
Hey Thank you very much for this amazing Video! I have one question: why do we have given the Question the attribute prompt? What kind of purpose does it have?
How would you do this, if the questions are picking randomly because you I have to use math. random to make the computer pick out a random 10 questions from a total 20. How Would i make them check if the answer is right then? Because question 1 isnt the same question all the time
You would have to create 20 question objects. Since every object has their own prompt and answer , you just simply use Random class (google it, it's not hard to use) to random number in the range of 20 using nextInt() method and put it in the loop(so it will random new number everytime we pass the loop), in for loop you would use a random number as an index of the question array then do exactly like Mike did. And if you want the user to answer 10 questions, just tell for loop to loop 10 times. Hope this helps.
Hi thanks for the video! It is very useful seeing the colours so you can easily identify the connections among the objects. Are you using a specific version of Java ?
When you create an instance of the Question class, you made it an array. I wasn't aware that you could do that. Could you explain a bit more about creating class objects and using them as "data types"? I find it confusing.
Hi. You can do that by using while loop (eg. While(true) ) and set the condition like this. if (!keyboardInput.equals("a") || !keyboardInput.equals("b") || !keyboardInput.equals("c")) ). Remember that !a.equals(b) means "a is NOT equal to b" and || means "or". The code above is to check if the input is equal to a, b, c or not. If not, keep getting the input till the user input one of them. In the else statement put "break;" to exit the loop when the user input one of them.
thanks for your tutorial. I have a question: How do I put and else statement so, if the answer is wrong the system says: try again. Because the method is void and don't allow to introduce a return statement. I removed the void from the method and wrote the else return but doesnt work. Can you help please
Have you got the answer yet? If not, you don't have to return anything. You can just use System.out.println("try again"); to display the message. Only return something when you want to store it to use later.
THere may be a "clear" button/option in the program that you are using for the project, if not, you can try and code a method that will reset the test once you've done it (maybe add a counter for the number of times you've done it).
yes, you may have one class itself(personally consider it better), you do not have to create another. he might have created another class just for better understanding and to show how classes are used.
This feature would have to be part of your conditional. Example: if answer = questions[i.answer] println “String True!” Else println “String False, try again” or “String False, better luck next time” or stg like that....
Questions: lets say for question 1 the answer was “a”, will it give a wrong answer if the user entered “A”? Because I’m not sure if case-insensitivity was coded.
Yes it will. Inside for the for loop when you accept the answer, do this: "String answer = scanner.nextLine().toUpperCase();" // or ".toLowerCase()" depending on how you write the code.
I didn't understend very well the part of code of the parameters of takeTest. takeTest(questions); ^ public static void takeTest (Question [] questions) ^
error: non-static variable this cannot be referenced from a static context Question q[]={new Question(q1,"a"),new Question(q2,"b")}; ^ error: non-static variable this cannot be referenced from a static context Question q[]={new Question(q1,"a"),new Question(q2,"b")};
you are literally better at explaining code than my "professional" college prof. I feel like I should be paying you instead of him.
this is very creative. And extremely well explained. Thanks so much Mike.
Just found this gem of a tutorial, thank you it simple to understand! Im new to coding, this taught me a lot
Thanks for this video I managed to get most of my assignment done by following this :D
Well copying assignments doesn't make a good programmer !
Hi! I tried doing this, but i created an array for the questions and another one for the answers. At 12:13 I put it inside a for loop so i could do "new Questions(questionsarray[i], answersarray[i])" but then i can't do the "takeTest(questions)" part cause it doesn't recognize the questions variable. I tried inicializing it in other ways but there's always an error. How should i do it, any advice? Thanks
Can you put a tutorial on this similar topic but using ArrayList
alternate code:
public class mcq1 {
public static void main(String[] args) {
Scanner type = new Scanner(System.in);
int score=0;
String q1= "what color are apples?
"
+"(a)red
(b)blue
";
System.out.println(q1);
String ans1=type.nextLine();
if(ans1.equals("a")){
score++;
}
String q2= "what color are bananas?
"
+"(a)red
(b)yellow
";
System.out.println(q2);
String ans2=type.nextLine();
if(ans2.equals("b")){
score++;
}
System.out.println("you have scored:"+score+"/2");
}
}
Appreciate this man
Procedure way of writing in your future projects will you, fuck. Up.
appreciate this, gonna use this as a skeleton for my code
thank u so much!!
NGL you just made something so complicated seem so simple... Thank you :)
Yeah I notice that as wll
Hi,I have some problem creating 20 questions quiz game.I can't define my variable.can you help me with that.thanks!
this guy is awesome ,he makes everything look so easy!
thank you man you saved my ass
how to print the two strings (prompt and answer) together? System.out.print( questions[x].prompt,answer) did not work ?
Thank you, no seriously thank you, I just finished my assignment because of this
source code? your website does not display
you find it
or not
Hi! Can you please put out a tutorial on the same topic but in JFrames with designing
I'm Building a Quiz Management System using JFrame Form in netbeans if you're interested I'll let you see
Gaming Hype yes please
@@raomuhammadusama9244 pls share the System
great explanation 👏
Thank You! It is worth to have such video.
It helped me a lot.
Once again Thank You!.
Thanks for this tutorial, it greatly helped my output test!
I like the way you teach Java thank you very much you came to rescue me
Thanks for the tutorial! This is more understandable than how my prof teaches
how to make this questions with scoring in try-catch exceptions?
please help? How can i use if/else statement to allow user to run program multiple times, otherwise pressing any other key to exit?
I think you what you need is a do{ "your program" }while(statment for leaving the program);
use a loop rather
Is there a better way to do a questionnaire type thing that can accept user input and multiple-choice questions?
where is the code please send the link
Hi Mike! You are doing absolutely amazing. Please keep up. I am going through all your tutorials however for this one I have a question. Would this be an example of abstraction or encapsulation? Under which OOPs principle this falls under? And how?
Can you upload the Source code? Website is not showing it.
This really helps me a lot thank you so muchhh
Can you please tell me the codes to be used upon applying it to GUI
where can i get the source code
can i also do this on java n-ide app?
is this done on BlueJ ?
How to random the questions and answer?
Does anybody know why if we use "==" instead of equals it doesn't work?
It works with other strings, but for some reason (even though they print the same character) answer is not == questions[i].answer
Hello Mike ..Can we do the same in blue j ?
On the off chance you see this because this comment is almost 4 years late, I would like to let you know your series of c++ and java are fantastic.
thanksss for thisss, but my problem is that how to use the try catch method using this?
Thanks A lot For giving such code idea !
Hi Mike, Great work with your Java tutorials. I was just wondering why you chose double quote for the answer a ("a") instead of single quotes ('a') since 'a' is a character.
Im no pro here, and you probably know why already, but I think its because its a string and not a character.
ya me too, by using character we could've even saved up memory
Ok....now how to make those list of questions appear in random order?....
I couldn't find the source code for this exercise... Got a link to it somewhere?
How can I apply this code into GUI?
Thank you man. You should do a java tuotorial for beginners. Would be amazing.
Don't we need like setters and getters for these?
What is the difference between a class type and a primitive data type? I don't see the difference?
On which software is the code written ?
I added additional if statements to give different responses to varying scores.
How do I get the percentage?
Hey Thank you very much for this amazing Video! I have one question: why do we have given the Question the attribute prompt? What kind of purpose does it have?
This is awesome. Thank you very much.
is there a way that i can get these questions randomly ordered?
just enter the random function
How would you do this, if the questions are picking randomly because you I have to use math. random to make the computer pick out a random 10 questions from a total 20. How Would i make them check if the answer is right then? Because question 1 isnt the same question all the time
You would have to create 20 question objects. Since every object has their own prompt and answer , you just simply use Random class (google it, it's not hard to use) to random number in the range of 20 using nextInt() method and put it in the loop(so it will random new number everytime we pass the loop), in for loop you would use a random number as an index of the question array then do exactly like Mike did. And if you want the user to answer 10 questions, just tell for loop to loop 10 times. Hope this helps.
The plus signs are the only signs that have error can someone help me fix this problem?
You're great ,thanks sir.
can you tell me how to make the questions appear randomly please?
If i wanted to print a variable for a score how would i do that
score is the variable
How can i do that in 2d array?
Thank you, Please keep up creating new videos
Hi thanks for the video! It is very useful seeing the colours so you can easily identify the connections among the objects. Are you using a specific version of Java ?
he is using Eclipse, a program you use to write Java www.eclipse.org
you can change the colors in your own ide
When you create an instance of the Question class, you made it an array. I wasn't aware that you could do that. Could you explain a bit more about creating class objects and using them as "data types"? I find it confusing.
same, have you figured it our yet ?
what if i input other letter/number in the answer. i mean how can i repeat the question if i did that?
sorry for my english..
Hi. You can do that by using while loop (eg. While(true) ) and set the condition like this.
if (!keyboardInput.equals("a") || !keyboardInput.equals("b") || !keyboardInput.equals("c")) ).
Remember that !a.equals(b) means "a is NOT equal to b" and || means "or". The code above is to check if the input is equal to a, b, c or not. If not, keep getting the input till the user input one of them. In the else statement put "break;" to exit the loop when the user input one of them.
for such cases learn about "try and catch" it will make your code much better
Thank you. That was helpful
thanks for your tutorial. I have a question: How do I put and else statement so, if the answer is wrong the system says: try again. Because the method is void and don't allow to introduce a return statement. I removed the void from the method and wrote the else return but doesnt work. Can you help please
Have you got the answer yet?
If not, you don't have to return anything. You can just use System.out.println("try again"); to display the message. Only return something when you want to store it to use later.
use System.out.println("try again");
under else
use a while statement for it to loop back to make the user try again, but then it will loop until the user gets it correct
How to repeat or retake the quiz?
THere may be a "clear" button/option in the program that you are using for the project, if not, you can try and code a method that will reset the test once you've done it (maybe add a counter for the number of times you've done it).
How would I do this using JOption and Radio Buttons?? Anybody??
i am stuck please help
hey great video just wanted to ask what the reason to create another class. Can I just have one class for this program?
did u find the answer to ur question ?
yes, you may have one class itself(personally consider it better), you do not have to create another.
he might have created another class just for better understanding and to show how classes are used.
Which algorithm is used sir???
where is source code?
Hi Mike, how can I display true and false
This feature would have to be part of your conditional. Example: if answer = questions[i.answer] println “String True!” Else println “String False, try again” or “String False, better luck next time” or stg like that....
Which IDE best for java project?
eclipse
netbeans
I added messages to the score checker:
if(answer.equals(questions[i].answer)) {
System.out.println("Nice!");
score++;
}else {
System.out.println("Nope!");
}
Also added different messages depending on your score.
if(score == questions.length) {
System.out.println("You got " + score + " out of " + questions.length + "! Nice job!");
}else if(score < questions.length && score > 0) {
System.out.println("You got " + score + " out of " + questions.length + "! Not bad.");
} else {
System.out.println("You got " + score + " out of " + questions.length + "! That's a crap score!");
}
Questions: lets say for question 1 the answer was “a”, will it give a wrong answer if the user entered “A”? Because I’m not sure if case-insensitivity was coded.
Yes it will. Inside for the for loop when you accept the answer, do this: "String answer = scanner.nextLine().toUpperCase();" // or ".toLowerCase()" depending on how you write the code.
thank u , u saved my life
thank you so much Mike
it doesnt work
thanks for teaching us
your codes is error
I didn't understend very well the part of code of the parameters of takeTest.
takeTest(questions);
^
public static void takeTest (Question [] questions)
^
what would I do if I have multiple correct answers for 1 question
Add an extra choice letter, say like “d) all of the above” or “d) b and c are correct” - simplest answer possible
How would I do this using math.random
Same question here iwant the question to be in a random
U are a god for me brother
Why does he put another public class? What's the purpose of that?
Hi, can you please make a tutorial on the same topic but instead of for loop could you please do it in a try-catch block?
yo sameeeeeeed
great sir
2:10 that's a constructor not a method!!!
a constructor is a method.
thanks so much!
Error in line
public static void takeTest(Question[] questions){
I tried it but sadly, many errors occur 😩💔
hej, do You have github account or maybe sharing this code something oter way ?
Hey Eljan, unfortunately I don't have the code for this tutorial available anywhere! Thanks for the comment
Which algorithm is used?
tough questions you made there
This helped
This is OOP ??
error: non-static variable this cannot be referenced from a static context
Question q[]={new Question(q1,"a"),new Question(q2,"b")};
^
error: non-static variable this cannot be referenced from a static context
Question q[]={new Question(q1,"a"),new Question(q2,"b")};
How to this in cmd
Why do you want to run this in cmd? Might be a stupid question but it makes absolutely no sense to me
@@Digital-Shaman-Music true😂
Could you give me your Java code? xoxo, Luca
hello sir can you help me? please?
Can you make a vid for making a random question ?
nice
recommend watching at 1.5 speed.
mine got a lot of error i did what you did
I love you