我正在用Java编写一个程序,其中包含用于保存员工数据的变量,例如
EmployeeCode
EmployeeName
EmployeeDateOfJoining
我已经编写了一个函数,该函数将用户定义的值分配给上述变量。在变量EmployeeDateOfJoining
中,我存储了3-3-2019
之类的值。之后,我想编写另一个函数,要求用户输入当前日期,然后检查雇员的任期是否超过三年。
如果雇员的任期超过三年,则调用该函数否则没有。
package assignment;
import java.util.Scanner;
import java.util.Calendar;
public class EmployeeData {
String EmployeeName, EmployeeCode, DateOfJoining;
Scanner input=new Scanner(System.in);
Calendar c1=Calendar.getInstance();
public void Employee_Data()
{
System.out.println("Enter the employee name:");
EmployeeName=input.nextLine();
System.out.println("Enter Employee code:");
EmployeeCode=input.nextLine();
System.out.println("Current date:"+(c1.get(Calendar.MONTH)+1)+"-"
+c1.get(Calendar.DATE)+ "-" +c1.get(Calendar.YEAR));
}
public void checkdate()
{
System.out.print("Enter his date of joining --> - should be used and all entries must be integer:");
DateOfJoining=input.nextLine();
}
}
这是主要课程
package assignment;
public class Assignment {
public static void main(String[] args) {
EmployeeData E1=new EmployeeData();
E1.Employee_Data();
E1.checkdate();
}
}
如果我输入的日期类似于21-3-2019
,则它应该从当前日期中减去该日期,并以22-3-2018
的格式显示输出