Hello, I am making a show quiz show applet in Java and I am now basically done it, all I need to finish it off and make my teacher happy is to find out how i would get the applet to show the user what their score is at when they finish all the questions.

import java.awt.*;
import java.applet.*;
import java.io.*;

public class Quiz_Show extends Applet
{
    public static void main (String args[])
    {
        InputStreamReader istream = new InputStreamReader (System.in);
        BufferedReader bufRead = new BufferedReader (istream);
        String Answer = "";
        int score = 0;
        System.out.println ("Welcome to my quiz show.");
        System.out.println ("Please enter the letter of the answer for each question and press enter.");
        /*Question One*/
        System.out.println ("Here is the first question.");
        System.out.println ("What is the largest country in the world?");
        System.out.println ("A-Canada");
        System.out.println ("B-Russia");
        System.out.println ("C-USA");
        System.out.println ("D-China");
        while (Answer.equalsIgnoreCase (""))
        {
            try
            {
                System.out.println ("Please answer with a, b, c, or d");
                Answer = bufRead.readLine ();
            }
            catch (IOException err)
            {
                System.out.println ("Error reading line");
            }
        }
        if (Answer.equals ("b"))
        {
            System.out.println ("Good job, that is correct!");
            score = score + 15;
        }
        else
        {
            System.out.println ("Sorry, that answer is incorrect.");
            score = score - 5;
        }
        /*Question Two*/
        Answer = "";
        System.out.println ("Get ready for question two.");
        System.out.println ("What is 32+(4x9)?");
        System.out.println ("A-32");
        System.out.println ("B-324");
        System.out.println ("C-36");
        System.out.println ("D-68");
        while (Answer.equalsIgnoreCase (""))
        {
            try
            {
                System.out.println ("Please answer with a, b, c, or d");
                Answer = bufRead.readLine ();
            }
            catch (IOException err)
            {
                System.out.println ("Error reading line");
            }
        }
        if (Answer.equals ("d"))
        {
            System.out.println ("Nice work, that's right!");
            score = score + 15;
        }
        else
        {
            System.out.println ("Sorry, that's not the right answer.");
            score = score - 5;
        }
        /*Question Three*/
        Answer = "";
        System.out.println ("Time for question three.");
        System.out.println ("What is a euphonium?");
        System.out.println ("A-a musical instrument");
        System.out.println ("B-a bug");
        System.out.println ("C-a type of book");
        System.out.println ("D-a small muscle in the lower leg");
        while (Answer.equalsIgnoreCase (""))
        {
            try
            {
                System.out.println ("Please answer with a, b, c, or d");
                Answer = bufRead.readLine ();
            }
            catch (IOException err)
            {
                System.out.println ("Error reading line");
            }
        }
        if (Answer.equals ("a"))
        {
            System.out.println ("Wow, you're smart, that's correct.");
            score = score + 20;
        }
        else
        {
            System.out.println ("Guess you're not as smart as I thought, that's not the right answer.");
            score = score - 5;
        }
        /*Question Four*/
        Answer = "";
        System.out.println ("Time to move on to the fourth question.");
        System.out.println ("What company makes Alienware computers?");
        System.out.println ("A-Kraft");
        System.out.println ("B-Dell");
        System.out.println ("C-Apple");
        System.out.println ("D-Microsoft");
        while (Answer.equalsIgnoreCase (""))
        {
            try
            {
                System.out.println ("Please answer with a, b, c, or d");
                Answer = bufRead.readLine ();
            }
            catch (IOException err)
            {
                System.out.println ("Error reading line");
            }
        }
        if (Answer.equals ("b"))
        {
            System.out.println ("Guess you know your computers, you're correct.");
            score = score + 15;
        }
        else
        {
            System.out.println ("Maybe you should learn some more about computers, that's not the correct answer.");
            score = score - 5;
        }
        /*Question Five*/
        Answer = "";
        System.out.println ("Question number five heading your way.");
        System.out.println ("How many time zones are in Canada?");
        System.out.println ("A-27");
        System.out.println ("B-2");
        System.out.println ("C-7");
        System.out.println ("D-6");
        while (Answer.equalsIgnoreCase (""))
        {
            try
            {
                System.out.println ("Please answer with a, b, c, or d");
                Answer = bufRead.readLine ();
            }
            catch (IOException err)
            {
                System.out.println ("Error reading line");
            }
        }
        if (Answer.equals ("d"))
        {
            System.out.println ("You're pretty good at this, that's correct.");
            score = score + 15;
        }
        else
        {
            System.out.println ("Sorry, that's not the answer I was looking for.");
            score = score - 5;
        }
        /*Question Six*/
        Answer = "";
        System.out.println ("Onward to the sixth.");
        System.out.println ("What is the largest province in Canada?");
        System.out.println ("A-Quebec");
        System.out.println ("B-Nunavut");
        System.out.println ("C-British Columbia");
        System.out.println ("D-Ontario");
        while (Answer.equalsIgnoreCase (""))
        {
            try
            {
                System.out.println ("Please answer with a, b, c, or d");
                Answer = bufRead.readLine ();
            }
            catch (IOException err)
            {
                System.out.println ("Error reading line");
            }
        }
        if (Answer.equals ("a"))
        {
            System.out.println ("You really know abour Canada, that's the correct answer.");
            score = score + 15;
        }
        else
        {
            System.out.println ("Maybe you should learn more about Canada's geography, that's the wrong answer.");
            score = score - 5;
        }
        /*Question Seven*/
        Answer = "";
        System.out.println ("Time to try out the seventh question.");
        System.out.println ("What was another name for Antonio Vivaldi?");
        System.out.println ("A-The White Salamander");
        System.out.println ("B-The Black Nun");
        System.out.println ("C-The Red Priest");
        System.out.println ("D-Pikachu");
        while (Answer.equalsIgnoreCase (""))
        {
            try
            {
                System.out.println ("Please answer with a, b, c, or d");
                Answer = bufRead.readLine ();
            }
            catch (IOException err)
            {
                System.out.println ("Error reading line");
            }
        }
        if (Answer.equals ("c"))
        {
            System.out.println ("You really know your musical history, that'sthe right answer.");
            score = score + 20;
        }
        else
        {
            System.out.println ("I guess that one was a pretty tough one, but you still got the wrong answer.");
            score = score - 5;
        }
        /*Question Eight*/
        Answer = "";
        System.out.println ("Time for question eight");
        System.out.println ("What is a Nigerian Uromastyx?");
        System.out.println ("A-a type of grass");
        System.out.println ("B-a person born in Nigeria, but now lives in Europe");
        System.out.println ("C-a type of lizard");
        System.out.println ("D-a very rare disease");
        while (Answer.equalsIgnoreCase (""))
        {
            try
            {
                System.out.println ("Please answer with a, b, c, or d");
                Answer = bufRead.readLine ();
            }
            catch (IOException err)
            {
                System.out.println ("Error reading line");
            }
        }
        if (Answer.equals ("c"))
        {
            System.out.println ("Nice work, that's right!");
            score = score + 15;
        }
        else
        {
            System.out.println ("Sorry, that's not the right answer.");
            score = score - 5;
        }
        /*Question Nine*/
        Answer = "";
        System.out.println ("You're almost done, time for question nine.");
        System.out.println ("How many months of the year have 28 days?");
        System.out.println ("A-12");
        System.out.println ("B-1");
        System.out.println ("C-13");
        System.out.println ("D-2");
        while (Answer.equalsIgnoreCase (""))
        {
            try
            {
                System.out.println ("Please answer with a, b, c, or d");
                Answer = bufRead.readLine ();
            }
            catch (IOException err)
            {
                System.out.println ("Error reading line");
            }
        }
        if (Answer.equals ("a"))
        {
            System.out.println ("Nice work, that's right!");
            score = score + 10;
        }
        else
        {
            System.out.println ("Sorry, that's not the right answer.");
            score = score - 5;
        }
        /*Choice of Question 10*/
        Answer = "";
        System.out.println ("Finally, you've reached the end of your journey, the final question.");
        System.out.println ("Warning-It's time for your final question, but it's a very difficult question.");
        System.out.println ("If you get the answer right you get 100 points!");
        System.out.println ("Although, if you get the question wrong you lose 100 points.");
        System.out.println ("Do you want to try the question (Y/N)?");
        while (Answer.equalsIgnoreCase (""))
        {
            try
            {
                System.out.println ("Please answer y or n");
                Answer = bufRead.readLine ();
            }
            catch (IOException err)
            {
                System.out.println ("Error reading line");
            }
        }
        if (Answer.equals ("y"))
        {
            /*Question Ten*/
            Answer = "";
            System.out.println ("Which of these cities is the farthest north?");
            System.out.println ("A-Madrid");
            System.out.println ("B-Rome");
            System.out.println ("C-Beijing");
            System.out.println ("D-New York");
            while (Answer.equalsIgnoreCase (""))
            {
                try
                {
                    System.out.println ("Please answer with a, b, c, or d");
                    Answer = bufRead.readLine ();
                }
                catch (IOException err)
                {
                    System.out.println ("Error reading line");
                }
            }
            if (Answer.equals ("b"))
            {
                System.out.println ("WOW!  You're amazing that's the correct answer, you deserve the 100 points.");
                score = score + 100;
            }
            else
            {
                System.out.println ("Good try, but that's not the answer that I'm looking for.");
                score = score - 100;
            }
            System.out.println ("Congratulations you have completed the quiz!");
        }
        else
        {
            System.out.println ("Congratulations you have completed the quiz.");
        }
    }
}

Recommended Answers

All 3 Replies

Write at the end of code System.out.println ("You have Scored: ."+ score);

You fail. That's not an applet, and it's not Java. It's BASIC written in Java syntax.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.