注册 登录
编程论坛 JAVA论坛

在main中调用出错,是不是写少了什么

Vsnow 发布于 2016-10-08 12:09, 2063 次点击
package fourth;
//要求:创建一个corporation类,以基本工资和工作小时为参数,计算出总工资或错误信息,在main()方法中每一个员工调用这个方法
public class corporation {
    String name;
    double basicWage;
    int workHours;
    public corporation(String name,double basicWage,int workHours)
    {    this.name=name;
        this.basicWage=basicWage;
        this.workHours=workHours;
        
        float wage;
        //基本工资小于8元。报错
        if(this.basicWage<8)
            System.out.println("Error!");
        else
        {    //工作时间<40,,基本工资=工作小时*基本工资
            if(this.workHours<=40)
            {    wage=(float)(this.workHours*this.basicWage);
                System.out.println(this.name+"  "+wage);
            }
                //40<工作时间<=60,,超时工资=基本工资*1.5
            else if(40<this.workHours && this.workHours<=60)
            {    wage=(float)(40*this.basicWage+(this.workHours-40)*this.basicWage*1.5);
                System.out.println(this.name+"  "+wage);
            }
            //工作时间超过60小时,则出错
            else
                System.out.println("Error!");
        }
    }   

public static void main(String[] args) {
    corporation cor1=new corporation("员工1",7.50,35);
    corporation cor2=new corporation("员工3",8.20,47);
    corporation cor3=new corporation("员工3",10.00,73);
   
    }
}
4 回复
#2
孤独与烈酒2016-10-08 16:05
把corporation类中的方法名改一下,在mai方法中调用方法传参就行了
#3
反脑控20162016-10-08 16:55
//package fourth;
 //要求:创建一个corporation类,以基本工资和工作小时为参数,计算出总工资或错误信息,在main()方法中每一个员工调用这个方法
 public class corporation {
     String name;
     double basicWage;
     int workHours;
     public corporation(String name,double basicWage,int workHours)
     {    this.name=name;
         this.basicWage=basicWage;
         this.workHours=workHours;
         
         float wage;
         //基本工资小于8元。报错
         if(this.basicWage<8)
             System.out.println("Error!");
         else
         {    //工作时间<40,,基本工资=工作小时*基本工资
             if(this.workHours<=40)
             {    wage=(float)(this.workHours*this.basicWage);
                 System.out.println(this.name+"  "+wage);
             }
                 //40<工作时间<=60,,超时工资=基本工资*1.5
             else if(40<this.workHours && this.workHours<=60)
             {    wage=(float)(40*this.basicWage+(this.workHours-40)*this.basicWage*1.5);
                 System.out.println(this.name+"  "+wage);
             }
             //工作时间超过60小时,则出错
             else
                System.out.println("Error!");
         }
     }   

public static void main(String[] args) {
     corporation cor1=new corporation("员工1",7.50,35);
     corporation cor2=new corporation("员工3",8.20,47);
     corporation cor3=new corporation("员工3",10.00,73);
     
    }
 }
#4
Vsnow2016-10-08 17:04
回复 2楼 孤独与烈酒
OK
#5
Vsnow2016-10-08 17:04
回复 3楼 反脑控2016
谢谢!


1