Question: Provide the code for the following method so that it: - Adds to the ArrayList the subscription passed as parameter if it is NOT
Provide the code for the following method so that it: - Adds to the ArrayList the subscription passed as parameter if it is NOT of type Paid Subscription (.5 point) If it is of type PaidSubscription, then only add it if its price will not put us over our budget (.5 point). If you end up adding it, also update the cost attribute so as to reflect how much we have spent so far (.5 point) */ public void add (Subscription s) { for (Subscription i: subs) { if(i instanceof Subscription) { this.subs.add(s); }if() { this.subs.add(s); }//end method add - /* TASK #6 - 3 points Provide the code for the following method so that it:[ Creates a File object corresponding to the parameter filename (0.5 point) Uses it to test if the file actually already exists (0.5 point) If it does, we will raise the Subscriptions ListException with a message indicating "File already exists" (0.5 point). Creates a Printwriter object that will be automatically closed (0.5 point) Uses it to write to the file each of the subscriptions contained in our ArrayList (0.5 point). Catches any exceptions that may be thrown and rethrows instead a Subscriptions ListException with a message corresponding to the toString of the exception object (0.5 point). public void save(String filename) throws Subscriptions ListException {
Step by Step Solution
3.44 Rating (160 Votes )
There are 3 Steps involved in it
public class SubscriptionsList private ArrayList subs private double bu... View full answer
Get step-by-step solutions from verified subject matter experts
