Вы находитесь на странице: 1из 2

SSK 3101 (Computer Programming II)

Lab 6

Learning Outcomes:

• Code and document programs using good programming techniques. (P4)


• Solve problems using programming techniques. (CTPS)

Instructions:

1. Find solution to each problem and get help from your instructor whenever you encounter
any problem.
2. Include the following details in your source code:
// Author’s name:
// Matric number:
// Lab Group:
3. Copy or other forms of cheating is forbidden. The faculty has very strong rules about this,
and the penalties may be severe. The standard penalty for the first offence is to award 0
to all parties concerned.
4. This assignment must be shown to the instructor before or at the end of lab session.
Failure to do so will cause lab points to be deducted.

Note: Use meaningful identifiers and appropriate comments, line spacing and indentation.

1
Question

Create a class named NewspaperSubscriber with private fields for a subscriber’s street address
and the subscription rate. Include get and set methods for the subscriber’s street address and
subscription rate. In the same class, include an equals() method that indicates any two
subscribers are equal if they have the same street address.

Create three child classes of service type named as SevenDaySubscriber, WeekDaySubscriber,


and WeekendSubscriber. Each child class constructor sets the rate as follows:
SevenDaySubscriber pays RM4.50/week, WeekDaySubscriber pays RM3.50/week, and
WeekendSubscriber pays RM2.00/week. Each child class should include a toString() method that
returns the service type, street address, and rate.

Construct a method known as PrintDetails(Object o) in the public class. Pass all instances of
SevenDaySubscriber, WeekDaySubscriber, and WeekendSubscriber to PrintDetails method and
invoke their respective toString() method by using the operator “instanceof” and appropriate
casting might be required.

Write an application named Subscribers that accepts subscriber’s requested service type and
street address. The method PrintDetails(Object o) is inclusive in this class.

Sample input:
NewspaperSubscriber sevendays = new SevenDaySubsriber(“Seven day subscriber”,”Taman Seri
Serdang”);

NewspaperSubscriber weekday = new WeekDaySubscriber(“Weekday subscriber”,”Taman Seri


Serdang”);

NewspaperSubscriber weekend = new WeekendSubscriber(“Weekend subscriber”,”Taman Seri


Serdang”);

<End of Question>

Вам также может понравиться