COM3113 -- Fundamentals of Programming -- Assignments

College of Computer Science -- Northeastern University

Fall Quarter 2002

Assignment 2

Due by the end of Monday, October 14th.

Part 1: Reading Assignment

Chapter 4 of our text book Java 2 A Beginner's Guide By Herbert Schildt. Page 129 ~ 167

Part 2: Coding Assignment

  • Compute the percentage of four bases in a sequence

  • Using command line to compile and run your code
  • Hard-coded the sequence in your code

    Part 3: Extra Credit

    Use one subroutine/function/method to calculate the percentage for a given base and call this subroutine for each base in your main function instead of writing 4 different loops.

    Hint: This subroutine can take the given base as a parameter and the caculation result, percentage, as a return value. In this way, the return type for the subroutine can not be void any more.

    Be careful with the declaration of your sequence. If you declare it as a local variable in main(), then you have to pass it as an argument to the subroutine. Otherwise, it has to be declared outside main().

    Note: To make it simple, you can declare your subroutine in the same class as main(). If so, then it should be declared as a static function, i.e. it should begin with "public static".

    Reference: The example of translation from celsius to fahrenheit. (the second one, which takes the translation as a subroutine with celsius as parameter and fahrenheit as return value)

    Back to assignments index page