Unit 1 Lesson 7 Homework

Part A: Read Method Information

  1. Identify the method name, return type, and ordered parameter types.
boolean isAffordable(double price, int quantity)



  1. Determine which statement describes a precondition and which describes a postcondition.
    a. score must be 0–100 before the call.    b. The method returns the average.



  1. Determine which use causes a compilation error.
void displayMenu()
int countSeats(int row)

displayMenu();
int seats = countSeats(4);
int result = displayMenu();



  1. Determine whether each call is compatible with the method signature.
double findCost(double price, int count)

a. findCost(6.5, 2)    b. findCost(6, 2)    c. findCost(6.5, 2.0)



  1. Determine whether these are valid overloads. Explain why.
int convert(int value)
double convert(double value)



  1. Determine the value stored in each variable.
double root = Math.sqrt(196);
double power = Math.pow(3, 3);
int distance = Math.abs(-21);



Part B: Find and Fix

  1. Correct the call so its arguments match the parameter list.
boolean canRide(int height, boolean hasTicket)

boolean allowed = canRide(true, 150);



  1. Correct the conflicting signature to create a valid overload. Keep the method name.
int measure(int length)
double measure(int distance)



Part C: Write Calls and Expressions

  1. Write an expression using Math for the positive distance between position and zero. A complete main method is not required.



  1. Write a statement that stores a random integer from 12 through 17 in ticket.