我是初学者,我几乎什么都不知道,我厌倦了做一些课程而且只是乱用方法,但由于某种原因这种方法不会打印,我也很难用数组:( < / p>
主要课程:
public class Employees {
static Employee[] array =new Employee[3];
static int i=0;
public void insertEmployee(){
Scanner keyboard=new Scanner(System.in);
System.out.println("please fill in the information :");
System.out.println("name :");
String Name=keyboard.next();
System.out.println("ID :");
long ID=keyboard.nextLong();
System.out.println("Salary :");
double Salary =keyboard.nextDouble();
Citizen s2 =new Citizen(Name);
Employee E= new Employee(ID,s2,Salary);
array[i]=E;
}
public void main(String[] args) {
Employees m1=new Employees();
for ( i=0; i<3;++i){
Employees c1=new Employees();
c1.insertEmployee();
}
System.out.println("*****");
for (i=0;i<3;++i){
array[i].print();
}
}
}
第二课:
public class Employee {
private Citizen employeeInfo =new Citizen();
private long employeeID;
private double employeeSalary;
Employee(long employeeID,Citizen employeeInfo ){
this.employeeID=employeeID;
this.employeeInfo=employeeInfo;
}
Employee(long employeeID,Citizen employeeInfo, double employeeSalary){
this.employeeID=employeeID;
this.employeeInfo=employeeInfo;
this.employeeSalary=employeeSalary;
}
void print(){
if (employeeSalary==0){
employeeSalary=-1;
}
System.out.println(employeeID+"-"+employeeInfo.getCitizenName()+"-"+employeeSalary);
}
}
和最后一个:
public class Citizen {
private String citizenName;
private long citizenID;
public Citizen(){
}
public Citizen(String Name){
this.citizenName=Name;
}
public Citizen(String citizenName,long citizenID){
this.citizenName=citizenName;
this.citizenID=citizenID;
}
public String getCitizenName(){
return citizenName;
}
public long getCitizenID(){
return citizenID;
}
}
谢谢你:)
答案 0 :(得分:-1)
必须是public static void main(String[] args)
。 static
很重要