Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

An internet service provider (ISP) has three different subscription packages for

ID: 3562627 • Letter: A

Question

An internet service provider (ISP) has three different subscription packages for its customers. Each has
a monthly cost, the number of hours the customer has access to, and.the cost per hour over the allotted
amount. Partial hours over are calculated as well (use a double!).
Package A
? $9.95 per month
? 10 hours of access
? $2.00 per additional hour
Package B
? $18.95 per month
? 25 hours of access
? $1.50 per additional hour
Package C
? $23.50 per month
? Unlimited access (no additional fees)

Design a class that calculates a customer

Explanation / Answer

=========================================

Code for ISP class

=========================================


public class ISP {

   private int numberOfHours;
   private double cost;
   private double costPackageA;
   private double costPackageB;
   private double costPackageC;
  
   //Default constructor
   public ISP() {
       super();
       setNumberOfHours(0);
       cost=0;  
   }

   //Single Parameter constructor
   public ISP(int numberOfHours) {
       super();
       setNumberOfHours(numberOfHours);
   }


   public int getNumberOfHours() {
       return numberOfHours;
   }

   public void setNumberOfHours(int numberOfHours) {
       this.numberOfHours = numberOfHours;
       costPackageA();
       costPackageB();
       costPackageC();
   }

   /**
   * Get Cost by package name
   * @param packageName
   * @return
   */
   //Missed this point in the previous code, now its added
   public double getCost(char packageName) {
      
       if(packageName=='A') {
           cost = costPackageA();
       } else if(packageName=='B'){
           cost = costPackageB();
       } else if(packageName=='C') {
           cost = costPackageC();
       }
      
       return cost;
   }

   //Calculating cost for package A
   public double costPackageA() {
      
       if(numberOfHours <=10 ) {
           costPackageA = 9.95;
       } else {
           costPackageA = 9.95 + (numberOfHours-10)*2;
       }
       return costPackageA;
   }
  
   //Calculating cost for package B
   public double costPackageB() {

       if(numberOfHours <=25 ) {
           costPackageB = 18.95;
       } else {
           costPackageB = 18.95 + (numberOfHours-25)*1.50;
       }
      
       return costPackageB;
      
   }
  
   //Calculating cost for package C
   public double costPackageC() {
      
       costPackageC = 23.50;
       return costPackageC;  
  
   }
  
   /**
   * Display All Packages cost
   */
   public void displayAllPackagesCost() {
       System.out.println("Cost for Package A:"+costPackageA());
       System.out.println("Cost for Package B:"+costPackageB());
       System.out.println("Cost for Package C:"+costPackageC());
   }
  
   /**
   * Method to displaySavings on each package
   */
   public void diplaySavingsOnEachPackage() {
       double maxAmount;
      
       if(costPackageA > costPackageB) {
           maxAmount = costPackageA;
       } else {
           maxAmount = costPackageB;
       }
      
       if(costPackageC > maxAmount) {
           maxAmount = costPackageC;
       }
  
       if((maxAmount-costPackageA) != 0.0) {
           System.out.println("Amount of money package A coustomers can save is:"+(maxAmount-costPackageA));  
       }
      
       if((maxAmount-costPackageB) != 0.0) {
           System.out.println("Amount of money package B coustomers can save is:"+(maxAmount-costPackageB));
          
       }
      
       if((maxAmount-costPackageC) != 0.0) {
           System.out.println("Amount of money package C coustomers can save is:"+(maxAmount-costPackageC));  
       }
   }
  
}

=====================================================

Code for Driver Class

=====================================================

import java.util.Scanner;


public class Driver {

   public static void main(String[] args) {
      
       String ch;
       ISP isp = new ISP();
      
       do {
           Scanner sc = new Scanner(System.in);
           System.out.println("==========================================");
           System.out.println("Enter the number of internet hours used");
          
           int numberOfHours = sc.nextInt();
           isp.setNumberOfHours(numberOfHours);
           //Display All Package Cost
           isp.displayAllPackagesCost();
           //Display Saving on each package
           isp.diplaySavingsOnEachPackage();
          
           System.out.println("Do you want to continue press Y or y");
           ch = sc.next();
          
       } while(ch.equalsIgnoreCase("Y"));
   }
}

====================================================

Sample Input and Output

====================================================

==========================================
Enter the number of internet hours used
10
Cost for Package A:9.95
Cost for Package B:18.95
Cost for Package C:23.5
Amount of money package A coustomers can save is:13.55
Amount of money package B coustomers can save is:4.550000000000001
Do you want to continue press Y or y
y
==========================================
Enter the number of internet hours used
26
Cost for Package A:41.95
Cost for Package B:20.45
Cost for Package C:23.5
Amount of money package B coustomers can save is:21.500000000000004
Amount of money package C coustomers can save is:18.450000000000003
Do you want to continue press Y or y
Y
==========================================
Enter the number of internet hours used
50
Cost for Package A:89.95
Cost for Package B:56.45
Cost for Package C:23.5
Amount of money package B coustomers can save is:33.5
Amount of money package C coustomers can save is:66.45
Do you want to continue press Y or y
y
==========================================
Enter the number of internet hours used
100
Cost for Package A:189.95
Cost for Package B:131.45
Cost for Package C:23.5
Amount of money package B coustomers can save is:58.5
Amount of money package C coustomers can save is:166.45
Do you want to continue press Y or y

=========================================

For Test Case generation for ISP i used JUNIT

=========================================

import org.junit.Test;


public class ISPTestCase {
  
   ISP isp = new ISP();

   @Test
   public void testISP() {
      
       ISP isp1 = new ISP();
       isp1.displayAllPackagesCost();
       isp1.diplaySavingsOnEachPackage();
   }

   @Test
   public void testISPInt() {
       ISP isp2 = new ISP(25);
       isp2.displayAllPackagesCost();
       isp2.diplaySavingsOnEachPackage();
   }

   @Test
   public void testGetNumberOfHours() {
       isp.getNumberOfHours();
   }

   @Test
   public void testSetNumberOfHours() {
       isp.setNumberOfHours(15);
   }

   @Test
   public void testGetCost() {
       System.out.println("Cost of package A:"+isp.getCost('A'));
       System.out.println("Cost of package B:"+isp.getCost('B'));
       System.out.println("Cost of package C:"+isp.getCost('C'));

   }

   @Test
   public void testCostPackageA() {
       System.out.println("Cost of package A:"+isp.costPackageA());
   }

   @Test
   public void testCostPackageB() {
       System.out.println("Cost of package B:"+isp.costPackageB());
   }

   @Test
   public void testCostPackageC() {
       System.out.println("Cost of package C:"+isp.costPackageC());
   }

   @Test
   public void testDisplayAllPackagesCost() {
       isp.displayAllPackagesCost();
   }

   @Test
   public void testDiplaySavingsOnEachPackage() {
       isp.diplaySavingsOnEachPackage();
   }

}

===========================================================================

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote