0

so i've been working on this code for awhile and gotten a lot of the errors fixed but now when the user enter numbers as the payrates its giving me some weird errors, first ill post the code than ill post the errors

import java.util.Scanner;
import java.util.*;
public class project3
{
   private static double[] payrate;
   private static String[] names;


   public static void SortData(double payrate[])
    {
         int first;
         int temp;
         int i;
         int j;
         for(i = payrate.length - 1; i > 0; i--)
         {
            first = 0;
            for(j = 1; j<=i;j++)
            {
               if(payrate[j]<payrate[first])
               first = j;
            }
            temp = (int)payrate[first];
            payrate[first] = payrate[i];
            payrate[i] = temp; 
         } 
    }

   public static void GetData()
   {

    Scanner input = new Scanner(System.in);
     System.out.println("How many names do you want to enter?");
                String strNum = input.nextLine();
                int num = Integer.parseInt(strNum);
                int array[] = new int[num];
                for (int i = 0  ; i < array.length ; i++ ) 
                    {
                        names = new String[num];


                        System.out.println("enter employee's name: ");

                        names[i] = input.nextLine(); 
                        //while(names[i].length < 2)
                        //{
                           //System.out.println("enter valid employee's name: ");

                        //names[i] = input.nextLine(); 
                        //} 

                    }
                for(int j = 0; j < array.length;j++)
                    {
                        payrate = new double[num];
                        System.out.println("enter employee's payrate: ");
                        payrate[j] = input.nextDouble();
                        while(payrate[j] > 100 || payrate[j] < 0)
                        {
                           System.out.println("enter valid employee's payrate: ");
                           payrate[j] = input.nextDouble();
                        }


                     }


   }
        public static void DisplayData(double payrate[], String names[])
    {

         System.out.printf("Name    PayRate\n");
         for (int l=0; l< names.length; l++) 
         {

           //for(int i=0;i<names.length;i++)
          // {
              System.out.print(names[l]);

           System.out.printf("%6d\n", payrate[l]);

           //} 
      }
    }

    public static void main(String[] args)
   {
      GetData();
      SortData(payrate);
      DisplayData(payrate,names);

   }

The errors its giving me is I'm the DisplayData Method I think , This is the error:

nullException in thread "main" java.util.IllegalFormatConversionException: d != java.lang.Double
    at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4302)
    at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2793)
    at java.util.Formatter$FormatSpecifier.print(Formatter.java:2747)
    at java.util.Formatter.format(Formatter.java:2520)
    at java.io.PrintStream.format(PrintStream.java:970)
    at java.io.PrintStream.printf(PrintStream.java:871)
    at project3.DisplayData(project3.java:80)
    at project3.main(project3.java:90)
kyle
  • 9
  • 2

1 Answers1

-1

You're using an incorrect format string. See for example this related question: Java: Double % formatting question for printf

Community
  • 1
  • 1
Evert
  • 354
  • 2
  • 7
  • a link only answer is bad, a link only answer that bears out that this is a duplicate is even worse, the appropriate action is to vote to close as the duplicate or flag as a duplicate so those that can vote to close will see it in the queues. do not answer duplicates. –  Feb 23 '16 at 20:56