Question: D. [10 pts] Implement the class PremiumSubscriber. The data field premiumYears contains for how many years the subscriber has been a premium subscriber. a) Write
![D. [10 pts] Implement the class PremiumSubscriber. The data field premiumYears](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f4e15ab10c9_50666f4e15a364e8.jpg)
D. [10 pts] Implement the class PremiumSubscriber. The data field premiumYears contains for how many years the subscriber has been a premium subscriber. a) Write the constructor that takes as parameters all data fields. b) Implement the method feesAfterDiscount method of the Discountable interface. Only premium subscribers are eligible for a discount based on how many years they had premium subscription. Subscribers who have been premium for 3 years or less are eligible to a 20% discount; otherwise, they are eligible to a 40% discount. c) Assuming a subscriber has an id of 12345, name of John White, monthly fees of 50, and 4 premium years, the toString method should return a String in the following format: ID: 12345, Name: John White, Monthly Fees: $50.0, Premium Years: 4, Monthly Fees after discount: $30.0 E. [20 pts] Implement the class SpotifyPage that represents an artists Spotify Page. Each page has a title, a set of subscribers, and their number. a) Write the constructor that takes as parameters the title of the page and the maximum number of subscribers that it can hold. b) Write the addSubscriber method that adds a subscriber to the page if it is not already full. If it is full, an error message should be displayed. c) Write the subscriberById method that looks for a subscriber by its id. If found, the method should return the subscriber object, otherwise, it returns null. d) Write the nbOfPremiumSubscribers method that returns the number of premium subscribers of the page. e) Write the totalMonthlyIncome method that calculates and returns the total monthly income generated by the page by summing the subscribers monthly fees.
Question 1 [40 pts] Open with Implement the below classes and interface as presented in the following UML diagram except the class BasicSubscriber for which you will find the code provided below. For all classes implement only the getters that you will need later in your code. SpotifyPage - title: String - nbOfSubscribers: int Subscriber - subscribers: Subscriber) #id: int + SpotifyPage (title:String, maxNbOfSub:int) # name: String + addSubscriber(s: Subscriber): void #monthlyFees: double + subscriberById(id:int): subscriber + Subscriber (id:int, name: String) + nbOfPremiumSubscribers(): int toString(): String + totalMonthlyIncome(): double > Discountable + feesAfterDiscount(): double BasicSubscriber PremiumSubscriber - joinDate: String - premium Years: int + Constructor (--All Parameters--) + Constructor (--All Parameters--) + toString(): String + toString(): String A. [6 pts] Write the abstract class Subscriber as presented in the above UML. a) Write the constructor that takes as parameters all data fields. b) Assuming a subscriber has an id of 12345, name of John White, and monthly fees of 50, the toString method should return a String in the following format: ID: 12345, Name: John White, Monthly Fees: $50.0 B. [4 pts] Write the interface Discountable. C. Do not implement the class BasicSubscriber. The code is: public class BasicSubscriber extends Subscriber private String joinDate; public BasicSubscriber (int i, String n, double m, String j) { super(i, n,m); joinDate = 1; } @Override public String toString() { return super.toString() +", Join Date: "+ joinDate; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
