import java.util.Scanner;
interface rateOfInterest {
void ROI();
void display();
}
class SBI implements rateOfInterest {
public void ROI() {
int p, t;
Scanner in = new Scanner(System.in);
System.out.println("Enter the Principal amount");
p = in.nextInt();
System.out.println("Enter the Time in years");
t = in.nextInt();
p = p * t;
System.out.println("Enter the Simple Interest");
float s = in.nextInt() * 100;
s = s / p;
float r = s;
display(r);
}
public void display(float r) {
System.out.println("The ROI of SBI is " + r);
}
}
public class Main {
public static void main(String[] args) {
rateOfInterest r = new SBI();
r.ROI();
r.display();
}
}
这是我的代码,输出是
输入本金金额
10000
输入时间(以年为单位)
5
输入单利
1254
SBI 的投资回报率为 2.508
线程“main”java.lang.Error中出现异常:未解决的编译问题:
The type SBI must implement the inherited abstract method rateOfInterest.display()
at SBI.display(Bank.java:10)
at Bank.main(Bank.java:40)
这是界面。这两种方法都不需要参数。
interface rateOfInterest {
void ROI();
void display();
}
这是你的班级。
class SBI implements rateOfInterest {
...
public void display(float r) { // argument is here but not required.
System.out.println("The ROI of SBI is " + r);
}
}
你有两个选择。
@Override
public void display() {}
注意:当重写继承的方法时,请像上面那样使用 @Override 注释来确保匹配签名。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)