hts.StevenWood.com

[ Last Page ]

Exam Review Questions

These are additional review questions

1. Write a program to score a football game. Ask the user for the two team names. Create a loop that asks for the team name and type of score. A touchdown counts 6 points, a convert 1 point, and a field goal three points. When Quit is entered as the team name, a final score for each team should be printed. Naturally, the team with the higher point score wins. The program should print a statement such as Stampeders win the game.
2.  Devise a program that simulates a cash register. It should ask for the purchase price of an item and then calculate the sales tax. The tax and the total price are then printed. Next payment must be entered. If there is insufficient money, the program should make a comment and ask for the money again. It should then calculate and print the change. The entire process should continue until a purchase of zero is made.
3. Adapt the above program so that once a purchase of zero is made the total sales price of all sales is displayed and the total sales tax is displayed.
4. a) Those in Finite will be familiar with the term factorial. The factorial of a number is the product of all positive integers less than or equal to the number. For example, 5 factorial (written 5!) is equal to 5 * 4 * 3 * 2 * 1, or 120. Write a program that reads an integer and prints the factorial for that integer.

b) Modify the program to print an error message if a negative integer or zero is entered.

5. a) A prime number is any integer that is evenly divisible only by itself and 1. For example, the numbers 2, 3, 5, and 7 are prime while 9, 10, and 15 are not. Write a program that will read an integer. The computer will test the integer by repeatedly using the modulus by integers smaller than itself but larger than 1 and checking whether the remainder is 0. If so, the integer is not prime. 

b) Write a program that check all number between 2 and a number entered by the user to see if any of them are prime numbers.

Solution: IPO Chart

Solution: Flowchart

Solution: Class

6. Heron's Formula

If the three sides of a triangle, a, b, and c, are known, its area can be found from the formula:

where s is one-half the perimeter:

Solution: IPO

Solution: Flowchart

Solution: Heron.java

 
[Last Page]
All material on this site is copyright © 1997- by Steven Wood or as credited. All right reserved. Use of this site indicates you agreement with the  terms of use.
Send comments or questions to about this page.
Every attempt has been made to credit work under copyright. If there are any claims that copyright has been missed please contact the .
+SDG+