如果您想知道我的程序的目的是什么,可以查看我以前的问题。这是我几乎完成的代码:
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[] employees = new Employee[num];
for (int i = 0; i < num; i++)
{
eNumber = getInt ("Enter Employee Number:");
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):");
Name name = new Name(input2, input3);
Address address = new Address (input4, input5, input6, input7);
Date hireDate = new Date (input8, input9, input10);
employees[i] = new Employee (eNumber, name, address, hireDate);
System.out.println("#" + employees[i].empNumber + "\n" + employees[i].empName + "\n" + employees[i].empAddress + "\nHire Date: " + employees[i].empHireDate + "\n\n");
}
}
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
{
Number empNumber;
Name empName;
Address empAddress;
Date empHireDate;
public Employee(Number empNumber, Name empName, Address empAddress, Date empHireDate)
{
this.empNumber = empNumber;
this.empName = empName;
this.empAddress = empAddress;
this.empHireDate = empHireDate;
}
}
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;
}
}
我希望我的程序显示通过命令行指定的员工数量的信息(例如,我键入“java AssignmentTen 3”来记录三个不同员工对象的数据)。我希望信息显示如下:
[#]员工编号
名字姓氏
街道城市州首字母邮政编码
入职日期:MM DD YYYY
例如:
#123
约翰·史密斯
123 示例街 CA 12345
入职日期:2013 年 9 月 30 日
但是,最终显示的内容根本不正确。员工编号显示正常,但名称行显示为“姓名@[RandomCharacters]”,地址行显示为“地址@[RandomCharacters]”,雇用日期行显示为“雇用日期:日期@[随机字符]”。我怎样才能让它显示我想要的方式(包括单词之间的空格和分隔月、日和年的斜线)?
谢谢。
编辑:我添加了接受的答案建议的更改,但我仍然遇到日期线问题。我使用了这段代码:
class Date
{
int month;
int day;
int year;
Date(int eMonth, int eDay, int eYear)
{
month = eMonth;
day = eDay;
year = eYear;
}
public String toString()
{
return month + "/" + day + "/" + year;
}
}
但它仍然想出了随机字符。