创建学生类 Student 属性 String name,int number ,double score_百度...
发布网友
发布时间:2024-10-13 11:25
我来回答
共2个回答
热心网友
时间:2024-11-01 20:53
public class Student {
private String name;
private int number;
private float score;
public Student(String name, int number, float score){
this.name=name;
this.number=number;
this.score=score;
}
public String getName(){
return this.name;
}
public int getNumber(){
return this.number;
}
public float getScore(){
return this.score;
}
public void setName(String name){
this.name=name;
}
public void setNumber(int numbder){
this.number=number;
}
public void setScore(float score){
this.score=score;
}
public void ifPrint(Student stu){
float temp=stu.getScore();
if (temp<60){
System.out.println("您的成绩不及格!!!");
}
if (temp>60 && temp<=70){
System.out.println("您的成绩为中!!!");
}
if (temp>70 && temp<=80){
System.out.println("您的成绩良!!!");
}
if (temp>80 && temp<=90){
System.out.println("您的成绩良好!!!");
}
if (temp>90 && temp<=100){
System.out.println("您的成绩优异!!!");
}
}
public static void main(String args[]){
Student stu=new Student("张三",1,90.0f);
stu.ifPrint(stu);
}
}
成绩lz自己改成double吧,刚没注意
热心网友
时间:2024-11-01 20:52
Scanner s = new Scanner(System.in);
String stuScore = s.next();
String [] scores = stuScore.split(",");// 假如输入的时候格式为:85,86,98,59,60等
剩下就遍历这个数组了,判断区间。然后计数器++就可以了。