m0_67828940 2022-05-09 14:46 采纳率: 25%
浏览 61
已结题

Java中如何把true改成Male?

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?

  • 写回答

3条回答 默认 最新

  • 溪风沐雪 2022-05-09 14:57
    关注

    没看懂题意,题主需要更详细的描述一下需求

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 5月17日
  • 已采纳回答 5月9日
  • 修改了问题 5月9日
  • 修改了问题 5月9日
  • 展开全部

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?