Question

In: Computer Science

Define a JAVA class ISP. The class consists of the name of the subscription plan and...

Define a JAVA class ISP. The class consists of the name of the subscription plan and a
method that display the plan. Derive a class DPlan from ISP. The DPlan will charge
RM10 per Mbps subscribe and RM0.20 per GB used. Derive a class MPlan from ISP.
The MPlan will charge RM5 per Mbps subscribe and RM0.80 per GB used. Display
the plan and select the best plan.

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================

// ISP.java

public class ISP {
   private String subscriptionPlan;

   /**
   * @param subscriptionPlan
   */
   public ISP(String subscriptionPlan) {
       this.subscriptionPlan = subscriptionPlan;
   }

   /**
   * @return the subscriptionPlan
   */
   public String getSubscriptionPlan() {
       return subscriptionPlan;
   }

   /**
   * @param subscriptionPlan
   * the subscriptionPlan to set
   */
   public void setSubscriptionPlan(String subscriptionPlan) {
       this.subscriptionPlan = subscriptionPlan;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Subscription Plan = " + subscriptionPlan;
   }

}

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

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

// DPlan.java

public class DPlan extends ISP {
   private double mbps;
   private double GBUsed;

   /**
   * @param subscriptionPlan
   * @param mbps
   * @param gBUsed
   */
   public DPlan(String subscriptionPlan, double mbps, double GBUsed) {
       super(subscriptionPlan);
       this.mbps = mbps;
       this.GBUsed = GBUsed;
   }

   /**
   * @return the mbps
   */
   public double getMbps() {
       return mbps;
   }

   /**
   * @param mbps
   * the mbps to set
   */
   public void setMbps(double mbps) {
       this.mbps = mbps;
   }

   /**
   * @return the gBUsed
   */
   public double getGBUsed() {
       return GBUsed;
   }

   /**
   * @param gBUsed
   * the gBUsed to set
   */
   public void setGBUsed(double gBUsed) {
       GBUsed = gBUsed;
   }

   public double totalCost() {
       double price = 0.0;
       price = mbps * 10 + GBUsed * 0.20;
       return price;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return super.toString() + "\nMbps = " + mbps + "\nGBUsed = " + GBUsed
               + "\nTotal Price :$" + totalCost();
   }

}

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

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

// MPlan.java

public class MPlan extends ISP {
   private double mbps;
   private double GBUsed;

   /**
   * @param subscriptionPlan
   * @param mbps
   * @param gBUsed
   */
   public MPlan(String subscriptionPlan, double mbps, double GBUsed) {
       super(subscriptionPlan);
       this.mbps = mbps;
       this.GBUsed = GBUsed;
   }

   /**
   * @return the mbps
   */
   public double getMbps() {
       return mbps;
   }

   /**
   * @param mbps
   * the mbps to set
   */
   public void setMbps(double mbps) {
       this.mbps = mbps;
   }

   /**
   * @return the gBUsed
   */
   public double getGBUsed() {
       return GBUsed;
   }

   /**
   * @param gBUsed
   * the gBUsed to set
   */
   public void setGBUsed(double gBUsed) {
       GBUsed = gBUsed;
   }

   public double totalCost() {
       double price = 0.0;
       price = mbps * 5 + GBUsed * 0.80;
       return price;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return super.toString()+"\nMbps = " + mbps + "\nGBUsed = " + GBUsed+"\nTotal Price :$"+totalCost();
   }

}

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

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

// Test.java

import java.util.Scanner;

public class Test {

   public static void main(String[] args) {

       int choice,mbps;
       double noOfGBUsed,dPrice=0.0,mPrice=0.0;
       /*
       * Creating an Scanner class object which is used to get the inputs
       * entered by the user
       */
       Scanner sc = new Scanner(System.in);

       // Getting the input entered by the user
       System.out.print("Enter the No of MBPS :");
       mbps=sc.nextInt();
       System.out.print("Enter the No of GB of data used :");
       noOfGBUsed=sc.nextInt();
      
       DPlan dp=new DPlan("DPlan", mbps, noOfGBUsed);
       MPlan mp=new MPlan("MPlan", mbps, noOfGBUsed);
       dPrice=dp.totalCost();
       mPrice=mp.totalCost();
       System.out.println("\n-------------------------");
       System.out.println(dp);
       System.out.println("-------------------------");
       System.out.println(mp);
       System.out.println("-------------------------");
      
       if(dPrice<mPrice)
       {
           System.out.println("\nThe Bst Plan is :"+dp.getSubscriptionPlan());
       }
       else
       {
           System.out.println("\nThe Bst Plan is :"+mp.getSubscriptionPlan());
       }
      
      
   }

}

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

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

