CS10, Fall 2009, lab09

Instructor: Phill Conrad
TAs: Esra Kucukoguz, Yiming Li, Murali Yeleswarapu

Primary TA for this lab: Esra Kucukoguz
Grader for this lab: Not Applicable—this lab is not for credit

This lab is not graded

Goals for today's lab


Collaboration

Since today's lab is not graded, collaboration is just fine.


Detailed Instructions

Step 1: Do your peer evaluation(s) if you haven't done it (them) yet:

Visit http://tr.im/cs10peereval

Follow the instructions.

Step 2: Finish up lab08

and lab06 and lab07 if they aren't done.

Step 3: Practice with Number Systems

See the number systems practice questions.

Your classmate Keal Jones made an improved version of the page:
http://kealjones.com/numberConversions/

Step 4: Practice with arrays

On the website Javabat.com there are three sections dealing with arrays.

I recommend those as preparation for the final exam questions about arrays—espcially if you did poorly on question 4 on the midterm.

 

You may also like to try all of the other problems on that site—they are all good practice.

www.javabat.com

Step 5: Problems dealing with for loops and recursion

Here are two BlueJ projects that provide some practice with nested for loops and recursion.

These build off the triangle drawing programs you worked with in Homework 15.

The first version contains only stubs—you have to implement all the methods.

The second version contains solutions. You might like to try first implementing all of these yourself. If you get stuck, you can peek at the solutions.

Look at the javadoc and the test methods to see what the methods in the classes are supposed to do.

You might also open the completed project, and just run the program called H15Runner to get an idea of what the methods are supposed to do.

When you've gotten all the test cases to pass, go back and be sure you understand how all the methods work.

Step 6: Problems dealing with inheritance

Here is some sample code, and some exercises for you to review your understanding of inheritance.

We can hope that the reading you did previously about inheritance—reading from Chapter 11 of the text that you did in order to complete homework 12—has stuck with you, but just in case, the examples below will help refresh your memory.

If you find that you cannot understand what is going on, you may want to re-read Chapter 11, and then look at these examples again.



Step 6.1: Download the following projects:

Step 6.2: Work with the inheritanceExample1 project:

You'll see three classes. Look at the Person class first. It is a very simple class—so simple, that it could have appeared on Midterm 1.

The Person class has instance variables for

There are then three getters for those attributes, one setter, and a toString method.

Now, suppose we want to make a class for a Student. A Student has all the same attributes as a Person, plus perm number and gpa. So, we can proceed in one of two ways:

Look through Student_TheHardWay first. Read not only the code, but all the comments as well.

The comments in the files explain a lot about how inheritance works, why you do it, and how you do it.
So read them!

Next look through Student_TheEasyWay. Read not only the code, but all the comments.

Look at the test classes for both Student_TheHardWay and Student_TheEasyWay as well. The comments in there explain what we have to do when writing test cases for inheritance, and shed additional light on how inheritance works.

When you think you understand the code in these three files, move on to the next step.

Step 6.3: Work with the inheritanceExample2 project

This is a copy of the previous project, with these changes:

Compare the Student class and the Instructor class.

Now, write your own class called "TA" that inherits from Person. It should add one attribute (instance variable) which is "course" (let's assume for now that a TA covers only one course. That isn't always true in the real world, but for now, let's pretend.)

Represent the course as a String. Add a method to TA called "getCourse".

Then, write a toString method that will return the TA object formatted as a String like this:

"Esra Kucukoguz (TA for CS10)"

Then, write a test class to be sure that your new TA class works properly.

If you can do all these things, you understand enough about inheritance that you should be in good shape for the Final exam, and also well prepared for CS20 (if you choose to take that course.)

 


This lab is not graded...

so there is nothing to turn in, and no due date...

...except that you will be graded on your final exam, and that definitely has a due date. :-)

End of lab09