我对 Java 很陌生。我必须创建一个模拟员工的程序。该员工有员工编号、名字和姓氏、由街道、城市和州组成的地址,以及由月、年和日组成的雇用日期。这是我的代码:
import javax.swing.JOptionPane;
public class AssignmentTen
{
public static void main (String[] args)
{
System.out.println();
int num = Integer.parseInt(args[0]);
int eNumber;
String input2;
String input3;
String input4;
String input5;
String input6;
int input7;
int input8;
int input9;
int input10;
Employee[] employee = new Employee[num]
for (int i = 0; i < num, i++)
employee[i] = new Employee()
input2 = getString ("Enter Employee First Name:");
input3 = getString ("Enter Employee Last Name:");
input4 = getString ("Enter Employee Street:");
input5 = getString ("Enter Employee City:");
input6 = getString ("Enter Employee State (Initials):");
input7 = getInt ("Enter Employee Zip Code (5 Digits):");
input8 = getInt ("Enter Employee Hire Month (MM):");
input9 = getInt ("Enter Employee Hire Day (DD):");
input10 = getInt ("Enter Employee Hire Year(YYYY):");
eNumber = getInt ("Enter Employee Number:");
System.out.println("#" + eNumber);
Name n1 = new Name(input2, input3);
System.out.println(n1.firstName + " " + n1.lastName);
Address a1 = new Address (input4, input5, input6, input7);
System.out.println(a1.eStreet + " " + a1.eCity + " " + a1.eState + " " + a1.eZipCode);
Date d1 = new Date (input8, input9, input10);
System.out.println("Hire Date: " + d1.month + "/" + d1.day + "/" + d1.year);
}
public static int getInt(String paramString)
{
String str = JOptionPane.showInputDialog(paramString);
return Integer.parseInt(str);
}
public static String getString(String paramString)
{
String str = JOptionPane.showInputDialog(paramString);
return str;
}
}
class Employee
{
}
class Name
{
String firstName;
String lastName;
Name(String first, String last)
{
firstName = first;
lastName = last;
}
}
class Address
{
String eStreet;
String eCity;
String eState;
int eZipCode;
Address(String street, String city, String state, int zipCode)
{
eStreet = street;
eCity = city;
eState = state;
eZipCode = zipCode;
}
}
class Date
{
int month;
int day;
int year;
Date(int eMonth, int eDay, int eYear)
{
month = eMonth;
day = eDay;
year = eYear;
}
}
如何让 Employee 类使用 Name、Address 和 Date 类作为构造函数来将所有员工信息存储在一个对象中?此外,我的程序中需要有一个单独的 Employee、Name、Address 和 Date 类。另外,如何创建一个 for 循环来创建多个等于 num 整数(从命令行输入)的员工对象,以便每个对象都有自己的名称、日期和地址?
我知道这段代码可能不会编译,我只需要完成它。