我正在通过构造函数传递一个字符串并将其值分配给 Grade 类型对象类变量。我知道这很简单,但我无法弄清楚这项工作。我不能修改变量或构造函数参数,只能实现构造函数。
我查看了字符串中的方法,但一个小时后无法弄清楚该怎么做。铸造/转换/ idk
public class Course
{
private String courseNumber;
private int numberOfCredits;
private Grade gradeReceived;
private String termWhenTaken;
/**
* The value for the courseNumber instance variable is converted to uppercase.
* The numberOfCredits instance variable is set to the credits passed as a parameter if it's 0 or more.
* Otherwise, it gets set to 0.
*/
public Course(String course, int credits, String grade, String term)
{ courseNumber = course.toUpperCase();
numberOfCredits = credits;
termWhenTaken = term;
gradeReceived = grade; <-----problem here mismatched data types obviously
}