在java中编写程序,定义一个学生类

在java中编写程序,定义一个学生类,属性包括姓名,学号,语文成绩,数学成绩,英语成绩,方法包括输出数据,设置姓名和学号,设置三门课程的成绩,求总成绩和平均成绩!

代码如下:

package exam2;

import java.util.ArrayList;

import java.util.List;

/**

编写一个Java应用程序,该程序包括3个类:

定义一个学生类,Student有姓名,学号,选学的课程列表

定义一个课程类:课程名称,课程分数 

(1)初始化一个学生,选择了三门课程,并添加到学生的属性中

(2)实现统计学生的总分功能

1.正确编写2个类(5分)

2.统计学生的总分功能(5分)

*/

public class Test {

public static void main(String[] args) {

List<Course> courses = new ArrayList<>();

// 初始化3门课程及分数

Course course1 = new Course("java", 80);

Course course2 = new Course("Math", 60);

Course course3 = new Course("English", 90);

// 课程对象添加到集合

courses.add(course1);

courses.add(course2);

courses.add(course3);

// 初始化学生对象

Student student = new Student("tom", "2015101", courses);

// student.setStuid("2015101");

// student.setStuname("tom");

// student.setCourses(courses);

// System.out.println(student);

// (2)实现统计 学生 的总分功能

int sum = sumScore(courses);

System.out.println(student.getStuname() + "学生总分:" + sum);

}

private static int sumScore(List<Course> courses) {

int sum = 0;

// 用课程对象,来获取课程的分数

for (Course course : courses) {

sum += course.getScore();

}

return sum;

}

}

package exam2;

import java.util.List;

public class Student {

// 定义一个学生类,Student有姓名,学号,选学的课程列表

private String stuname;

private String stuid;

private List<Course> courses;

public Student() {

}

public Student(String stuname, String stuid, List<Course> courses) {

this.stuname = stuname;

this.stuid = stuid;

this.courses = courses;

}

public String getStuname() {

return stuname;

}

public void setStuname(String stuname) {

this.stuname = stuname;

}

public String getStuid() {

return stuid;

}

public void setStuid(String stuid) {

this.stuid = stuid;

}

public List<Course> getCourses() {

return courses;

}

public void setCourses(List<Course> courses) {

this.courses = courses;

}

@Override

public String toString() {

return "学生姓名=" + stuname + ",学号=" + stuid + ", 课程=" + courses;

}

}

package exam2;

public class Course {

//定义一个课程类:课程名称,课程分数

private String cname;

private int score;

public Course() {

}

public Course(String cname, int score) {

this.cname = cname;

this.score = score;

}

public String getCname() {

return cname;

}

public void setCname(String cname) {

this.cname = cname;

}

public int getScore() {

return score;

}

public void setScore(int score) {

this.score = score;

}

@Override

public String toString() {

return "[课程名称=" + cname + ", 课程分数=" + score + "]";

}

}

/*

运行:

tom学生总分:230

*/

扩展资料:

Public 语句说明

1.Public 语句声明的变量在所有应用程序的所有没有使用OptionPrivate Module 的模块的任何过程中都是可用的;若该模块使用了 OptionPrivate Module,则该变量只是在其所属工程中是公用的。

2.使用Public 语句可以声明变量的数据类型。例如,下面的语句声明了一个 Integer 类型的变量。

3.Public NumberOfEmployees As Integer 也可以使用Public 语句来声明变量的对象类型。下面的语句为工作表的新实例声明了一个变量。

参考资料:百度百科-Public 语句



