Java员工计划

时间:2015-03-05 07:42:25

标签: java

我一直在做一个程序,作为一个安静的任务现在,我似乎无法让它正常工作当我返回我的员工名称时,它只显示为 employee.Employee@7f787395 即可。如果我将第一个员工设置为empTypes之一,我不知道怎么做。所以我想知道是否有人能告诉我该怎么做或者我在哪里错了。

class employee {
private static int empCount;
private String empName;
private double empSalary;
private double empRate;
private double empHour;
private double empBase;
private static int empPieces;
private static int empType;

public employee(String name){
this.empName = name;
empCount++;
}

 public String getName(){   
 return this.empName;    
 }

重载方法setEmployeePay( )以适应基于empType的不同付款方式:

public void setEmployeePay(double Salary){

empType = 2; 
Salary = 45350.00;
}
public void setEmployeePay(double rate, double hours){

empType =1;
rate = 22.50;
hours = 35.0;

}
 public void setEmployeePay(double base, int pieces){
base = 500.00;
pieces = 25;
empType =3;

}

静态字段empCount跟踪实例化员工的数量,可以使用静态方法getCount( )

进行检索
    public static int getCount(){
    int empCou = 1;
    empCou = empCou + 1;

    return empCou;
 }

 public static int getNumber(){
 Random random = new Random(); 
     int empnumber = 1000 + random.nextInt(9999);

 return empnumber;
 }

这里是我想让它返回1000到9999之间的数字,但我似乎无法做到这一点

 public double calculatePay(){

     return empSalary;
 }

方法calculatePay( )将根据付款类型确定员工的每周工资是多少,但我不知道我将在这里做什么

 }

这是我的主要方法

package employee;

import java.util.Random;
import java.util.Scanner;


public class Lab3 {

public static void main(String[] args, int empCount) {
    Scanner input = new Scanner(System.in);
    empCount = 0;


    System.out.printf("Enter Employee Name: " );
    String name =input.next();
    Employee e1= new Employee(name);
    System.out.printf( "Employee count is " + empCount+ "\n" );


    e1.setEmployeePay(253553);
    System.out.printf("Enter Employee Name: ");
    name =input.next();
    Employee e2= new Employee(name);
    System.out.println( "Employee count is " + empCount );


    System.out.printf("Enter Employee Name: ");
    name =input.next();
    Employee e3= new Employee(name);
    System.out.println( "Employee count is " + empCount );


    System.out.printf("Enter Employee Name: ");
    name =input.next();
    Employee e4= new Employee(name);
    System.out.println( "Employee count is " + empCount );


   System.out.println("Employee "+empnumber+ e1.getName()+" earned: " +"");
   System.out.println("Employee "+empnumber+ e2.getName()+" earned: " +"");
   System.out.println("Employee "+ empnumber+ e3.getName()+" earned: " +"");
   System.out.println("Employee " + empnumber +e4.getName()+" earned: " +"");




}

2 个答案:

答案 0 :(得分:1)

尝试覆盖Employee类中的toString方法,如:

public String toString() {
    return "empName: " + empName ...;
}

答案 1 :(得分:1)

//只需将该类重命名为Employee //

班级员工{

}