Click here to Skip to main content
15,902,883 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have to do this in school yet it does not work!

What I have tried:

import java.util.Scanner;
public class LITTLEQUIZZ {
	public static void main( String[] args)
	{
		
		Scanner keyboard = new Scanner(System.in);
		
		String answer;
		
		int answer1, answer2, answer3 , answer4, answer5, answer6, answer7, answer8,answer9,answer10,answer11,answer12,answer13,answer14,answer15;
		int score=0;
		System.out.print("Are you ready for a quiz?");
		answer = keyboard.next();
		
		if(answer == "YES") System.out.println("Okay, here it comes!!!");
		else if (answer == "NO")
				System.out.println("Too late you are in!!!");
		
		System.out.println("Q1: What is the language spoken in Ireland"); /// NO 1
		
		System.out.println("1) Italian");
		
		System.out.println("2) Irish");
		
		System.out.println("3) English");
		
		System.out.println("4) Russian");
		
		System.out.println("5) French");
		
		System.out.println(">");
		answer1 = keyboard.nextInt();
		
		if(answer1==3)
		{
			System.out.println("That's right!");
			score+=1;
		}
		else if (answer1==1||answer1==2||answer1==4||answer1==5)
			System.out.println("Sorry, the language spoken in Ireland is English");
		else System.out.println("That wasn't an option!");
		
        
		
		System.out.println("Q2: Whats 5 mutliply by 5 divided by five minus 2 multipy by 20");///No2
		
		System.out.println("1) 30");
		
		System.out.println("2) 20");
		
		System.out.println("3) 3");
		
		System.out.println("4) 60");
		
		System.out.println("5) 100");
		
		System.out.println(">");
		answer2 = keyboard.nextInt();
		
		if(answer2==4)
		{
			System.out.println("That's right!");
			score+=1;
		}
		else if(answer2==1||answer2==2||answer2==3||answer2==5)
			System.out.println("Sorry the answer is 60");
		else System.out.println("That wasn't an option!");
		
		
		
	
        
		
		System.out.println("Q3: What is the most popular food in Italy");/// No 3
		
		System.out.println("1) Cheese");
		
		System.out.println("2) Spaghetti");
		
		System.out.println("3) Pizza");
		
		System.out.println("4) Burgers");
		
		System.out.println("5) Chips");
		
		System.out.println(">");
		answer3 = keyboard.nextInt();
		
		if(answer3==3)
		{
			System.out.println("That's right!");
			score+=1;
		}
		else if(answer3==1||answer3==5||answer3==2||answer3==4)
			System.out.println("Sorry the answer was Spaghetti and Pizza");
		else System.out.println("That wasn't an option!");
		
		
		
System.out.println("Q4: What is the Capital city o Croatia");/// No 4
		
		System.out.println("1) Osijek");
		
		System.out.println("2) Luxenburg");
		
		System.out.println("3) Zagreb");
		
		System.out.println("4) Rome");
		
		System.out.println("5) Moscov");
		
		System.out.println(">");
		answer4 = keyboard.nextInt();
		
		if(answer4==3)
		{
			System.out.println("That's right!");
			score+=1;
		}
		else if(answer4==1||answer4==5||answer4==4||answer4==2)
			System.out.println("Sorry the answer was Zagreb");
		else System.out.println("That wasn't an option!");
		
		
System.out.println("Q5: What is a Prime number");/// No 5
		
		System.out.println("1) 0");
		
		System.out.println("2) 6");
		
		System.out.println("3) 8");
		
		System.out.println("4) 29");
		
		System.out.println("5) 16");
		
		System.out.println(">");
		answer5 = keyboard.nextInt();
		
		if(answer5==4)
		{
			System.out.println("That's right!");
			score+=1;
		}
		else if(answer5==1||answer5==5||answer5==2||answer5==3)
			System.out.println("Sorry the answer was 29");
		else System.out.println("That wasn't an option!");
			
		
		
		
System.out.println("Q6 What is the average IQ:");/// No 6
		
		System.out.println("1) Between 80-100");
		
		System.out.println("2) Between 30-50");
		
		System.out.println("3) Between 20-40");
		
		System.out.println("4) Between 90-110");
		
		System.out.println("5) Between 80-120");
		
		System.out.println(">");
		answer6 = keyboard.nextInt();
		
		if(answer6==4)
		{
			System.out.println("That's right!");
			score+=1;
		}
		else if(answer6==1||answer6==5||answer6==2||answer6==3)
			System.out.println("Sorry the answer was  Between 90-110 ");
		else System.out.println("That wasn't an option!");
		

		
		
		System.out.println("Q7 Which a Marvel Here:");/// No 7
		
		System.out.println("1) Superman");
		
		System.out.println("2) Cat Woman");
		
		System.out.println("3) Daredevil");
		
		System.out.println("4) Capitan Cold");
		
		System.out.println("5) Lex Luther");
		
		System.out.println(">");
		answer7 = keyboard.nextInt();
		
		if(answer7==3)
		{
			System.out.println("That's right!");
			score+=1;
		}
		else if(answer7==1||answer7==5||answer7==2||answer7==4)
			System.out.println("Sorry the answer was Daredevil");
		else System.out.println("That wasn't an option!");
		
		
	
		
		
		System.out.println("Q8 How is my name spelled!!!:");/// No 8
		
		System.out.println("1) Cristi");
		
		System.out.println("2) Cristy");
		
		System.out.println("3) Christy");
		
		System.out.println("4) Kristi");
		
		System.out.println("5) Khristi");
		
		System.out.println(">");
		answer8 = keyboard.nextInt();
		
		if(answer8==1)
		{
			System.out.println("That's right!");
			score+=1;
		}
		else if(answer8==2||answer8==5||answer8==3||answer8==4)
			System.out.println("WHAT!!!!!! MY NAME IS CRISTI!!!!!YOU LOSE 5 Points");
				score=-5;
	
		
		
		
	    System.out.println("Q9 What is 1 above 2:");/// No 9
		
		System.out.println("1) 1/2");
		
		System.out.println("2) 2/1");
		
		System.out.println("3) 12");
		
		System.out.println("4) 21");
		
		System.out.println("5) 1,2");
		
		System.out.println(">");
		answer9 = keyboard.nextInt();
		
		if(answer9==1)
		{
			System.out.println("That's right!");
			score+=1;
		}
		else if(answer9==2||answer9==5||answer9==3||answer9==4)
			System.out.println("Sorry the answer is 1/2");
		else System.out.println("That wasn't an option!");
		
	   
		
		System.out.println("Q10 Which is a french word :");/// No 10
		
			System.out.println("1) Fluture");
			
			System.out.println("2) Buna");
			
			System.out.println("3) Lapte");
			
			System.out.println("4) Telefon");
			
			System.out.println("5) Agreable");
			
			System.out.println(">");
			answer10 = keyboard.nextInt();
			
			if(answer10==5)
			{
				System.out.println("That's right!");
				score+=1;
			}
			else if(answer10==2||answer10==1||answer10==3||answer10==4)
				System.out.println("Sorry the answer is Agreable");
			else System.out.println("That wasn't an option!");
			
			
			
			
			System.out.println("Q11 What is the Rathmines' principal's name:");/// No 11
			
			System.out.println("1) Brenadette Ó Maoilriain");
			
			System.out.println("2) Anna Morris ");
			
			System.out.println("3) Bernadette Moore");
			
			System.out.println("4) Carrol Hanney");
			
			System.out.println("5) Kelly Ó Ceallaigh");
			
			System.out.println(">");
			answer11 = keyboard.nextInt();
			
			if(answer11==3)
			{
				System.out.println("That's right!");
				score+=1;
			}
			else if(answer11==2||answer11==1||answer11==5||answer11==4)
				System.out.println("Sorry the answer is Bernadette Moore");
			else System.out.println("That wasn't an option!");
		
			
			
            System.out.println("Q12 What has legs but not feet:");/// No 12
			
			System.out.println("1) Worm");
			
			System.out.println("2) Snake ");
			
			System.out.println("3) Snail");
			
			System.out.println("4) Butterfly");
			
			System.out.println("5) Bat");
			
			System.out.println(">");
			answer12 = keyboard.nextInt();
			
			if(answer12==3)
			{
				System.out.println("That's right!");
				score+=1;
			}
			else if(answer12==2||answer12==1||answer12==5||answer12==4)
				System.out.println("Sorry the answer is Bernadette Moore");
			else System.out.println("That wasn't an option!");
		
		
		
		
		
            System.out.println("Q13 I fly without wings, I cry without eyes. What am I?:");/// No 13
			
			System.out.println("1) Plane");
			
			System.out.println("2) Human ");
			
			System.out.println("3) Bird");
			
			System.out.println("4) Cloud");
			
			System.out.println("5) Music");
			
			System.out.println(">");
			answer13 = keyboard.nextInt();
			
			if(answer13==4)
			{
				System.out.println("That's right!");
				score+=1;
			}
			else if(answer13==2||answer13==1||answer13==5||answer13==3)
				System.out.println("Sorry the answer is Bernadette Moore");
			else System.out.println("That wasn't an option!");
			
			
			
            System.out.println("Q14 I'm tall when I'm young, I'm short when I'm old. What am I?:");/// No 14
			
			System.out.println("1) Ciggarette");
			
			System.out.println("2) Pencil ");
			
			System.out.println("3) Candle");
			
			System.out.println("4) Life");
			
			System.out.println("5) Maths");
			
			System.out.println(">");
			answer14 = keyboard.nextInt();
			
			if(answer14==3)
			{
				System.out.println("That's right!");
				score+=1;
			}
			else if(answer14==2||answer14==1||answer14==5||answer14==4)
				System.out.println("Sorry the answer is Bernadette Moore");
			else System.out.println("That wasn't an option!");
			
			
            System.out.println("Q15 Feed me and I live, yet give me a drink and I die?:");/// No 15
			
			System.out.println("1) Smoke");
			
			System.out.println("2) Candle ");
			
			System.out.println("3) Fire");
			
			System.out.println("4) Lantern");
			
			System.out.println("5) Laser");
			
			System.out.println(">");
			answer15 = keyboard.nextInt();
			
			if(answer15==3)
			{
				System.out.println("That's right!");
				score+=1;
			}
			else if(answer15==2||answer15==1||answer15==5||answer15==4)
				System.out.println("Sorry the answer is Bernadette Moore");
			else System.out.println("That wasn't an option!");
		
		
		    System.out.println("Overall, you got" + score + "out of 15.");
		    
        
			
			
			
	}

}
Posted
Updated 11-Oct-17 11:34am
Comments
Ralf Meier 11-Oct-17 6:21am    
OK ... what have you tried until now, what happens and what should not happen ?
Which part of the code you don't understand ?
Richard MacCutchan 11-Oct-17 9:31am    
You really need to go back to basics and learn how to use lists and loops.

We don't know what it is supposed to do, what it does that you didn't expect, or didn't do that you did. We don't know what you entered in order to get it to do that!

So, its going to be up to you.
Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
Quote:
it does not work!

You only forgot to tell us what your code is supposed to do and how it go wrong.

Use the debugger to see what your code is doing, it should help you to understand what is wrong.

By the way:
- in Q1 Ireland have 2 official languages, Irish and English.
- in Q6 if 90-110 is the correct answer, 80-120 should also be correct since it include the previous one.
- in Q10, 'Agreable' is not French, but 'Agréable' is.
- in Q12 and following, I fear 'Bernadette Moore' is not the answer of those questions.

There is a tool that allow you to see what your code is doing, its name is debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900