CIS 160 Methods exercise #1

Objective

  • Create Java methods to solve problems

Exercise

This quiz is to be done as an exercise. It involves writing a number of different methods to get a program running. A skeleton program is provided. As you get each method written, uncomment the part of the skeleton program that uses it, recompile, and rerun it. Do NOT change anything within the main method other than uncommenting code. A copy of the output from a sample run is also available. Listed below is a brief decsription of each of the methods that you must write.

  • method 1: Write a method named printHeading that displays your name on one line and the message "In-class method exercise" on the next line.
  • method2: Write a method named displayMessage that displays a String sent to it as an argument.
  • method3: Write a method named max that accepts two integers as arguments and returns the value of the largest of the two.
  • method4: Write a method named calcGross that takes two doubles as arguments (hours and hourly rate) and returns the calulated gross pay. Any hours worked beyond 40 should be paid at 1.5 times the regular rate.
  • method5: Write a method named quadrant which takes two integer values which represent an (x, y) coordinate. Return a String value as follows:
    • at the origin (if x = 0 AND y = 0)
    • on the x axis (if y = 0)
    • on the y axis (if x = 0)
    • in quadrant I (if x > 0 AND y > 0)
    • in quadrant II (if x < 0 AND y > 0)
    • in quadrant III (if x < 0 AND y < 0)
    • in quadrant IV (if x > 0 AND y < 0)
  • method6 and method7: Write methods to calculate Fahrenheit and Celsius temperatures. The first method should be named toCelsius. It should take a double which represents the Fahrenheit temperature in degrees. It should return a double that is the equivalent Celsius temperature. The second method should be named toFahrenheit. It should take a double which represents the Celsius temperature in degrees. It should return a double that is the equivalent Fahrenheit temperature. The following two equations might come in handy:
    • C = 5/9 * (F - 32)
    • F = 9/5 * C + 32
  • method8 and method9: This one requires two methods.
    • The first should be named quadraticSolutionType. It should accept three doubles (a, b, and c). It should return an integer code indicating what types of roots the corresponding quadratic equation has as follows:
      • return -1 if a = 0
      • return 1 if b*b - 4*a*c = 0 (single repeated root)
      • return 2 if b*b - 4*a*c > 0 (two real roots)
      • return 3 if b*b - 4*a*c < 0 (two complex roots)
    • The second method should be named displayQuadType. It should accept one integer argument indicating the root type and display the following:
      • The equation has a single repeated root. (if the code is 1)
      • The equation has two real roots. (if the code is 2)
      • The equation has two complex roots. (if the code is 3)
      • *** Invalid argument value *** (if the code is -1)
      • *** ERROR *** (if the code is anything else)