温馨提示:内容为网友见解,仅供参考
第1个回答  2019-07-26
学生类:
public
class
Student{
private
String
name;
private
int
age;
private
double
score;
public
dd(String
name,
int
age,
double
score)
{
super();
this.name
=
name;
this.age
=
age;
this.score
=
score;
}
public
String
getName()
{
return
name;
}
public
void
setName(String
name)
{
this.name
=
name;
}
public
int
getAge()
{
return
age;
}
public
void
setAge(int
age)
{
this.age
=
age;
}
public
double
getScore()
{
return
score;
}
public
void
setScore(double
score)
{
this.score
=
score;
}
public
void
printInfo()
{
System.out.println("name:"
name);
System.out.println("age:"
age);
System.out.println("score:"
score);
}
}
main()
方法:
public
class
TestStudent{
public
static
void
main(String[]
args)
{
Student
stu=new
Student("李四",20,89);
stu.printInfo();
}
}
友情提示:考试的题目还是应该自己做,尽管就是做错了,那对自己还是很有帮助的
第2个回答  2010-04-20
public class Student {
private String name;

private String stuNo;

private double score1;

private double score2;

private double score3;

public Student() {
}

public Student(String name, String stuNo, double score1, double score2,
double score3) {
this.name = name;
this.stuNo = stuNo;
this.score1 = score1;
this.score2 = score2;
this.score3 = score3;
}

public void GetAllScore() {
System.out.println("总成绩为:" + this.score1 + this.score2 + this.score3);
}

public void GetAvgScore() {
System.out.println("平均成绩为:" + (this.score1 + this.score2 + this.score3)
/ 3);
}
}再到main方法里调用Student类里的带参构造函数为类中的属性赋值,然后调用求总成绩和平均成绩的两个方法就可以了
第3个回答  2010-04-20
package js.topcom;

public class Student {
//属性包括姓名,学号,语文成绩,数学成绩,英语成绩
private String name;
private String id;
private int chn_score;
private int math_score;
private int en_score;
//方法包括输出数据,设置姓名和学号,设置三门课程的成绩,求总成绩和平均成绩

public void diplay(){
System.out.println("the student name is: " + this.name);
System.out.println("the student id is: " + this.id);
System.out.println("the student chinese score is: " + this.chn_score);
System.out.println("the student math score is: " + this.math_score);
System.out.println("the student english score is: " + this.en_score);
System.out.println("the student total score is: " + this.get_total_score());
System.out.println("the student average score is: " + this.get_avg_score());
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public int getChn_score() {
return chn_score;
}

public void setChn_score(int chnScore) {
chn_score = chnScore;
}

public int getMath_score() {
return math_score;
}

public void setMath_score(int mathScore) {
math_score = mathScore;
}

public int getEn_score() {
return en_score;
}

public void setEn_score(int enScore) {
en_score = enScore;
}

public int get_total_score(){
return this.chn_score + this.en_score + this.math_score;
}

public int get_avg_score(){
return this.get_total_score() / 3;
}

public static void main(String[] args) {
Student stu = new Student();
stu.setName("baidu");
stu.setId("123");
stu.setChn_score(89);
stu.setEn_score(98);
stu.setMath_score(88);
stu.diplay();
}
}本回答被提问者采纳
第4个回答  2010-04-20
/**
* 在java中编写程序,定义一个学生类,属性包括姓名,学号,语文成绩,数学成绩,英语成绩,方法包括输出数据,
* 设置姓名和学号,设置三门课程的成绩,求总成绩和平均成绩!
* @author Administrator
*/
public class Student {
private String name;//姓名
private String sNo;//学好
private double chineseScore;//语文成绩
private double englishScore;//英语成绩
private double mathScore;//数学成绩
//设置姓名
public void setName(String name) {
this.name = name;
}
//设置学号
public void setsNo(String sNo) {
this.sNo = sNo;
}
//设置语文成绩
public void setChineseScore(double chineseScore) {
this.chineseScore = chineseScore;
}
//设置英语成绩
public void setEnglishScore(double englishScore) {
this.englishScore = englishScore;
}
//设置数学成绩
public void setMathScore(double mathScore) {
this.mathScore = mathScore;
}
//获取姓名
public String getName() {
return name;
}
//获取学号
public String getsNo() {
return sNo;
}
//获取语文成绩
public double getChineseScore() {
return chineseScore;
}
//获取英语成绩
public double getEnglishScore() {
return englishScore;
}
//获取数学成绩
public double getMathScore() {
return mathScore;
}
//输出数据
public void exportInfo(){
System.out.println("学生:"+name+",学号为:"+sNo+",语文成绩为:"+chineseScore+",数学成绩为:"+mathScore+",英语成绩为:"+englishScore);
}
//获取总成绩
public double getTotalScore(){
return chineseScore+englishScore+mathScore;
}
//获取平均分
public double getAverageScore(){
return (chineseScore+englishScore+mathScore)/3;
}
}

用java表示学生信息 问题:用java怎么写学生表示?
getNo():获得学号;getName():获得姓名;getSex():获得性别;getAge()获得年龄;getJava():获得Java 课程成绩 (4)根据类Student的定义,创建五个该类的对象,输出每个学生的信息,计算并输出这五个学生Java语言成绩的平均值,以及计算并输出他们Java语言成绩的最大值和最小值。*\/ class...

在java中编写程序,定义一个学生类
定义一个学生类,Student有姓名,学号,选学的课程列表 定义一个课程类:课程名称,课程分数 (1)初始化一个学生,选择了三门课程,并添加到学生的属性中 (2)实现统计学生的总分功能 1.正确编写2个类(5分)2.统计学生的总分功能(5分)\/ public class Test { public static void main(String[] ...

JAVA 定义一个学生类(Student),包含学号、姓名、年龄(7-60岁)三个私 ...
import java.util.Scanner;class Student{ private String num;private int age;private String name;public Student(String b,String a,int c) { num=b;name=a;age=c;} public int reage() { return age;} void shou() { if(age>=7&&age<=60)System.out.println(name+" "+num+" "+a...

用JAVA定义一个学生类Student来表示学生信息,学生类中包含成员有学号...
public class Student {private int sNo; \/\/学号private String name; \/\/姓名private String sex; \/\/性别private int yu; \/\/语文private int shu; \/\/数学private int wai; \/\/外语public int getsNo() {return sNo;}public void setsNo(int sNo) {this.sNo = sNo;}public String ge...

如何使用java来创建一个学生类?
首先,你需要创建一个学生类来表示学生的信息,例如:public class Student { private String name;private int age;private String gender;private String grade;public Student(String name, int age, String gender, String grade) { this.name = name;this.age = age;this.gender = gender;this....

用java定义一个Student类,包含的内容如下:
public class Student { private String s_no;\/\/学号 private String s_name;\/\/姓名 private boolean isLeader;\/\/班干部否 private String s_sex;\/\/性别 private double s_shuxue;\/\/数学 private double s_yuwen;\/\/语文 private double s_waiyu;\/\/外语 \/\/学生信息录入 public void addStudent...

JAVA编程 定义一个学生类,数据成员包括:学号,姓名,年龄,成绩;成员函数...
public static void main(String[] args) { Scanner sc = new Scanner(System.in);System.out.println("请输入学生个数:");int n = sc.nextInt();Student [] ss = new Student[n];for(int i=0;i<n;i++){ Scanner sca = new Scanner(System.in);Student s = new Student();Syste...

Java程序设计,定义一个表示学生的类Student
public class Student { \/\/定义一个学生类 private int StuNum; \/\/学号 private int Class; \/\/班级 private char Gender; \/\/性别 private int Age; \/\/年龄 public Student(int StuNum, int Class, char Gender, int Age){\/\/构造函数 this.stuNum = StuNum;this.class = Cla...

编写Java程序,定义一个学生类,并编写主类测试该类的功能。基本要求如下...
import java.util.*;public class MainClass_StudentInfor{ public static void main(String args[]){ boolean e=true;Student stu=new Student();Scanner sc=new Scanner(System.in);while(e){ System.out.println("\\t\\t\\t\\t\\t***欢迎进入学生信息系统***\\t\\t\\t\\t\\t");System.out.prin...

Java定义一个Student类,包括学号、姓名、性别、班级、出生日期
public class Student { private String sno; \/\/学号 private String name; \/\/姓名 private String sex; \/\/性别 private String calss; \/\/班级 private String major; \/\/专业 public String getSno() { return sno;} public void setSno(String sno) { this.sno = sno;} public String get...

相似回答