I am a little confused! We are doing classes, constructors and methods in class at the moment and I get the basics. Leap forward to 2am in the morning and 4 hours of searching on the net for a solution to my question and I am back at stackoverflow looking for advice.
I have built my class and in it I have my get and sets. I will add my class now.
public class staff
{
private String empName;
private int prefix;
private int dialCode;
private int telNum;
private double grossSalary;
public staff( String name, int prefix1, int dial, int celNum, double salary)
{
empName = name;
prefix = prefix1;
dialCode = dial;
telNum = celNum;
grossSalary = salary;
}
The next part is where I am getting confused. I am now trying to populate this all using a Scanner but I am getting an error. As always I am not looking for an out right answer but more a nudge in the right direction. Here is the second part to my code.
import java.util.Scanner;
public class staffInfo
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
String staffName [] = new String [4];
int staffPrefix [] = new int [4];
int staffDialCode [] = new int [4];
int staffCellNum [] = new int [4];
double staffSalary[] = new double [4];
int i = 0, j = 0;
for(j = 0; j < staffName.length; j++)
{
for(i = 0; i < staffName.length; i++)
{
System.out.print("Please enter staff name and press return : ");
staffName [i] = input.nextLine();
System.out.print("Please enter there cell number prefix : ");
staffPrefix [i] = input.nextInt();
System.out.print("Please enter dialing code : ");
staffDialCode[i] = input.nextInt();
System.out.print("Please enter cell number : ");
staffCellNum[i] = input.nextInt();
System.out.print("Please enter there salary : ");
staffSalary[i] = input.nextDouble();
}
staff staff[j] = new staff(staffName,staffPrefix,staffDialCode,staffCellNum,staffSalary);
}
}
}
Thanks in advance for any help you may offer me.
Matthew
Aucun commentaire:
Enregistrer un commentaire