GeeksforGeeks » Interview Questions

Sapient Interview Question for Software Engineer/Developer about Object Oriented

(2 posts)
  • Started 1 year ago by micropiskts
  • Latest reply from Mitendra Anand
  1. gagan
    guest
    Posted 1 year ago #

    You need to create a class diagram or data model for the given requirements. the requirement is as follows
    In a village there are only few families and there were only one newspaper/magazine agent. there are lot of news paper and magazine available and every month a new magazine or newspaper it introduced. Every family is getting at least one newspaper or magazine. Every month at the end the cost is calculated and collected. Suppose if a family wants to cancel the subscription, they should be able to do it at any day of the month. The family should be billed only for the days which they got the newspaper or magazine.
    The agent plans to buy a computer and proceed. Please create a class diagram or data model which helps him in developing a new software for it. Do not write the code or Flowchart

  2. Mitendra Anand
    guest
    Posted 4 months ago #

    - Use observer pattern
    - Subject is Agent, aggregated by many family. and has the list of observers i.e. list<family>
    - Family is observer.
    - Family should aggregate newspaper and magazine entity with 1 to many relationship.
    - Family has TotalCost() method which gives the cost of magazines and newspaper family has aggregated.

    pseudo code:-
    1. Create Agent.
    2. Create n number of family and Agent in it's constructor
    3. Access Agent's observer's list and add this* (i.e. family) to observer list.
    4. Call Agent.TotolBil(), this should iterate throught the observer list and query them for no. of magazine's and it's cost.


Reply

You must log in to post.

RSS feed for this topic