hts.StevenWood.com

[ Last Page ]

Review Questions: June

  Note: to display things you can use either 

the System.out.println() method

 

  IF statement
3. Acme Products Ltd. ships goods anywhere in Canada, charging the customer according to the value of the items ordered, as shown in the following table. Write an if statement that, when given the total value of an order and prints the correct shipping costs.
Value of order Shipping Costs
under $10 $1.50
$10.00 - 24.99 3.20
$25.00 - 49.99 5.75
$50.00 - 74.99 7.50
$75.00 - 124.99 12.50
$125.00 and over 15.00

 

4. Assume that you have 3 integer values and that they are stored in variables named num1, num2, num3.

Using the if structure display the largest number.

  Strings
5. Input a sentence. Determine if the first letter is capitalized. Capitalize it if it is not already capitalized. Display it.
6. Given two variables, on that contains a person's first name: Fred and another that contains the last name: Flintstone.  

Display the first initial and the last name. 
E.g. F. Flintstone (note that there is a period '.' after the initial)

7. Enter in a telephone number as 9 digits. E.g. : 9057371114

Display the telephone number in this format: (905) 737-1114

8. Enter a word and print it backwards. Words or phrases that are the same forwards and backwards are called palindromes. Using your program, show that WOW is a palindrome. Then show that ABLE WAS I ERE I SAW ELBA is a palindrome.
  User defined methods
9. Create a method that will return 1 if the argument is positive, 0 if the argument is zero, and -1 if the argument is negative. Test it out.
10. Create a void method that simulates choosing a card from a standard deck of cards using the following steps.

Select the suit (heart, spade, diamond, club) by choosing a random number in the range 1-4.

A second random number in the range 1 - 13 represent the card. The ace is 1, the jack is 11, the queen is 12, and the king is 13. Print the card as the "king of hearts" or the "10 of diamonds".

11. Do the above question but this time create a method that returns a String.
12. Simulate the game of "odd man out." Three people each toss a coin in the air. The person with the "odd coin" give each of the others a coin. If there is no odd coin, then no one pays. Continue the game for 100 plays, keeping a total of each person's winnings. Display the final results.
13. Create a method that will accept 5 integers and return a double number representing the average of the numbers with 2 decimal places.
14. Create a method that will accept an integer number and then display that many asterisks (*). 
15. Create a method that will accept a value representing the pH of a liquid and return:
when pH < 7: ACID
when pH = 7: NEUTRAL
when pH > 7: ALKALINE
16. A Niven number is a positive integer that is divisible by the sum of its digits. For example, 720 is a Niven number because 7 + 2 + 0 = 9 which divides into 720 evenly. Write a method that will return true if a number is a Niven number or false if the number is not a Niven number.

Write a program to discover all Niven numbers in the range 1 - 2000.

  Other (can be done using methods)
17. A right-angled triangle has the property that when the values of the lengths of the sides are squared, the sum of the two smaller values is equal to the larger value. For example, 12, 5, 13 make a right-angled triangle, because 12*12=144, 5*5=25, 13*13=169, and 144+25=169. Your program should ask the user to enter three values and then determine whether the triangle created is right-angled.
19. Make a program that will allow the user to enter two double numbers.

Create a menu that will allow the user to press 1 to add the two numbers together, 2 to subtract the first number from the second number, 3 to subtract the second number from the first, 4 to multiply the two numbers, or Q to quit the program.

  Creating a Class
  Robot Review Questions
 
[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+