为了账号安全,请及时绑定邮箱和手机立即绑定

Class中的构造方法无法应用于给定类型

Class中的构造方法无法应用于给定类型

胡说叔叔 2021-05-07 18:23:16
我根据deitel撰写的《 Java How to program》一书创建了一个程序。在第3章“有所作为”中,练习说:(“目标心率计算器”)创建一个称为HeartRates的类。类别属性应包括此人的名字,姓氏和出生日期(由出生月份,日期和年份的单独属性组成)。您的类应具有一个接收此数据作为参数的构造函数。为每个属性提供set和get方法。该类还应该包括一种计算并返回该人的年龄(以年为单位)的方法,一种计算并返回该人的最大心率的方法以及一种计算并返回该人的目标心率的方法。编写一个Java应用程序,提示输入该人的信息,实例化HeartRates类的对象,并打印该对象中的信息,包括该人的名字,所以我写了这段代码:// File: HeartRates.javapublic class HeartRates {    private String firstName;    private String lastName;    private int month;    private int day;    private int year;    // constructor    public HeartRates( String fName, String lName, int aMonth,        int aDay, int aYear) {        firstName = fName;        lastName = lName;        month = aMonth;        day = aDay;        year = aYear;    }    // method to set first name    public void setFirstName( String fName ) {        firstName = fName;    }    // method to get first name    public String getFirstName() {        return firstName;    }     // method to set last name    public void setLastName( String lName ) {        lastName = lName;    }    // method to get last name    public String getLastName() {        return lastName;    }    // method to set month    public void setMonth( int aMonth ) {        month = aMonth;    }    // method to get month    public int getMonth() {        return month;    }    // method to set day    public void setDay( int aDay ) {        day = aDay;    }    // method to get day    public int getDay() {        return day;    }    // method to set year    public void setYear( int aYear ) {        year = aYear;    }    // method to get year    public int getYear() {        return year;    }    // returns person's age    public int ageInYears() {        return 2018 - getYear();    }    // returns maximum heart rate    public int maxHeartRate() {        return 220 - ageInYears();    } 但是我不知道为什么要我放String,String,int,int,int。谁能帮我解决此错误?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 237 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信