Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Exception in thread "main" java.util.InputMismatchException !Help!

  1. #1
    Junior Member
    Join Date
    Nov 2019
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Exception in thread "main" java.util.InputMismatchException !Help!

    I have tried many different ways like compareTo == and making service code all uppercase with the strService and made equalsIgnoreCase to just equals and still not working! help!

    here is the whole error message I recieve this is line 49

    System.out.println("Enter Your Day Minutes Used: ");
    dayMinutes = console.nextDouble();



    Exception in thread "main" java.util.InputMismatchException
    at java.util.Scanner.throwFor(Unknown Source)
    at java.util.Scanner.next(Unknown Source)
    at java.util.Scanner.nextDouble(Unknown Source)
    at cellphonebill.cellularbill.main(cellularbill.java: 49)


     
    package cellphonebill;
     
    import java.util.*;
     
    public class cellularbill {
     
    	public static void main(String[] args) {
     
                    Scanner console = new Scanner(System.in);
     
    				final double premiumService = 25.00;
    				final double dayPremiumPerMin = 0.10;
    				final double nightPremiumPerMin = 0.05;
    				final double regularService = 10.00;
    				final double regPerMin = 0.20;
     
    				double nightMinutes;
    				double dayMinutes;
    				double dayMinutes1;
    				double nightMinutes1;
    				double amountDue;
    				double usedMinutes;
    				double usedMinutes1;
     
    				int accountNum;
     
     
    				String serviceCode;
    				String userName;
     
     
    				System.out.println("Enter Your Member Account Number: ");
    				accountNum = console.nextInt();
     
    				System.out.println("Enter Your Name: ");
    				userName = console.next();
     
    				System.out.println("What Type Of Service Do You Have:(Regular or Premium) ");
    				serviceCode = console.next();
     
     
     
     
     
    					{
    					if (serviceCode.equalsIgnoreCase("premium"))
     
    					System.out.println("Enter Your Day Minutes Used: ");
    					dayMinutes = console.nextDouble();
     
    					if(serviceCode.equalsIgnoreCase("premium"))
     
    					System.out.println("Enter Your Night Minutes Used: ");
    					nightMinutes = console.nextDouble();
     
    					{				
    					if (dayMinutes > 75)
    					dayMinutes1 = dayMinutes - 75;
     
    					else
    					dayMinutes1 = dayMinutes - dayMinutes;
    					}
     
    					{
    					if (nightMinutes > 100)
    					nightMinutes1 = nightMinutes - 100;
     
    					else
    					nightMinutes1 = nightMinutes - nightMinutes;
    					}
     
    					amountDue = (dayMinutes1 * dayPremiumPerMin) + (nightMinutes1 * nightPremiumPerMin) + (premiumService);
     
    					System.out.println(
    							  "Account Number: /r/n" + accountNum 
    							+ "Service Type: /r/n" + serviceCode 
    							+ "Minutes Service Used (Day): /r/n" + dayMinutes 
    							+ "Minutes Service Used (Night):/r/n" + nightMinutes 
    							+ "Amount Due: " + amountDue);
    					}
     
     
     
     
     
     
    					{
     
    					if (serviceCode.equalsIgnoreCase("regular"))
     
    					System.out.println("Enter Your Minutes Used: ");
    					usedMinutes = console.nextDouble();
     
    					if (usedMinutes > 50)
    					usedMinutes1 = usedMinutes - 50;
     
    					else
    					usedMinutes1 = usedMinutes - usedMinutes;
     
    					amountDue = (usedMinutes1 * regPerMin) + (regularService);
     
    					System.out.println(
    							 "Account Number: /r/n" + accountNum 
    							+" Service Type: /r/n" + serviceCode 
    							+" Minutes Service Used: /r/n" + usedMinutes
    							+" Amount Due: /r/n" + amountDue);
     
    					}
     
     
     
     
     
     
    				console.close();
     
    			}
     
    		}
    Last edited by AabNormal22; November 4th, 2019 at 03:18 PM. Reason: Proper Format On Message Boards & Full Error

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Exception in thread "main" java.util.InputMismatchException !Help!

    Please copy the full text of the error message and paste it here. It has important info about the error.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    AabNormal22 (November 4th, 2019)

  4. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Exception in thread "main" java.util.InputMismatchException !Help!

    at java.util.Scanner.nextDouble(Unknown Source)
    at cellphonebill.cellularbill.main(cellularbill.java: 49)
    The user entered a value that was not a double when the call to nextDouble on line 49 was made. It's hard to make a user enter valid numbers, but for testing you should be careful to always enter a valid value.

    One BIG PROBLEM in the code is the misplaced and mis-used {}s. {}s should always be used with if statements:
       if(the condition) {
          // the code to do when the condition is true goes inside the {}s
       }

    There are other {}s that do not have any reason to be there. For example the { BEFORE the if statement.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 6
    Last Post: August 16th, 2014, 01:34 AM
  2. Replies: 1
    Last Post: September 24th, 2013, 02:22 AM
  3. Replies: 3
    Last Post: April 27th, 2013, 09:07 AM
  4. Replies: 11
    Last Post: August 30th, 2012, 02:30 PM
  5. Replies: 2
    Last Post: March 23rd, 2010, 01:38 AM

Tags for this Thread