我一直收到错误 " Java错误不兼容类型:可能有损转换"
我相信我可能需要设置更多变量,但我不太确定?
路线:
1)创建一个名为SavingsAccount
的公共类2)将您的姓名和章节编号放在顶部的
块注释中3)包含一个构造函数,该构造函数将所有者的名称和初始帐户余额作为参数。
4)包括帐户持有人姓名和帐户余额的私有非静态变量。
5)包括低利率和高利率的私有静态变量。
6)为帐户持有人姓名和帐户余额编写公共getter和setter方法。
7)为利率写一个公共的getter方法,如上所述计算。
8)包括低利率和高利率的公共静态getter和setter方法。
9)保存文件并确保编译。
import java.util.*;
public class SavingsAccount
{
//private static and private nonstatic variables
private String ownerName;
private double acctBalance;
private static double lowInt;
private static double highInt;
//write a public getter and setter for account holder
public void setOwnersName(String name)
{
ownerName = name;
}
public String getOwnerName()
{
return ownerName;
}
//write a public getter and setter for the account balance
public void setAcctBalance(double balance)
{
acctBalance = balance;
}
public double getAcctBalance()
{
return acctBalance;
}
//write a public getter method for interest rate
public double getInterestRate()
{
if(acctBalance < 1000)
{
return lowInt;
}
if(acctBalance > 1000)
{
return highInt;
}
}
//include public static getter and setter method for the lowe interest
public static int setLowInt(double rate)
{
lowInt = rate;
}
public static int getLowInt()
{
return lowInt;
}
//include public static getter and setter for high interest
public static int setHighInt(double rate)
{
highInt = rate;
}
public static int getHighInt()
{
return highInt;
}
public SavingsAccount(String name, double balance)
{
ownerName = name;
acctBalance = balance;
}
}//end class
答案 0 :(得分:0)
您需要将返回转换为int
public static int getLowInt()
{
return (int) lowInt;
}