ELI CSC 201
Unit 6 Programming Problems Worksheet
Programming Problem 1 – PayCalculator
Create an abstract class PayCalculator that has an attribute payRate given in dollars per hour. The class should also have a method computePay(hours) that returns the pay for a given amount of time.
Derive a class RegularPay from PayCalculator, as described above. It should have a constructor that has a parameter for the pay rate. It should not override any of the methods. Then derive a class HazardPay from PayCalculator that overrides the computePay method. The new method should return the amount returned by the base class method multiplied by 1.5.
Grading Rubric
|
Task |
Points |
|
Working solution for the problem |
5 |
|
Best practices in programming |
1 |
|
Total |
6 |
Screenshots
Programming Problem 2 – Message Encoder
Create an interface MessageEncoder that has a single abstract method encode(plainText), where plainText is the message to be encoded. The method will return the encoded message.
Create a class SubstitutionCipher that implements the interface MessageEncoder, as described above. The constructor should have one parameter called shift. Define the method encode so that each letter is shifted by the value in shift. Defne the method encode so that each letter is shifted by the value in shift. For example, if shift is 3, a will be replaced by d, b will be replaced by e, c will be replaced by f, and so on. (Hint: You may wish to define a private method that shifts a single character.)
Create a class ShuffleCipher that implements the interface MessageEncoder, as described above. The constructor should have one parameter called n. Define the method encode so that the message is shuffled n times. To perform one shuffle, split the message in half and then take characters from each half alternately. For example, if the message is abcdefghi, the halves are abcde and fghi. The shuffled message is afbgchdie. (Hint: You may wish to define a private method that performs one shuffle.)
Grading Rubric
|
Task |
Points |
|
Working solution for the problem |
6 |
|
Best practices in programming |
2 |
|
Total |
8 |
Screenshots
Programming Problem 3 – Message Decoder
Create an interface MessageDecoder that has a single abstract method decode(cipherText), where cipherText is the message to be decoded. The method will return the decoded message. Modify the classes SubstitutionCipher and ShuffleCipher, as described in Programming Problem 2, above, so that they implement MessageDecoder as well as the interface MessageEncoder described above. Finally, write a program that allows a user to encode and decode messages entered on the keyboard.
Grading Rubric
|
Task |
Points |
|
Working solution for the problem |
5 |
|
Best practices in programming |
1 |
|
Total |
6 |
Screenshots
1