Conditional Statement Practice Problems


  1. Write a main method that will prompt the user to enter a temperature as a floating point value and then prompt them to enter "F" for Fahrenheit or "C" for Celsius. Print out equivalent temperature in the other system. Recall that Cel = (5/9)(Far-32) and vice-versa. Be careful about doing arithmetic with integers. Check your program by entering 212 degrees F and by entering 100 degrees C.

  2. For this exercise, you should strive to avoid redundant code. Write a main method that will ask the user to enter a type of pet. If the user enters "dog", then ask him to enter the number of cats it has eaten this year. If the user enters "cat", ask him to enter the number of dogs it has scratched this year. if the user enters "cockatiel", ask him to enter BOTH the number of cats it has eaten this year AND the number of dogs it has scratched this year. If the user enters anything else (not dog, cat, or cockatiel), tell him you have no further questions, and terminate the program. If the user DID enter one of the three valid species (dog, cat, cockatiel) then print out a report in the following format:
                  Species:  dog
                  Number of cats eaten:  54
                  Number of dogs scratched:  0

  3. Write a program that computes the letter grade for a student based on his/her numerical total. The program will read in the total and compute the letter grade based on the following: to get an A the total must be at least 90.0. To get a B it must be at least 80.0. For a C, at least 70.0. For a D, at least 60.0. Less than 60.0 is an F.