Question: Can you help with the question below? (OOP - Java NetBeans) If and switch statements in the InternetBill class Open last weeks Lab3-InternetBill project and

Can you help with the question below? (OOP - Java NetBeans)

If and switch statements in the InternetBill class

Open last weeks Lab3-InternetBill project and copy and paste it to a new project for this lab. Call it Lab4 - InternetBill.

This project will incorporate a better version of InternetBill class. We will use a character to identify internet package instead of entering long names, add a new service method to get user input and change the get method to map a character package letter into a string package name.

An Internet service provider has four different internet packages for its customers:

o PACKAGE A (IGNITE_60): 200GB usage for $49.99 per month. Extra usage is $3.00 per GB.

o PACKAGE B (IGNITE_30): 125GB usage for $39.99 per month. Extra usage is $1.50 per GB.

o PACKAGE C (INTERNET_5): 25GB usage for $24.99 per month. Extra usage is $5 per GB.

o PACKAGE D (UNLIMITED_USAGE): For $69.99 per month unlimited access is provided.

We have done some work using package C in previous lab.

This lab calculates and displays the bill for listed internet packages.

InternetBill class

Declare another three constants to hold price for newly introduced internet packages.

Add a new field of type char. Call it cPackName. Optionally, rename packageName to sPackName. Letters c and s help us identify the variables type.

Modify the parameterized constructor to replace string parameter with char.

Add a new method to get user input. This method accepts one parameter of type Scanner.

o Ask for customer name.

o Ask for package letter/character: A, B, C or D. This input is not case sensitive. Your method must be able to handle both lower and upper case letters.

Use Scanners next() to accept this input.

Convert String input to char using charAt() method and save it in appropriate field as: cPackName = stringInput.chartAt(0)

charAt(0) returns the first element of the string.

o If entered letter is not D, then ask for usage in GB.

Modify the getter for package name, to check the character package letter and return the corresponding string package name. Use switch and case statements for this purpose.

Modify usageCost() to set price, allowed and extraCost variables for every package.

Remove the first parameter in calculateCharges() as usage is a field and can be used by this method.

Improve toString(), to display usage only if the package is not D. Remember, call only getters to display the values of fields.

Heres the modified UML (Unified Modelling Language) class diagram for it:

InternetBill

Attributes

private String customerName

private String sPackName

private char cPackName

private int usage

private double totalCharges

Operations

public InternetBill()

public InternetBill(String newName,char newPack, int usage)

public String getCustomerName()

public String getSPackName()

public int getUsage()

public double calculateCharges(int allowedGB, double extraCharge, double packPrice)

public void usageCost() public void takeInput(Scanner scan)

public String toString()

InternetBillTest Class:

Change your InternetBillTester classs main method:

o Create and initialize a Scanner object.

o Create an object of InternetBill class using no-arg constructor.

o Call the newly added method takeInput(), to get user input.

o Call usageCost() and then toString() to print the details and total charges.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!