Question

ntermetrovider-Noteps Fil Ei Fo i Hl public static vold matn String args) Sranner sr Scanner Syston.in); final doule PACKACE ABASE PRICE 9.95; inal double PALKALE H ASE PHICE 14. final double PACKACE C BASE PRICE 19.95 final int PKNGFI TMTT HOIRS-1a final irt PACKAGE D LIMIT HOJRS 29 inal double PAKAEXIHA HEL-1; int userHours; double cxtr Charge e double totdIB?11-3 string userPackags; ?); Systen.cut.print1n(Lnter the custoers packago: userPatkage c.nextlineC Systen.cut.println(Enter the nuter of hours used: ); userHours -s.nextat) if (userPackage.equalsIgnureaea 1f ?userHour. PACKAGE. A-I INIT-HEARS) { > hoursExcceded-uscrHourt- PACKAGE A LIMIT HOURS ota-extraharg PACKAA RASE PRICF hoursExceeded-userHours PACKAGE B LIMIT HOURS extraCharge-hoursFxceeded ? PACKAGF ? FXTRA FFF; Lala1Bi11 PACKGECBASE PRICE System.ot.pintYcu rhase narkage userparkaee); Systen,vut print(Totsl o ue userHours) Systen.out.print The charges are: extraCharge

i have created this java program but need help by making it the userHours limited to only 0 to 720 for all packages. If any number higher than 720, get this display

Invalid input, please enter number of hours between 0 & 720.  

Let’s try again.  
Enter the customer's package (A, B, or C): A

and allows you to choose a different package from the given.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Java Program:

import java.util.*;

class PackageFee {
  
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
      
       final double PACKAGE_A_BASE_PRICE = 9.95;
       final double PACKAGE_B_BASE_PRICE = 12.95;
       final double PACKAGE_C_BASE_PRICE = 19.95;
      
       final int PACKAGE_A_LIMIT_HOURS = 10;
       final int PACKAGE_B_LIMIT_HOURS = 20;
      
       final double PACKAGE_A_EXTRA_FEE = 2;
       final double PACKAGE_B_EXTRA_FEE = 1;
       int userHours;
       int hoursExceeded = 0;
       double extraCharge = 0;
       double totalBill=0;
      
       String userPackage;
      
       //Loop till user enters correct value
       do {
           //Reading customer package
           System.out.println("Enter the customer's package: ");
           userPackage = sc.nextLine();
          
           //Reading number of hours used
           System.out.println("Enter the number of hours used: ");
           userHours = sc.nextInt();
          
           //Validating number of hours used
           if(userHours < 0 || userHours > 720)
           {
               //Printing error message
               System.out.println("Invalid input, please enter number of hours between 0 & 720.\nLet's try again.\n");              
           }
          
           //Ignoring new line
           sc.nextLine();
       }while(userHours < 0 || userHours > 720);
      

       /* Remaining code here */
   }
}

____________________________________________________________________________________________

Sample Run:

C:Windows system32 cmd.exe D:Java> javac PackageFee.java D:Java> java PackageFee Enter the customer s package: Enter the numb

Add a comment
Know the answer?
Add Answer to:
i have created this java program but need help by making it the userHours limited to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Java, I have created a program which can generate passwords. Currently the program can generate...

    In Java, I have created a program which can generate passwords. Currently the program can generate a password through a menu system of which characters to use. To complete the project, I need a system which allows the user to generate another password after the first password is created. I also need a method to check whether or not the password is complex by checking if the generated password has 3 or more character types and then displaying whether or...

  • Can you please help me to run this Java program? I have no idea why it...

    Can you please help me to run this Java program? I have no idea why it is not running. import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.DecimalFormat; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.ListSelectionModel; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; @SuppressWarnings({"unchecked", "rawtypes"}) public class SmartPhonePackages extends JFrame { private static final long serialVersionID= 6548829860028144965L; private static final int windowWidth = 400; private static final int windowHeight = 200; private static final double SalesTax = 1.06; private static JPanel panel;...

  • I have a java project that I need help trying to finish. I have most of it completed but the issue I am running into is adding numbers with different lengths. Project requirements: . Use a Stack ADT w...

    I have a java project that I need help trying to finish. I have most of it completed but the issue I am running into is adding numbers with different lengths. Project requirements: . Use a Stack ADT with the implementation of your choice (Array or Link), it should not make a difference 2.Read two “integer” numbers from the user. Hint: You don’t need to use an int type when you read, it may be easier to parse the input...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT