import java.util.Scanner;
class Person {
protected String name;
protected int age;
protected boolean gender; // true: male
public String gender (boolean gender) {
if(gender) {
return "Male";
}else {
return "Female";
}
}
public Person(String name, int age, boolean gender) {
super();
this.name = name;
this.age = age;
this.gender = gender;
}
@Override
public String toString() {
return "" +name + ";" + age + ";" + gender;
}
}
class Student extends Person {
protected String stuID;
protected int chinese;
protected int math;
protected int english;
public Student(String name, int age, boolean gender, String stuID, int chinese, int math, int english) {
super(name, age, gender);
this.stuID = stuID;
this.chinese = chinese;
this.math = math;
this.english = english;
}
public double getAve() {
double ave = (chinese+math+english)/3;
return ave;
}
@Override
public String toString() {
return "" + stuID + ";" + name + ";" + gender + ";" + age + ";"
+ getAve();
}
}
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Student s[] = new Student[3];
// s[0] = new Student("Alice", 20, false, "100", 90, 80, 70);
// s[1] = new Student("Bob", 21, true, "101", 60, 70, 80);
// s[2] = new Student("Carter", 22, true, "102", 90, 92, 100);
for (int i = 0; i < s.length; ++i) {
String name = sc.next();
int age = sc.nextInt();
boolean gender = sc.nextBoolean();
String stuID = sc.next();
int chinese = sc.nextInt();
int math = sc.nextInt();
int english = sc.nextInt();
s[i] = new Student(name,age,gender,stuID,chinese,math,english);
}
sc.close();
for (int i = 0; i < s.length; ++i) {
System.out.println(s[i]);
}
}
}
Java中如何把true改成Male,false改成Female?