/**
@auther 2113042102njy
@date 2022.09.24
@description 定义一个学生类Student,该类中包含的属性有:姓名(String)、性别(char)、高数成绩(float)、线代成绩(float)、C语言成绩(float)、面向对象成绩(float);
*/importjava.util.Scanner;publicclassTestStudentSpeak{publicstaticvoidmain(String[] args){Student s =newStudent();
s.init();
s.speak();}}enumSex{
男,女
}classStudent{String name;Sex sex;String[] course ={"数据结构与算法","大学物理","高等数学","离散数学","C语言"};float[] score;// 初始化学生信息publicvoidinit(){Scanner sc =newScanner(System.in);System.out.println("请输入你的名字,性别和各门功课的成绩:");System.out.println("姓名:");
name = sc.next();System.out.println("性别:(0代表男,1代表女)");byte flag = sc.nextByte();if(flag ==0){
sex =Sex.男;}else{
sex =Sex.女;}
score =newfloat[course.length];for(int i =0; i < course.length; i++){System.out.println(course[i]);
score[i]= sc.nextFloat();}}// 学生说话publicvoidspeak(){System.out.println("我叫"+ name +","+ sex +",我上学期通过努力取得了好成绩,各门功课的成绩如下:");for(int i =0; i < course.length; i++){System.out.print(course[i]);System.out.print(score[i]);System.out.print(".");}}}