Welcome to Lesson 17!


Announcements

  • Midterm 2 after a short lesson and the break
  • Next Quiz one week from today
  • Don't forget Lab 8 due Friday!
  • Assignment 16 due Tuesday!


Review Activity


Write the Javadoc comment for the below method:

public static double calc_area_circle(int radius) {

    double area = 3.14 * radius * radius;

    return area;

}


Call the above method, passing in 9 as the radius:

double area = ???????????????????????;



What is output by the following program? (Do not run the code -- work it out by hand)


public static int mystery(int param) {
System.out.println("param=" + param);
param = param * 2;
return param;
}

public static void main(String[] args) {
    int num = 2;
System.out.println("At first, num=" + num);
int result = mystery(num);
System.out.println("After calling, num=" + num);
System.out.println("And result=" + result);
}
  1. At first, num=2
    param=2
    After calling, num=4
    And result=4
    
  2. At first, num=2
    param=4
    After calling, num=4
    And result=4
    
  3. At first, num=2
    param=2
    After calling, num=2
    And result=4
    
  4. None of these

Write the following methods:

  • calcTip
    • Takes in one double parameter for the price of a meal
    • Calculates 15 percent of the price as the tip
    • returns a double for the tip
  • calcGPA
    • takes in one double parameter for the grade points and one integer parameter for the number of units.
    • divides the grade points by the units to calculate the GPA
    • returns a double for the GPA
  • minNum
    • Takes in two integer parameters
    • determines which of the two numbers is smaller
    • returns the smaller number




Midterm 2

Upcoming Assignments