我正在尝试显示由员工完成的认证。在一个数组中说“certificates”我持有在创建雇员时输入的证书。现在我希望我的员工通过将证书添加到同一数组来更新他的“证书”。我想显示更新后员工完成的总认证列表。这是我的密码
{
private String FirstName, LastName;
protected float salary;
private char grade;
private int empid;
private static int i;
private int j;
private Date1 dt; //*//
private int experience;
private String designation;
final String var1 = "YES";
String var2;
Scanner enterCertificate = new Scanner(System.in);
private String[] certificate = new String[]{};
// CONSTRUCT
public Employee(String nmf, String nml, float sal, char gd, Date1 dt, int experience, String designation, String[] certificate)
{
FirstName = nmf;
LastName = nml;
salary = sal;
this.dt = dt; //*//
grade = gd;
this.experience = experience;
this.designation = designation;
this.certificate = certificate;
empid = ++i;
}
// DISPLAY
public void display()
{
System.out.println("Employee"+empid+ " Complete Details : ");
System.out.print('\n');
System.out.println("Employee FirstName is " + FirstName);
System.out.println("Employee LastName is " + LastName);
System.out.println("Employee Salary is Rs." + salary);
System.out.println("Employee Grade is " + grade);
System.out.print("Joining Date is ");
dt.DateDisplay();
System.out.println("Employee experience is " + experience + " Years");
System.out.println("Employee Designation is " + designation);
}
public String[] updateCertificate()
{
System.out.println("Do you want to update certification ? YES/NO");
Scanner scanner3 = new Scanner(System.in);
var2 = scanner3.nextLine();
if(var1.equalsIgnoreCase(var2))
{
System.out.println("Enter Certification Details for any Updates: ");
this.certificate[j] = enterCertificate.nextLine();
}
else
{
return null;
}
return certificate;
}
public String toString()
{
return FirstName + ", " + "Employee ID: " + empid + ", " + experience + " Years Experience"+ ", " + designation + ", " + "Certification: " + certificate[j]+ ".";
}
// ID DISPLAY
public static void count()
{
System.out.println("Total number of employees is " + i);
}
@Override
public String[] displayUpdateCertificate()
{
String[] displaycertificate = new String[5];
displaycertificate = certificate;
if(var1.equalsIgnoreCase(var2))
{
System.out.println("Displaying updated certificate List.....");
System.out.println(Arrays.toString(certificate));
}
else
{
System.out.println("No Certificates were updated....");
}
return displaycertificate;
}
}
我的主要课程是这样的。。。。。
public static void main(String[] args)
{
Date1 dt = new Date1(12,11,2015); //*//
Employee emp1,emp2,emp3,emp4,emp5;
emp1 = new ProjectManager("MaheshKumar","Siddaraju",16700,'A',dt, 7, "Project Manager",new String[] {"PMI"}); // To input array as parameter new String[] form is used
((ProjectManager)emp1).ProjectManagerDisplay(); //Downcasting
emp2 = new ContractTechnicalAssociate("Mohammad","Javeed",0,'A',dt, 5, "Contract based Technical Associate",new String[] {"SCJP"});
((ContractTechnicalAssociate)emp2).ContractTechnicalAssociateDisplay();
emp3 = new TechnicalAssociate("Aruna","Daggubati",16700,'A',dt, 6, "Technical Associate",new String[] {"SCJP"});
((TechnicalAssociate)emp3).TechnicalAssociateDisplay();
emp4 = new ProjectManager("Kiran","Vadlamudi",16700,'A',dt, 4, "Project Manager",new String[] {"PMI"});
((ProjectManager)emp4).ProjectManagerDisplay();
emp5 = new TechnicalAssociate("Neenu","Sebastian",16700,'A',dt, 9, "TechnicalAssociate",new String[] {" "});
((TechnicalAssociate)emp5).TechnicalAssociateDisplay();
Employee.count();
scanner = new Scanner(System.in);
int i;
while(true)
{
System.out.println("Enter EmployeeID to get Employee short details : ___ ");
i = scanner.nextInt();
System.out.println("Employee ID entered is: " + i);
System.out.println("Fetching Employee Details......" + '\n');`
所以我想用主类中的这些添加更新的证书
1条答案
按热度按时间ibrsph3r1#
您应该使用arraylist或使arraycopy复制到长度为+1的新数组。