Lab 3: Objects and arrays

Objectives

Part A. Factorial

Using int or double for some arithmetic is problematic, because both types have a fixed size, and so arithmetic cannot be absolutely precise. The BigInteger class in the csbsju.cs160 package allows you to work with arbitrarily large integers, beyond the precision of an int.

Review the library documentation for BigInteger, and write a class Factorial that uses this class to compute the factorial of any integer exactly.

Find factorial of what? 48
12413915592536072670862289047373375038521486354677760000000000

Part B. Palindrome

Write a class Palindrome that accepts a string from the user, displays the string in reversed order, and then says whether the string is a palindrome. A palindrome is a string that reads the same backward and forward. The following is a transcript of how your program should behave.

String:     MADAMIMADAM
Reversed:   MADAMIMADAM
Palindrome: yes

String:     RACINGCAR
Reversed:   RACGNICAR
Palindrome: no

String:     REDDER
Reversed:   REDDER
Palindrome: yes
To accomplish this, build a class method reverse() that accepts a string as a parameter and returns a string representing the reversed order of the given string.

Part C. Gradebook

Write a class Gradebook that uses arrays to implement a simple gradebook. Your program should read in the number of students in the class and the names and scores of the students. (Each name is a single word.) Then, for each student, it should print the student's name, the grade, the number of points the grade is above or below average, and the final grade computed as follows.

Aif score is above 92 or at least 20 points above average
Bif score is above 83 or at least 10 points above average
Cif score is above 74 or at least average
Dif score is above 65 or at most 15 points below average
Ffor other scores

For example, a user might run the program as follows.

How many students? 3
Carl 95
Hal 23
Jeff 89

1. Carl scored 95.0, 26.0 points above average: grade is A
2. Hal scored 23.0, 46.0 points below average: grade is F
3. Jeff scored 89.0, 20.0 points above average: grade is A

To accomplish this problem, you might create two arrays - one to store the names of the students, and one to store the scores. The output of the program should match the above transcript.