LogoLogo
    Logo
    • TutoringSchools
    1. Home
    2. IB
    3. Computer Science (CS)
    4. Questions

    A hotel chain has a loyalty scheme in which customers are awarded 1000 points for each day they stay in one of their hotels. With these points, customers can achieve one of three status levels: Gold, Silver or Bronze. The level will determine the extra services to which they are entitled.

    Question
    SLPaper 2

    A hotel chain has a loyalty scheme in which customers are awarded 1000 points for each day they stay in one of their hotels. With these points, customers can achieve one of three status levels: Gold, Silver or Bronze. The level will determine the extra services to which they are entitled.

    The total number of points collected during the current year will determine which of the three status levels they are assigned for the following year: For example only the points collected in 2018 will determine the status level for 2019.

    Occasionally, new customers receive additional bonus points as part of a promotion.

    The Pointsclass keeps details of the points and status levels of each customer.

    public class Points
    {
    private String memberId; // id of the hotel customer
    private int totalPoints; // this year's points
    private int bonusPoints; // any bonus points given to this year's new member
    private String statusNow; // current(this year's)status
    private String statusNextYear; // following year's status
    private Visits$$ allVisits = new Visits366366366;//details of each visit
    // during this year
    int y; // number of visits this year
    public Points(String id) // constructor for new member
    {
    memberId = id;
    bonusPoints = 0;
    y = 0;
    statusNow = 'Bronze';
    }

    //constructor for new member given bonus points (valid for current year only)
    public Points(String id, int bp)
    {
    memberId = id;
    bonusPoints = bp; // multiples of 1000 - maximum number is 5000
    y = 0;
    statusNow = 'Bronze';
    }

    // all the accessor and mutator methods are present but not shown
    public Visits getAllVisits(int v)
    {
    return allVisitsvvv;
    }
    public void addVisit(Visits v) // adds a new Visit object to the array
    {
    allVisitsyyy = v;
    y = y + 1;
    }

    isGold() {code missing}
    calculateTotalPoints(){code missing}
    daysMissing(){code missing}
    }

    The instance variables in the Pointsclass are preceded by the modifier private. The choice of modifier affects the way in which these variables are accessed or used.

    The customers will be assigned one of three levels for the following year (Gold, Silver or Bronze) depending upon the current year’s total points as follows.

    • Bronze = less than 10 000 points
    • Silver = 10 000 or more but less than 50 000
    • Gold = 50 000 or more.

    In 2018, Tim became a member for the first time and was awarded a bonus of 1000 points. So far, in 2018, Tim has stayed three times at one of these hotels. The first visit lasted 2 days, the second visit lasted 1 day and the third visit lasted 6 days.

    The different Pointsobjects are stored in an array which is declared globally in the main (driver) class as follows:Points[] allPoints = new Points[10000];

    1.

    With the use of two examples other than private, outline how the choice of this modifier affects the way in which these variables are accessed or used.

    [4]
    Verified
    Solution

    public;
    Allows access to variables from outside of the class/unlimited access;

    protected;
    Allows access to variable from within the package (project) in which they are created/subclasses;

    final;
    Prevents variables from being modified;

    static;
    Refers to variables that act on the class as a whole (and not on individual objects);

    Note****:

    • Accept at most one example pertaining to methods.
    • Do not accept two examples pertaining to the same modifier.
    2.

    With reference to the two methods with the same name in the Pointsclass, explain the OOP feature that makes it possible to successfully implement either of these methods.

    [4]
    Verified
    Solution

    The OOP feature shown in the constructors (accept the 2 signatures) is overloading (accept polymorphism);
    The constructor methods have a different number / type of parameters / different parameters;
    The method calling the constructor / compiler will determine which of these methods is selected;
    By matching up with the parameters;

    3.

    State the status level that Tim has been assigned, for 2019, following these visits.

    [1]
    Verified
    Solution

    Silver;

    4.

    State how an individual object can be identified using this array.

    [1]
    Verified
    Solution

    Through the use of the (appropriate) array index / appropriate code description;

    Example:

    Individual object = allVisits[individual object’s location]

    Sign up for free to view this answer

    5.

    The attribute statusNowis assigned its correct value at the beginning of every year for existing members. It cannot be changed during the year.

    Construct the method isGold()in the Pointsclass, which will return whether the current status is “Gold”.

    [3]
    Verified
    Solution

    public boolean isGold()
    {
    return (statusNow.equals('Gold'); // allows =
    }

    Award marks as follows:
    Signature;
    Correct comparison (allow use of getStatusNow());
    Return (that matches the signature – allow FT);

    Note****:

    • Allow the equivalent use of IF/THEN statements.
    • Do not accept parameters to be passed.
    • Do not allow the use of_totalPoints._

    Sign up for free to view this answer

    Still stuck?

    Get step-by-step solutions with Jojo AI

    FreeJojo AI

    Want more practice questions for Computer Science (CS)?

    Related topics


    Footer

    General

    • About us
    • Mission
    • Tutoring
    • Blog
    • State of learning surveyNew

    • Trustpilot
    • Contact us
    • Join us We're hiring!

    Features

    • Jojo AI
    • Questionbank
    • Study notes
    • Flashcards
    • Test builder
    • Exam mode
    • Coursework
    • IB grade calculator

    Legal

    • Terms and conditions
    • Privacy policy
    • Cookie policy
    • Trust Center

    IB

    • Biology (New syllabus)
    • Business Management
    • Chemistry (New syllabus)
    • Chinese A Lang & Lit
    • Chinese B
    • Computer Science (CS)
    • Design Technology (DT)
    • Digital Society (DS)
    • Economics
    • English B
    • View more...
    Logo

    © 2022 - 2025 RevisionDojo (MyDojo Inc)

    RevisionDojo was developed independently of the IBO and as such is not endorsed by it in any way.

    RedditInstagramTikTokDiscord
    GDPR compliant