AP Computer Science Program: Fractions



AP Computer Science Program: Fractions

You are to write a program that drills kids with addition, subtraction, multiplication and division problems. In particular, ask the user how many problems for the game, what type of problems, and then give the user that many random problems, where each fraction is in between 0 and 1 with a denominator no greater than 10. At the end of the game, output how many problems the user has solved correctly and how much time it took them. Then, give students a final score according to the following formula:

Score = Time Spent (in seconds) + 10 × (Number of incorrect problems)

Clearly, the lower the overall score, the better! In this manner, kids can see if they are making progress or not.

Note: Feel free to change some of the specifications of the problem, namely the nature of the random fractions. Also, feel free to define how the user will enter a fraction and whether or not they have to reduce to get the answer correct. Feel free to specify how the user should enter whole numbers, if the answer to a problem is a whole number. Whatever you decide, make sure that your rules are clear when the user runs the program.

How to calculate time spent for a segment of code in a Java program:

In order to calculate how much time something takes, you can use the time function. In particular, the function call time(0) returns an int that represents the number of seconds after the birth of the Unix operating system. In order to effectively use this, you must call the function twice: once right before you start what you want to time, and once right afterwards. Subtract these two values to obtain the amount of time a segment of code took. Here is a short example:

long start = System.currentTimeMillis();

// Insert code you want to time here.

long end = System.currentTimeMillis();

double secs = (end – start)/1000.0;

System.out.println("Your code took " +secs+ "seconds.");

Input Specification

The number of problems to answer entered by the user will always be a positive integer less than 50.

Output Specification

For each correct response, output: Correct!

For each incorrect response, output: Incorrect, A op B = C.

where A and B are the numbers in the problem they missed, C is the correct answer, op is the appropriate operator.

After all the problems are completed, output a single line with the following format:

You got X problems correct and Y problems incorrect in Z seconds.

where X is the number of problems solved correctly, Y is the number of problems with incorrect answers, and Z is the amount of time in seconds the user took.

Then output one final line with the user's score:

Your final score is S.

where S is the final score for the user using the formula previously given.

Output Samples

Here is one sample output of running the program. Note that this sample is NOT a comprehensive test. You should test your program with different data than is shown here based on the specifications given above. The user input is given in italics while the program output is in bold.

Sample Run

How many problems do you want?

5

What type of problem do you want(+,-,x,/)?

x

Answer: 2/3 x 9/10 = 3/5

Correct!

Answer: 1/3 x 4/5 = 4/17

Incorrect, 1/3 x 4/5 = 4/15.

Answer: 0/5 x 8/9 = 0/1

Correct!

Answer: 5/7 x 1/6 = 5/42

Correct!

Answer: 7/8 x 5/6 = 35/48

Correct!

You got 4 problems correct and 1 problems incorrect in 17 seconds.

Your final score is 27.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download