Computer Science 202
Introduction to Programming

Fall 2012, The College of Saint Rose

Lab 10: Methods
Due: 11:59 PM, Wednesday, December 5, 2012

In this lab assignment, you will practice writing and calling methods in Java.

You may work alone or with a partner on this lab.

Getting Started

You will be adding a few method defintions and calls to a starter program. So you will need to download and extract that starter program from this link. Once you have it extracted to an appropriate folder, you should be able to open it in BlueJ.

Lab Procedure

Follow these steps to complete your lab.

  1. The starter program is not quite complete enough to compile. But we can fix that quickly. You need to complete the method header for the printMenu method. Do that and then try to compile and run the program. It's not very exciting yet - it should just ask you to enter a choice, but complain about every choice you try to enter.
  2. Now add a call to the printMenu method in the appropriate place in the main method (look for the comment). Compile and run your program to make sure it displays the menu printouts.
  3. You will be writing a method definition for the calcRectArea method, which accepts the 2 dimensions of a rectangle and returns the area of rectangle. First, write this method and make sure it compiles.
  4. Now, we would like to use the calcRectArea method. Uncomment "case 1" in the switch statement in the main method, and fill in the call to your method where indicated by the comment, save its result in a variable, and add that variable to the printout at the end of the case. Compile and run your program to make sure it computes rectangle areas correctly.
  5. Repeat the previous 2 steps for the calcRectPerimeter method.
  6. Repeat the previous 2 steps for the calcTriPerimeter method.

Bonus Opportunity

For up to 10 points of lab bonus points, write the Java program described in Gaddis Programming Challenge question 14 on page 294. Note that to do this, you will first need to complete Programming Challenge 13.

Style and Documentation Reminders

Before you submit your programs, make sure they conform to our guidelines for style and documentation.

In particular, you should have a comment at the top of each class that describes your program and has your name (and that of your partner if you are working with someone), the course number and section (02 for 11:15, E1 for 4:10). You should have comments throughout your programs describing your variables and any non-obvious Java statements or groups of statements.

All identifiers (class names and variable names) should be meaningful and conform to Java's naming conventions.

Your code should be nicely formatted, with new lines after any { or }, and indented as done in class examples.

Submitting Your Work

Before 11:59 PM, Wednesday, December 5, 2012, submit your Java program to Blackboard for grading. Please upload only your Java source file - the one with the .java file extension, not the .class, .ctxt, package.bluej or README files).

Should you choose to implement the bonus program, you should also upload your Java file for that program with your submission.


This assignment is worth 20 points, which are distributed as follows:

> FeatureValueScore
printMenu method header 2
printMenu method call 1
calcRectArea method correctness 2
calcRectArea method call 2
correct rectangle areas displayed 1
calcRectPerimeter method correctness 2
calcRectPerimeter method call 2
correct rectangle perimeters displayed 1
calcTriPerimeter method correctness 2
calcTriPerimeter method call 2
correct triangle perimeters displayed 1
Naming conventions 1
Formatting 1
Bonus program up to 10
Total 20