java基础入门代码出现错误

某公司的员工分为5类,每类员工都有相应的封装类,这5个类的信息如下
(1)Employee:这是所有员工的父类。
①属性:员工的姓名、员工的生日月份。
)方法:getSalary(int month)根据参数月份确定工资。如果该月员工过生日,则公司会额外发放100元。
(2)SalariedEmployee:Employee 的子类,拿固定工资的员工。
属性:月薪。
(3)HourlyEmployee:Employee的子类,按小时拿工资的员工,每月工作超出160h的
部分按照1.5倍工资发放。
属性:每小时的工资、每月工作的小时数。
(4)SalesEmployee:Employee的子类,销售人员,工资由月销售额和提成率决定。
属性:月销售额、提成率。
(5)BasePlusSalesEmployee:SalesEmployee的子类,有固定底薪的销售人员,工资为
底薪加上销售提成。
属性:底薪。
本题要求根据上述员工分类,编写一个程序,实现以下功能:
(1)创建一个Employee数组,分别创建若干不同的Employee对象,并打印某个月的
(2)每个类都完全封装,不允许有非私有化属性

package jquery;
class Employee
{
    private String name;        //员工姓名
    private int month;        //员工生日月份
    public Employee(){}
    public Employee(String name,int month){
        this.name = name;
        this.month = month;
    }

    public void setName(String name){
        this.name = name;
    }
    public String getName(){
        return name;
    }

    public void setMonth(int month){
        this.month = month;
    }
    public int getMonth(){
        return month;
    }

    public double getSalary(int month){
        double salary = 0;
        if(this.month == month){
            salary +=100;
        }
        return salary;
    }
}


class SalariedEmployee extends Employee
{
    private double monthsalary;//月薪
    public SalariedEmployee(){}
    public SalariedEmployee(String name,int month,double monthsalary){
        super(name,month);
        this.monthsalary = monthsalary;
    }

    public void setMonthsalary(double monthsalary){
        this.monthsalary = monthsalary;
    }
    public double getMonthsalary(){
        return monthsalary;
    }

    public double getSalary(int month){
        double salary = monthsalary+super.getSalary(month);
        return salary;
    }

 class HourlyEmployee extends Employee
    {
        private double hourlysalary;        //每小时的工资
        private int counthour;        //每月工作的小时数
        public HourlyEmployee(){}
        public HourlyEmployee(String name, int month, double hourlysalary, int counthour){
            super(name, month);
            this.hourlysalary = hourlysalary;
            this.counthour = counthour;
        }

        public void setHourlysalary(double hourlysalary) {
            this.hourlysalary = hourlysalary;
        }

        public double getHourlysalary() {
            return hourlysalary;
        }

        public void setCounthour(int counthour) {
            this.counthour = counthour;
        }

        public int getCounthour() {
            return counthour;
        }

        @Override
        public double getSalary(int month) {
            double salary = 0;
            if (counthour > 160) {
                salary = 160*hourlysalary+(counthour-160)*hourlysalary*3/2;

            }else{
                salary = hourlysalary*counthour+super.getSalary(month);
            }
            return salary+super.getSalary(month);
        }
    }
    }

class SalesEmployee extends Employee
    {
        private double monthlysales;        //月销售额
        private double commissiorate;        //提成率
        public SalesEmployee(){}
        public SalesEmployee(String name,int month,double monthlysales,double commissiorate){
            super(name,month);
            this.monthlysales = monthlysales;
            this.commissiorate = commissiorate;
        }
        public void setMonthlysales(double monthlysales) {
            this.monthlysales = monthlysales;
        }
        public double getMonthlysales() {
            return monthlysales;
        }

        public void setCommissiorate(double commissiorate) {
            this.commissiorate = commissiorate;
        }

        public double getCommissiorate() {
            return commissiorate;
        }

       public double getSalary(int month){
            double salary = 0;
            return salary = super.getSalary(month)+monthlysales*(1+commissiorate);
       }
    }
