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

In Java An ISP has three different subscription packages for its customers: Pack

ID: 3674439 • Letter: I

Question

In Java

An ISP has three different subscription packages for its customers: Package A: For $9.95 per month, 10 hours of access are provided. Additional hours are $2.00 per hour. Package B: For $13.95 per month, 20 hours of access are provided. Additional hours are $1.00 per hour. Package C: For $19.95 per month unlimited access is provided. Write a menu driven program [SWITCH statement] that calculates that customer's monthly bill. It should ask the user to enter the letter of the package the customer has purchased (A, B or C) and number of hours that were used. It should then display the total charges. Once the above part works perfectly, now modify the code to include input validation that input letter choice is from {A, B, C} and the amount of hours given by the user is a positive value. only. (For this, put additional conditional statements in the original code where user feeds the value). If any of the above input validation fails, display an error message "ERROR: Check your input values!"

Explanation / Answer

import java.util.Scanner;


public class HelloWorld {
   public static void main (String args[])
   {
       do
       {
           printMonthlyBill(calculateBill(getHours(), menu()));
       }
                               while(true);
   }
  

   public static double getHours()
   {
       double hours;
       int flag=0;
       Scanner inputHours = new Scanner (System.in);
       do
                              {
       System.out.print("Please enter the hours used: ");
       hours = inputHours.nextDouble();
       if (hours<=0) {
                                              System.out.println("Error:Check your input values!");
                                 }
                                 else
                                 flag=1;
                            }while(flag==0);
       inputHours.close();
      
       return hours;
   }

   public static int menu ()
   {
       int packageChoice;
       int flag=0;
Scanner userInput = new Scanner (System.in);
do
{
       System.out.println(" [1] Package A");
       System.out.println("[2] Package B");
       System.out.println("[3] Package C");
       System.out.print("Please select your package: ");
       packageChoice = userInput.nextInt();
       if(packageChoice>0 && packageChoice<4)
       {
                                System.out.println("Error:Check your input values!");
       }
       else
       flag=1;
       }while(flag==0);
       return packageChoice;
   }
  
   public static double calculateBill(double hours, int packageChoice)
   {
       switch (packageChoice)
       {
           case 1:
               if (hours < 10)
               {
                   return 9.95;
               }
              
               else
               {
                   return (hours - 10)*2 + 9.95;
               }
              
           case 2:
               if (hours < 20)
               {
                   return 13.95;
               }
              
               else
               {
                   return (hours - 20) + 13.95;
               }          
           case 3:
               return 19.95;
              
           default:
               System.out.println(" Invalid input!");
               return 0;
       }
   }
  
   public static void printMonthlyBill(double bill)
   {  
       if (bill != 0)
           System.out.println(" Your monthly bill is $" + bill + " ");
       else
           System.out.println(" ");
   }
}

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