Quick Index
Step-By-Step


NOTE WELL -- First study the Big Three.

We are provided this:

public void problem1() {
	//CODE HERE
}

With these instructions

/*
	Replace "void" with correct return type
	Replace method parameters (currently blank) with correct
		method parameters
	Replace "//CODE HERE" with solution code
*/


Problem Statement:


Given:

We are told that we have a method parameter of type Circle named circ. Thus we can complete the method parameters:

public void problem1(Circle circ) {

We know, from the provided method headers (the menu) for Circle that, for getBoundary, the method return data type is Frame.

That means we need to declare Frame (i.e., tell java we have a variable of data type Frame) and assign it to a variable named boundary so we can use it. Note that the return data type of method getBoundary must the data type of variable boundary (because the method return value is assigned to the variable).

Frame boundary;
boundary = circ.getBoundary();

We now must get the top of the boundary and assign the value to a var named result of data type int.

To get the top of the boundary we must send a message to boundary.

The variable boundary has a data type of "Frame".

Thus we browse the provided method headers for Frame and we find:

public int getTop()

We thus know that var result is data type int. Thus our next line:

int result = boundary.getTop();

We're told to return result, so we add this line:

return result;

Because we return an int data type, we know our method return data type is int, so we can finish the method header:

//Original:
public void problem1(Circle circ)
//Finished:
public int problem1(Circle circ)
 

Putting it all together:

	public int problem1(Circle circ) {
		Frame boundary;
		boundary = circ.getBoundary();
		int result = boundary.getTop();
		return result;
	}

Conclusion


Note that we had two new data types here (Frame and Circle). We didn't have a whole bunch of code and documents to learn about their inner details.

We only needed to understand their "method headers".

In other words, rather than browsing possibly hundreds or even thousands of lines of code, we only need to browse a few lines -- this is called encapsulation.