Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8762561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:33:35+00:00 2026-06-13T15:33:35+00:00

This program has 2 classes with a main method and is supposed to read

  • 0

This program has 2 classes with a main method and is supposed to read from a file. My problem is that the line double listPrice = fileScan.nextDouble(); gives an error exception like this Exception in thread "main" java.util.InputMismatchException. The error is in this class:

Here is contents of the file:
Honda Accord

2004 16780.00 10.0

Chrysler SUV

2002 8600.00 0.0

Toyota Camry

2007 21799.99 3.0

Ford Escort

2006 12345.78 5.5

//note there is no space between each line

class Proj1P2CarAryListService 
{

  private ArrayList<Proj1CarData> carList = new ArrayList<Proj1CarData>();

  public Proj1P2CarAryListService()
  {
     carList = new ArrayList<Proj1CarData>();
  }

  public void readStoreCarsData()
  {


     Scanner scan = new Scanner(System.in);

     Scanner fileScan;
     boolean validName = false;
     double discountAmount;
     double netPrice;

     do 
     {

        System.out.print("Enter file name: ");
        String str1 = scan.nextLine();

        try 
        {

           fileScan = new Scanner(new File(str1));
           validName = true;


           while (fileScan.hasNext())

           {

              String name = fileScan.nextLine();
              String modelYear = fileScan.next();
              double listPrice = fileScan.nextDouble();
              double percentDiscount = fileScan.nextDouble();

              discountAmount = listPrice * percentDiscount/100.0;
              netPrice = listPrice - discountAmount;

              Proj1CarData proj1 = new Proj1CarData(name, modelYear, listPrice, percentDiscount, discountAmount, netPrice);
              carList.add(proj1);
              System.out.println(proj1.toString());

           }// end while

        }// end try

           catch (FileNotFoundException fnfe)
           {
              System.out.println("Invalid File name; enter again");
           }

     } while (!validName);


  }//readStoreCarsData
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:33:36+00:00Added an answer on June 13, 2026 at 3:33 pm

    This exception is thrown by a Scanner to indicate that the token retrieved does not match the pattern for the expected type(Double must be separated by . or , like said jlordo), or that the token is out of range for the expected type. Perhaps it is a file content problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a program that has three classes: Output class receives data from other
I am working with an architecture that has a main program. When this starts
I wrote this short program which has a tiny GUI. Its supposed to allow
In this c program a=8; main() { printf(%d, a); } variable a has been
Wanting to make sure I'm using classes properly. The main script accepts this from
I have two classes: Action class, that has a method for executing VBScript files,
I have a program that has Classes GUI Upload and a buffer between the
My program has a handful of classes, and 2 forms. My first form Main
I am making a program with native C++ and the WinAPI. This program has
This program I use has it's own variables to set when you run it,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.