Question: Adding methods to the InternetBill class: This project will incorporate an improved InternetBill class. We will overload our constructor, add new service methods to calculate
Adding methods to the InternetBill class:
This project will incorporate an improved InternetBill class. We will overload our constructor, add new service methods to calculate customers bill based on internet usage and package bought.
We will also override toString method from Object class.
This lab calculates and display the bill for an internet package INTERNET5. For this lab, we assume that there is only one internet package offered by the internet service provider:
o INTERNET_5 with 25GB usage for $24.99 per month. Extra usage is $5 per GB.
InternetBill class
Declare a constant (a variable with final modifier) to hold price for INTERNET5 internet package.
You may also need to add another field for total charges. Make a defaulto-arg constructor that initializes all the fields to their default values.
Add a second constructor to your class that takes customer name, package name and usage as parameters, and then assigns each parameter to the appropriate field.
Add new service methods to your class:
o calculateCharges: Calculate and return total charges by identifying consumed GBs. It also considers extra usage charge and internet package cost.
o usageCost: this method verifies if usage is more than 25GB or not using if statement.
Declare local variables price, allowed and extraCost.
As we have only one internet package available, set price to the constant field (INTERNET5_PRICE).
If usage is more than 25GB, set allowed to 25 and extraCost to 5. Use an if statement for this purpose.
Call calculateCharges by passing the required arguments.
Add a new method called toString() to InternetBill class. It returns a string. It is used to describe the object in a way the programmer sees fit. In our case, it should return the customers name, package bought, monthly usage and total charges. Use appropriate labels and spacing.
Heres the modified UML (Unified Modelling Language) class diagram for it:
InternetBill
Attributes
private String customerName
private String packageName
private int usage
private double totalCharges
Operations:
public InternetBill()
public InternetBill(String newName,String newPack, int usage)
public String getCustomerName()
public String getPackageName()
public int getUsage()
public void setCustomerName(String newName)
public void setPackageName(String newName)
public void setUsage(int newUsage)
public double calculateCharges(int usedGB, int allowedGB, double extraCharge, double packPrice) public void usageCost()
public String toString()
Note:
You are allowed to change method name and include more/less methods as long as your problem-solving approach is object oriented.
InternetBillTest Class:
Change your InternetBillTester classs main method:
o Create and initialize a Scanner object.
o Using the Scanner object or JOpionPane, ask the user for customer name, package name and usage. This time, use the overloaded version of the constructor to set the InternetBill object.
o Call the newly added method usageCost() to calculate internet charges.
o Call the newly added method toString to print the details and total charges.
Your output should look something like this:
Within the allowed GBs:
Over usage (look for extra charge):

Enter the name of customer: Amrit Braich Enter your package name: INTERNET5 Please enter the usage (in GB) : 25 Amrit Braich has purchased the INTERNET5 internet package The usage for this month is: 25 GB Current Bill: \$24.99 - Over usage (look for extra charge): Enter the name of customer: Amrit Braich Enter your package name: INTERNET5 Please enter the usage (in GB) : 26 Amrit Braich has purchased the INTERNET5 internet package The usage for this month is: 26 GB Current Bill: \$29.99
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
