Unit 1 Lesson 7 Homework
Part A: Read Method Information
- Identify the method name, return type, and ordered parameter types.
boolean isAffordable(double price, int quantity)
- Determine which statement describes a precondition and which describes a postcondition.
a.scoremust be 0–100 before the call. b. The method returns the average.
- Determine which use causes a compilation error.
void displayMenu()
int countSeats(int row)
displayMenu();
int seats = countSeats(4);
int result = displayMenu();
- 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)
- Determine whether these are valid overloads. Explain why.
int convert(int value)
double convert(double value)
- 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
- Correct the call so its arguments match the parameter list.
boolean canRide(int height, boolean hasTicket)
boolean allowed = canRide(true, 150);
- 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
- Write an expression using
Mathfor the positive distance betweenpositionand zero. A completemainmethod is not required.
- Write a statement that stores a random integer from
12through17inticket.