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 188115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:56:49+00:00 2026-05-11T15:56:49+00:00

This is my assignment: Here are my questions: How can I fix this error:

  • 0

This is my assignment:

Here are my questions:

  1. How can I fix this error:

Exception in thread ‘main’ java.lang.NumberFormatException: empty String at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1012) at java.lang.Double.parseDouble(Double.java:527) at extracredit.Main.readData(Main.java:72) at extracredit.Main.main(Main.java:27)

  1. Are there any other problems that you can see with this program?

Here’s my code so far:

    import java.io.*;             import javax.swing.JOptionPane;             import java.util.*;             import java.util.StringTokenizer;              public class Main {      public static void main(String[] args) throws IOException {      String fname = 'data.txt'; //Read in the data file for use in the array      String pass= JOptionPane.showInputDialog('Please enter the ' +              'password to continue:'); /*Have the user enter the password to       access the file. */       checkPass(pass); // Verify that the password is correct before continuing.      readData (fname); // Read data, print output and save output file.    }       private static void checkPass (String pass)     {      String password= 'INF260';      int passCount= 0;           if (pass.equals(password)) {          System.out.println('The password is correct. Continuing...');        }        else {         do {            pass= JOptionPane.showInputDialog('Please re-enter the' +                    'password:');            passCount++;         } while (!pass.equals(password) && passCount < 2);            if (!pass.equals(password)) {             System.out.println('You have tried to enter the ' +                    'password too many times. Exiting...');             System.exit(0);            }            else {                System.out.println('The password is correct. Continuing...');            }        }     }        public static void readData (String data) throws IOException{                        FileReader inputData= new FileReader (data);             BufferedReader findNum= new BufferedReader (inputData);             String str= findNum.readLine ();              int count=-1;             int countNum= 0;              double total= 0;             double min= 0;             double max= 0;             double average= 0;              FileWriter writeFile = new FileWriter('sales.txt');             PrintWriter printFile = new PrintWriter(writeFile);              while (str != null)              {              double num= Double.parseDouble (str);              if (count == 0){                countNum++; // counter of Reciepts to use               }             str = findNum.readLine();         }            double [][] input = new double [countNum][10];             total= getCurrentTotal(input); /*This will get the total               from the method getCurrentTotal.*/             min= getCurrentMin(input); /*This will get the minimum value from             the method getCurrentMin.*/             max= getCurrentMax (input);  /*This will get the maximum value from             the method getCurrentMax.*/              average= (total / countNum);   //Calculate the average.                  System.out.println('The List of Today's Sales:');                 for (int row = 0; row < input.length; row++){                     System.out.println ();                     System.out.println('Customer ' + row + '\t');                     for (int column = 0; column < input[row].length; column++){                        if (input [row].length < 10){                                 System.out.println(input[row][column] + '\t');                         str = findNum.readLine();                     }                                   else{                          System.out.println ('There are too many receipts' +                                 ' for one Customer.\n');                         System.exit (0);                     }                 }              }      System.out.println ('There are ' + countNum + 'receipts in the list.');          /*This will print the total of receipts in the list.*/                           System.out.println ('The total of today's sales is $' + total); /*         This will print the total of the sales for the day.*/     System.out.println ('The average of today's sales is $' + average); /*           This will print the average sale total.*/     System.out.println ('The highest receipt is $' + max); /* This will print           the highest sale.*/     System.out.println ('The lowest receipt is $' + min); /* This will print          the lowest sale.*/     Date date = new Date();         System.out.println ('\n The current time is:' + date.toString()); /* This           will print the current date and time */         }        public static double getCurrentTotal (double [][] input){         double totalAmount = 0;         for (int row = 0; row < input.length; row++){             for (int column = 0; column < input [row].length; column++){                 totalAmount += input [row][column];             }         }         return totalAmount;         }      public static double getCurrentMin (double [][] input) {             double currentMin = input[0][0];          for (int row = 0; row < input.length; row++){             for (int column = 0; column < input [row].length; column++){                 if (currentMin > input[row][column])                     currentMin = input[row][column];                 }             }         return currentMin;     }      public static double getCurrentMax (double [][] input){             double currentMax = input[0][0];         for (int row = 0; row < input.length; row++){             for (int column = 0; column < input [row].length; column++){                 if (currentMax < input[row][column]){                     currentMax = input[row][column];                 }             }             }         return currentMax;     } } 
  • 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. 2026-05-11T15:56:50+00:00Added an answer on May 11, 2026 at 3:56 pm
    // from your main method String fname = 'data.txt'; readData (fname);  // the method being called public static void readData (String data[][]){               BufferedReader br = new BufferedReader(new FileReader(data)); 

    We have an incompatibility here.

    • fname is a String
    • The method takes a String[] as a parameter.
    • the constructor newFileReader() takes a string, not 2d array.

    All of these three should be the same data type.

    How can I separate each ‘receipt’ with zero (like shown in the image link above)?

    You don’t have to. You have to READ from that file with the zeros in it.
    I would recommend you write a method something like this:

    public double[] readOneReceipt(BufferedReader reader);

    This method should

    • Read line by line until it encounters a 0 entry
    • for each entry it reads convert the value into a number (double?)
    • Store the number in a temporary structure.
    • When you encounter the ‘0’, create a new array of the correct size and copy the read values into it.

    How can I write the output into a separate file?

    With a java.io.FileWriter

    The hardest bit of this IMO is the fact that you are told to store the data in a 2d array, but you don’t exactly what size to make the array until you’ve read the data. Which means that you either use a temporary dynamic structure, or read the file twice – once to find out how many receipts there are so that you can make the array, and then again to actually read the receipt data.

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

Sidebar

Ask A Question

Stats

  • Questions 105k
  • Answers 105k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Deploying RoR is not difficult anymore, especially with Phusion Passenger.… May 11, 2026 at 8:45 pm
  • Editorial Team
    Editorial Team added an answer If I were you, I would create a new calculated… May 11, 2026 at 8:45 pm
  • Editorial Team
    Editorial Team added an answer serialize and unserialize would be quicker, if you are using… May 11, 2026 at 8:45 pm

Related Questions

I teach the third required intro course in a CS department. One of my
The "goto" statement comes straight out of ASM or any other assembler language. Here's
In my last job, we worked on a very database-heavy application, and I developed
A recent homework assignment I have received asks us to take expressions which could
If you had to choose your Favorite (clever) techniques for defensive coding, what would

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.