Java Exercise: Create a Science Knowledge Test

Your Challenge ...

Develop a Java program that asks the user each of the questions below. For each question the user should be prompted to enter either "t" (true) or "f" (false). The program should calculate a total score for the user. Every wrong answer scores 0; every correct answer scores 1.

At the end you should tell the user his or her final score. You should also display text which categorises the user's score, giving one of three or four different texts depending on what range the user's score falls into. For example, "You know nothing of science!", "Not bad but have another go!", etc.

Some hints ...

The program should start by displaying instructions to the user. Use arrays to store the questions and correct answers. Use a loop to output the questions.

For each answer, if the user enters something other than t or f, remind the user to enter 't' or 'f' and repeat the question. After each answer tell the user whether the answer was correct or incorrect

Don't be afraid to Google for help with anything you're not sure about, and don't be afraid to use a new project to try out anything you're not sure of. Remember to build up your program step by step, starting with a simple version of the program and gradually adding features. Test at every step.

Questions (Or Make Up Your Own!)

  • Plants derive most of their dry mass from the air (true)
  • Aluminium is the most common metal in the Earth's crust (true)
  • Vitamin C has be shown to prevent colds (false)
  • We lose most of our heat through our heads (false)
  • Dogs are unable to digest chocolate (false*)
  • Apple pips contain cyanide (true)
  • Cholesterol is a naturally-occurring toxic substance (false)
  • When you're on a diet, you lose weight by oxidising fat to a gas and exhaling it (true)
  • Human beings are unable to sense when the oxygen level of the air is low (true)
  • Most of the Y chromosome is passed unchanged from father to son (true)
*although it's true that dark chocolate especially is not good for dogs!

Example Session

Answer each of the following questions with 't' (true) or 'f' (false)

Plants derive most of their dry mass from the air.
> t
correct

Aluminium is the most common metal in the Earth's crust.
> j
Please enter t for true or f for false.

Aluminium is the most common metal in the Earth's crust.
> t
correct

Vitamin C has be shown to prevent colds.
> t
incorrect!

We lose the most heat through our heads.
> t
incorrect!

Dogs are unable to digest chocolate.
> f
correct

Apple pips contain cyanide.
> t
correct

Cholesterol is a naturally-occurring toxic substance.
> t
incorrect!

When you're on a diet, you lose weight by oxidising fat to a gas and exhaling it.
> t
correct

Human beings are unable to sense when the oxygen level of the air is low.
> t
correct

Most of the Y chromosome is passed unchanged from father to son
> f
incorrect!

You scored: 6
Not bad! But have another go.

 

 

Concepts You'll Need for This Exercise