扫描仪和 class

Scanners and class

我们目前正在 class 中进行 classes、构造函数和方法,我掌握了基础知识。快进到凌晨 2 点,我花了 4 个小时在网上搜索我的问题的解决方案,然后我回到 Stack Overflow 寻求建议。

我已经构建了我的 class 并且在其中我有我的 get 和 sets:

 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;
    }

下一部分是我感到困惑的地方。我现在正尝试使用扫描仪填充这一切,但出现错误。一如既往,我不是在寻找正确的答案,而是在寻找正确的方向。这是我的代码的第二部分。

    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);
        }

    }

}

你的最后一行不会编译。

查看您传递给员工构造函数的参数 class,类型是否匹配?

此外,您必须将员工数组的声明与赋值分开。您对 staffName、staffPrefix 等做得很好