我有一个 get/set 程序,我试图获得平均结果,但我总是得到 0.0。
- 该程序有 5 个实例,每个实例有 1 个返回方法
- 主要有 2 个用户输入和 3 个年级数字
账户类:
public class Account {
private String name1;
private String name2;
private double grade1;
private double grade2;
private double grade3;
private double average;
public Account(String a1, String a2, double b1, double b2, double b3) {
name1 = a1;
name2 = a2;
grade1 = b1;
grade2 = b2;
grade3 = b3;
}
public void setName1(String a1) {
name1 = a1;
}
public void setName2(String a2) {
name2 = a2;
}
public void setGread1(double b1) {
grade1 = b1;
}
public void setGread2(double b2) {
grade2 = b2;
}
public void setGread3(double b3) {
grade3 = b3;
}
public String getName1() {
return name1;
}
public String getName2() {
return name2;
}
public double getgrade1() {
return grade1;
}
public double getgrade2() {
return grade2;
}
public double getgrade3() {
return grade3;
}
public void setAverage(double ave) {
average = ave;
}
public double getAverage() {
return average = (grade1 + grade2 + grade3) / 3;
}
public String toString() {
return String.format("%-5s %2s the average is: %5s%% ", name1, name2,
average);
}
}
主要方法:
public static void main(String[] args) {
Scanner in = new Scanner (System.in);
System.out.println("Enter the frist and last name of student" );
String inf=in.nextLine();
String infs=in.nextLine();
Account account= new Account(inf,infs,5,6,7);
System.out.print(account);
}
我厌倦了试图解决它,所以请帮助我。