class BasePlusSalesEmployee extends SalesEmployee
    {
        private double basesalary;        //底薪
        public BasePlusSalesEmployee(){}
        public BasePlusSalesEmployee(String name,int month,double monthlysales,double commissiorate,double basesalary){
            super(name,month,monthlysales,commissiorate);
            this.basesalary = basesalary;
        }

        public void setBasesalary(double basesalary) {
            this.basesalary = basesalary;
        }

        public double getBasesalary() {
            return basesalary;
        }


        public double getSalary(int month) {
            double salary = 0;
            return salary = basesalary+super.getSalary(month);
        }
    }

    public class Test1
    {
        public static void main(String[] args){
        Employee []employee = {    new SalariedEmployee("张三",4,4000),
                            new HourlyEmployee("黄四",12,60,39),
                            new SalesEmployee("李武",9,355,0.2),
                            new BasePlusSalesEmployee("秦见",10,242,0.2,1000)
            };
            System.out.println("十月份工资:");
            for (int i = 0; i < employee.length; i++) {
                System.out.println("姓名:" + employee[i].getName() + "   生日月份:" + employee[i].getMonth() + "     工资为:" + employee[i].getSalary(10));

            }
            }
        }

java: 找不到符号
 符号:   类 HourlyEmployee  
 位置:   类 jquery.Test1

一直报这个错,求各位兄弟姐妹帮解答

该回答通过自己思路及引用到GPTᴼᴾᴱᴺᴬᴵ搜索,得到内容具体如下:
在代码中,HourlyEmployee类的定义中缺少一个右大括号(}),导致该类定义没有关闭,从而影响了后续代码的编译。

请将代码中HourlyEmployee类的定义修改为如下形式即可:

class HourlyEmployee extends Employee {
    private double hourlysalary;   //每小时的工资
    private int counthour;         //每月工作的小时数

    public HourlyEmployee() {}

    public HourlyEmployee(String name, int month, double hourlysalary, int counthour) {
        super(name, month);
        this.hourlysalary = hourlysalary;
        this.counthour = counthour;
    }

    public void setHourlysalary(double hourlysalary) {
        this.hourlysalary = hourlysalary;
    }

    public double getHourlysalary() {
        return hourlysalary;
    }

    public void setCounthour(int counthour) {
        this.counthour = counthour;
    }

    public int getCounthour() {
        return counthour;
    }

    @Override
    public double getSalary(int month) {
        double salary = 0;
        if (counthour > 160) {
            salary = 160 * hourlysalary + (counthour - 160) * hourlysalary * 3 / 2;

        } else {
            salary = hourlysalary * counthour + super.getSalary(month);
        }
        return salary + super.getSalary(month);
    }
}

此外,建议在类定义结束后,使用空行进行分隔,以提高代码的可读性。


如果以上回答对您有所帮助,点击一下采纳该答案~谢谢

换成静态的,因为你这个类载SalariedEmployee里面呢

img


 static class HourlyEmployee extends Employee

HourlyEmployee 你放到了 SalariedEmployee里面,就是这个SalariedEmployee类的内部类,主函数 就不饿能直接调用了,
解决:

  1. 你把 HourlyEmployee 放到 和 SalariedEmployee 同级

  2. 或者 HourlyEmployee 定义成 static 修饰,然后这样调用

new SalariedEmployee.HourlyEmployee("黄四",12,60,39)

  • 这有个类似的问题, 你可以参考下: https://ask.csdn.net/questions/361963
  • 除此之外, 这篇博客: 我的前端成长之路-写给在迷茫路上的人中的 我是一名毕业于江西城市学院软件技术专业的一名编程人员,从2013年毕业到现在已经有将近7年的工作经验,有一个新手慢慢成长为一个经验丰富的编程者,也从初级工程师慢慢变成以前前端负责人,我这几年的职业生涯里,在外包公司待过,也在创业公司里奋斗过,也在电子厂迷茫过,回想这7年的工作生涯,我一路成长,渐渐的学到了很多,也用自己的技术帮助很多人,现在在这家公司组建了自己的团队,为公司,为各个产品线提供各种各样的前端支持和开发,我和我的团队一起克服种种困难,由稚嫩变成熟,逐渐形成我们自己的前端文化,我相信未来更好!我把我的经历分为四个时期,迷茫期、学习期、沉淀期、发展期。 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读: