JAVA编写一个学生类

2024年11月27日 20:36
有3个网友回答
网友(1):

import java.util.Scanner;
public class Student1{
private String name;
private int computer_score;
private int english_score;
private int maths_score;
public void setName(String name){
this.name=name;
System.out.println(this.name);
}
public void setComputer_score(){

System.out.print("计算机:");
Scanner scan=new Scanner(System.in);
computer_score=scan.nextInt();
}
public void setEnglish_score(){
System.out.print("英语:");
Scanner scan=new Scanner(System.in);
english_score=scan.nextInt();
}
public void setsetMaths_score(){
System.out.print("数学:");
Scanner scan=new Scanner(System.in);
maths_score=scan.nextInt();
System.out.println();
}
public int getTotalScore(){
int total=computer_score+english_score+maths_score;
return total;
}
public void introduce(){
getTotalScore();
}
public static void main(String[] args){
Student1 xiaozhang=new Student1();

xiaozhang.setName("小张");
xiaozhang.introduce();
xiaozhang.setComputer_score();
xiaozhang.setEnglish_score();
xiaozhang.setsetMaths_score();
System.out.println("总分为:"+xiaozhang.getTotalScore());
}
}

网友(2):

我觉得一般都没有人会给你写的
首先你怎么也该表示一下分
还有谢谢都没有
还说测试成功后提交
其实最多和你说说思路
自己多看看书吧 很简单

网友(3):

你加些分我就帮你写了