Graderpractice for programmers

231322 Java U4 - Methods

Awaiting submission
  • Read a double
  • Print it to 1 dp
Hint: Use printf("%.1f%n", num)
Awaiting submission
  • Read 2 doubles (radius of 2 circles)
  • Calculate the area of each circle
    (write your own static method)
  • Print both areas to 1 dp (on separate lines)
Hint: Math.PI and Math.pow()
Awaiting submission
  • Read 2 doubles (radius of 2 circles)
  • Calculate the difference in their areas
  • Convert to an absolute (position) value
  • Print the answer to 5 dp
Hint: Math.abs()
Awaiting submission
  • Read 2 doubles
  • Round the doubles to 1 dp (not format)
  • Print the difference (to 1 dp)
Hint: Math.round() + some cleverness
Awaiting submission
  • Read 2 doubles
  • Read 1 int (the desired precision)
  • Round the doubles (not format) to the given precision
  • Calculate the difference
  • Print to the same precision
Awaiting submission
  • Read 1 String
  • Convert it to proper case
    • First letter capital
    • Other letters small
Awaiting submission
  • Read 1 String: name
  • Write a static method cleanName(...)
    • Remove MR, mr, mR, Mrs, MS, miss, ...
    • Remove .
    • Trim the result
    • Ensure the name uses proper case
Hint: Use lowerCase() before replace("mr", "")
Awaiting submission
  • Read 1 double: temperature (in deg F)
  • Write a static method convToCelsius(...)
    Tc = (Tf - 32.0) * 5.0 / 9.0
  • Convert & print (1 dp)
Awaiting submission
  • Read 2 doubles: a, b (sides of a triangle)
  • Write a static method calcHypo(...)
    c = (a^2 + b^2)^0.5
  • Calculate & print the hypotenuse (1 dp)
Awaiting submission
  • Read 2 doubles: weight (kg), height (cm)
  • Write a static method calcBmi(...)
    bmi = weight / (height/100.0)^2
  • Calc & print BMI (1 dp)
Awaiting submission
  • Copy calcBmi(...) from the previous question
  • Add analyseBmi(...) that prints:
    Weight (kg): <<weight 1dp>>
    Height (m): <<height 2dp>>
    BMI: <<bmi 1dp>>
    Underweight: <<true if bmi < 18.5>>
    Overweight: <<true if bmi ≥ 25.0>>
  • Read inputs, calc bmi, and analyse!
Awaiting submission
  • Read:
    • 1 double: grade points
    • 1 int: credits
  • Write a static method calcGpa(...)
    gpa = gp / credits
  • Calculate & print the GPA (2 dp)
  • Repeat 3x (you only need 1 method)
Awaiting submission
  • Read:
    • 1 double: current GPA
    • 2 ints: current credits, new credits
  • Write a static method maxGpa(...)
    • Calculate max GP from new credits (4.0 x new credits)
    • Calculate current GP (current GPA * current credits)
    • Add current & max GP, and calculate new GPA
  • Calculate & print max GPA (2 dp)