Output:

=====================Could you plz rate me well.Thank You


Related Solutions

4) Define an abstract class Name Java class that implements interface Comparable   
4) Define an abstract class Name Java class that implements interface Comparable   
In Java, Here is a basic Name class. class Name { private String first; private String...
In Java, Here is a basic Name class. class Name { private String first; private String last; public Name(String first, String last) { this.first = first; this.last = last; } public boolean equals(Name other) { return this.first.equals(other.first) && this.last.equals(other.last); } } Assume we have a program (in another file) that uses this class. As part of the program, we need to write a method with the following header: public static boolean exists(Name[] names, int numNames, Name name) The goal of...
IN JAVA ECLIPSE PLEASE The xxx_Student class A Student has a: – Name - the name...
IN JAVA ECLIPSE PLEASE The xxx_Student class A Student has a: – Name - the name consists of the First and Last name separated by a space. – Student Id – a whole number automatically assigned in the student class – Student id numbers start at 100. The numbers are assigned using a static variable in the Student class • Include all instance variables • Getters and setters for instance variables • A static variable used to assign the student...
Create a java class with name Cat. Instructions for Cat class: This class is modeled after...
Create a java class with name Cat. Instructions for Cat class: This class is modeled after a Cat. You should have instance variables as follows: The Cat’s name The number of mice caught by the Cat. Whether or not the Cat is secretly plotting to kill you Note that you will need to choose both good types and meaningful identifiers for each of these instance variables. You may also assume that the Cat is not automatically always secretly plotting to...
A. Define and implement the class Alarm as follows: The class Alarm consists of two private...
A. Define and implement the class Alarm as follows: The class Alarm consists of two private member variables: description of type string and atime of type Time. The class Alarm also includes the following public member functions: 1. print to print out the alarm’s description and hour, minute, and second of the alarm time. 2. setDescription to accept a string argument and use it to set the description member variable. 3. setAtime to accept three integers (for hour, minute, and...
A. Define and implement the class Alarm as follows: The class Alarm consists of two private...
A. Define and implement the class Alarm as follows: The class Alarm consists of two private member variables: description of type string and atime of type Time. The class Alarm also includes the following public member functions: 1. print to print out the alarm’s description and hour, minute, and second of the alarm time. 2. setDescription to accept a string argument and use it to set the description member variable. 3. setAtime to accept three integers (for hour, minute, and...
Create java class with name BaseballPlayer Instructions for BaseballPlayer class: The BaseballPlayer class is modeled after...
Create java class with name BaseballPlayer Instructions for BaseballPlayer class: The BaseballPlayer class is modeled after a BaseballPlayer and will contain methods to calculate various statistics based on the stats of a player. For this class, you will want to use a static variable for storing a DecimalFormat object. See the API document for the BaseballPlayer class for a list of methods you will write. API Document Constructors: Identifier: BaseballPlayer(String name, int number, int singles, int doubles, int triples, int...
Create java Class with name Conversion. Instructions for Conversion class: The Conversion class will contain methods...
Create java Class with name Conversion. Instructions for Conversion class: The Conversion class will contain methods designed to perform simple conversions. Specifically, you will be writing methods to convert temperature between Fahrenheit and Celsius and length between meters and inches and practicing overloading methods. See the API document for the Conversion class for a list of the methods you will write. Also, because all of the methods of the Conversion class will be static, you should ensure that it is...
Write a Java program such that it consists of 2 classes: 1. a class that serves...
Write a Java program such that it consists of 2 classes: 1. a class that serves as the driver (contains main()) 2. a class that contains multiple private methods that compute and display a. area of a triangle (need base and height) b area of a circle (use named constant for PI) (need radius) c. area of rectangle (width and length) d. area of a square (side) e. surface area of a solid cylinder (height and radius of base) N.B....
Write a Java program such that it consists of 2 classes: 1. a class that serves...
Write a Java program such that it consists of 2 classes: 1. a class that serves as the driver (contains main()) 2. a class that contains multiple private methods that compute and display a. area of a triangle (need base and height) b area of a circle (use named constant for PI) (need radius) c. area of rectangle (width and length) d. area of a square (side) e. surface area of a solid cylinder (height and radius of base) N.B....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT