hts.StevenWood.com

[ Last Page ]

Test Review

Create a class for each of the following:

1. Create a program that asks the user to enter values for A, B, C, and D and calculates and prints the value of
2. Create a program that asks for a number, then a second number, and displays a message to give the correct answer. If the answer given display an appropriate message. If it is incorrect display an encouraging message.

Type in a number: 5
Type in another : 7
Add 5 and 7: 13

Sorry, the correct answer is 12!

3.  Write a program to calculate the roots of the quadratic equation: ax2 + bx + c = 0. Use the following formula:

Be sure to watch for the possibility that
Hint: Look in the Math class on the Java web site for how to do square roots.

4. Write a program that will calculate the Celsius temperature if given a Fahrenheit temperature. The formula is


5. Write a program that will calculate the Fahrenheit temperature when given a Celsius temperature.
6. The square of a number can be found by adding successive odd integers. For example, to find 42, add the first four odd integers:
42 = 1 + 3 + 5 + 7 = 16

To find 62 , add the first six odd integers:
6 = 1 + 3 + 5 + 7 + 9 + 11 = 36

Create a program that asks for a number and then uses a for lop to calculate its square using  this method.

7. Input a list of numbers (each will be under 100) and have the computer keep track of the largest value. Use 999 to indicate the end of the list. Print the largest number.
8. List all the values of the equation below  for values of x: -10, -8,...,8, 10

9. Any integer less than 256 can be converted to binary by following this series of steps:
  1. set a divisor variable equal to 128;
  2. divide the number by the divisor;
  3. print the integer quotient;
  4. reduce the original number by the value of the quotient multiplied by the divisor;
  5. divide the divisor by 2
  6. repeat steps (b) through (e) until the divisor is 1.

Write a program to ask for a number and convert it to binary. The following is a sample calculation using the number 195 to find its binary equivalent 11000011.

Number

Divisor

Integer Quotient

Reduce the original number
195 128 1 195 - 128* 1 = 67
67 64 1   67 -   64* 1 =   3
3 32 0     3 -   32 * 0 =  3
3 16 0     3 -   16 * 0 =  3
3 8 0     3 -     8 * 0 =  3
3 4 0     3 -     4 * 0 =  3
3 2 1     3 -     2 * 1 =  1
1 1 1     1 -     1 * 1 =  0
You can print your answer out on the form:
1
1
0
0
0
0
1
1
or you can try to print it this way:

11000011

 

10. You find that you have a rich relative that has been depositing $1000 into a bank account every year since you were born. The bank account earns 8% interest every year. How old will you be when there is one million dollars in the account?
11. Make a program where the user enters any two numbers. The numbers will be displayed in sorted order (smallest to largest.)
For example if the numbers were entered in this order:  4  1 
they would be displayed as: 1   4
12. Make a program where the user enters three numbers. The numbers will be displayed in sorted order (smallest to largest.)
For example if the numbers were entered in this order:  4  1  7, 
they would be displayed as: 1   4  7

 

 

 
[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+