当前位置: 代码迷 >> Java相关 >> show 出现错误
  详细解决方案

show 出现错误

热度:587   发布时间:2009-11-01 21:18:07.0
show 出现错误
abstract class EmpDemo
{
    String name;
    double basicSalary;
    double totalSalary;
    public EmpDemo(){}
    public EmpDemo(String _name, double _basicSalary)
    {
        name = _name;
        basicSalary = _basicSalary;
    }
   
    public abstract void paySalary();
}
class Seller extends EmpDemo
{
    double totalSalary;
    int daytime = 8;
    int hourget = 10;
    public Seller(String _name, double _basicSalary, int daytime, int hourget)
    {
        name = _name;
        basicSalary = _basicSalary;
    }
   
    public void paySalary()
    {
        totalSalary = basicSalary + 30 * daytime * hourget;
    }
   
    void showSeller()
    {
        System.out.println("销售员" + name + "的薪水为:" + totalSalary);
    }
}
class Manager extends EmpDemo
{
    double totalSalary;
    int times = 12;
    public Manager(String _name, double _basicSalary, int times)
    {
        name = _name;
        basicSalary = _basicSalary;
    }
   
    public void paySalary()
    {
        totalSalary = basicSalary + 2400 / times;
    }
   
    void showManager()
    {
        System.out.println("经理" + name + "的薪水为:" + totalSalary);
    }
}
public class Employee
{
    public static void main(String[] args)
    {
        EmpDemo e1 = new Seller("刘欢", 100, 8, 10);
        e1.showSeller();
        EmpDemo e2 = new Manager("王菲", 100, 12);
        e2.showManager();
    }
}

搜索更多相关的解决方案: show  

----------------解决方案--------------------------------------------------------
abstract class EmpDemo
{
    String name;
    double basicSalary;
    double totalSalary;
    public EmpDemo(){}
    public EmpDemo(String _name, double _basicSalary)
    {
        name = _name;
        basicSalary = _basicSalary;
    }
   
    public abstract void paySalary();
    public abstract void showSalary();        //构造一个showSalary方法
}
class Seller extends EmpDemo
{
    double totalSalary;
    int daytime = 8;
    int hourget = 10;
   
    public Seller(String _name, double _basicSalary, int daytime, int hourget)
    {
        name = _name;
        basicSalary = _basicSalary;
    }
   
    public void paySalary()   
    {
        totalSalary = basicSalary + 30 * daytime * hourget;
    }
   
   public void showSalary()        //继承,重写父类方法
    {
        System.out.println("销售员" + name + "的薪水为:" + totalSalary);
    }
}
class Manager extends EmpDemo
{
    double totalSalary;
    int times = 12;
   
    public Manager(String _name, double _basicSalary, int times)
    {
        name = _name;
        basicSalary = _basicSalary;
    }
   
    public void paySalary()
    {
        totalSalary = basicSalary + 2400 / times;
    }
   
   public void showSalary()        //继承,重写父类方法
    {
        System.out.println("经理" + name + "的薪水为:" + totalSalary);
    }
}
public class Employee
{
    public static void main(String[] args)
    {
        EmpDemo e1 = new Seller("刘欢", 100, 8, 10);
        e1.paySalary();    //计算薪水
        e1.showSalary();    //输出
        EmpDemo e2 = new Manager("王菲", 100, 12);
        e2.paySalary();
        e2.showSalary();
    }
}

在main方法中调用方法必须先声明后调用,你源程序 new的对象是EmpDemo,假如你new Seller 跟 Manager对象就可以运行了!
希望能帮到你!

----------------解决方案--------------------------------------------------------
回复 2楼 wsckt
谢谢
----------------解决方案--------------------------------------------------------
我也刚学的,呵呵
记得结贴哦
----------------解决方案--------------------------------------------------------
  相关解决方案