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)