Link to home
Start Free TrialLog in
Avatar of drunk0ffhate
drunk0ffhate

asked on

internet service provider java coding

Internet Service Provider
An Internet service provider 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 program that calculates a 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 the number of hours that were used. It should then display the total charges.


I started off with only package A to see if it would work, but it doesn't and I am getting a lot of error messages that I don't understand. What am I doing wrong with this first part?


import java.util.Scanner;

public class InternetPackages

{
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
      char packageLetter=0;
      int totalHours, regularHours, additionalHours=0;
      double monthlyFee, additionalHoursFee=0, totalFee; 
           
      
      System.out.println("Enter the letter of package purchased (either A, B, or C.");
      System.out.println("Enter the number of hours used"); 
      totalHours = input.nextInt();
      
      
      switch (packageLetter)
      
      
      {
      case 'A':
      case 'a':
      monthlyFee = 9.95;
      regularHours = 10;
      additionalHoursFee = additionalHours * 2.00;
      totalFee = monthlyFee + additionalHoursFee;
      System.out.print ("The total charges is $" + totalFee + ".");
      break; 

Open in new window

Avatar of kaufmed
kaufmed
Flag of United States of America image

What error messages are you receiving?
Avatar of drunk0ffhate
drunk0ffhate

ASKER

Exception in thread "main" java.util.InputMismatchException
	at java.util.Scanner.throwFor(Scanner.java:909)
	at java.util.Scanner.next(Scanner.java:1530)
	at java.util.Scanner.nextInt(Scanner.java:2160)
	at java.util.Scanner.nextInt(Scanner.java:2119)
	at InternetPackages.main(InternetPackages.java:19)

Open in new window


After compiling everything it says operation complete, but when I enter the values it gives me those error messages.
Look at lines 4 - 6. Your first prompt asks for a letter, but then it never gets input from the user. It just prints out the next prompt which asks for a number. If you are entering a letter in response to the first prompt, then the first line of code that expects input from the user (line 6) is looking for an integer, not a letter. Add in a line that will accept the input of a letter from the user.
Scanner input = new Scanner(System.in);
      char packageLetter=0;
      int totalHours, regularHours, additionalHours=0;
      double monthlyFee, additionalHoursFee=0, totalFee; 
      String inputString;
           
      
      System.out.println("Enter the letter of package purchased (either A, B, or C.");
      packageLetter = inputString.charAt(0);
      System.out.println("Enter the number of hours used"); 
      totalHours = input.nextInt();

Open in new window




Like this? I changed it but now it says that inputString.charAt(0);   hasnt been initialized
How do you get input from the user? (Hint, you're doing it in line 11 of your last post.) Look at the documentation for the Scanner class and determine which method would be appropriate to receive a letter as input.
Oh ok, so this is it?

System.out.println("Enter the letter of package purchased (either A, B, or C.");
      packageLetter = input.nextChar();

Open in new window


It cannot find that symbol though so how would I add that into my coding?
It cannot find that symbol though...
You mean that the IDE does not recognize the nextChar method? If so, what version of Java are you using?
ASKER CERTIFIED SOLUTION
Avatar of krakatoa
krakatoa
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So I take it that none of my input was helpful?