private String name
private double line
public School(){}
public School(String name,double line) {
super()
this.name=name
this.line = line
}
public double getLine() {
return line
}
public void setLine(double line) {
this.line = line
}
public String getName() {
return name
}
public void setName(String name) {
this.name = name
}
}
public class Student {
private String id
private String name
private double total
private double sports
public Student(){
}
public Student(String id, String name, double total, double sports) {
super()
this.id = id
this.name = name
this.total = total
this.sports = sports
}
public String getId() {
return id
}
public void setId(String id) {
this.id = id
}
public String getName() {
return name
}
public void setName(String name) {
this.name = name
}
public double getTotal() {
return total
}
public void setTotal(double total) {
this.total = total
}
public double getSports() {
return sports
}
public void setSports(double sports) {
this.sports = sports
}
}
public class Pass {
public void status(School s,Student stu){
if(stu.getTotal()>含晌袭=s.getLine()||(stu.getSports()>=96||stu.getTotal()>=300)){
System.out.println("学号为:"+stu.getId()+" "+"姓名为:"+stu.getName()+"的同学被"+s.getName()+"录取,该学校的录取分数线为:谈兄"+s.getLine())
}else{
System.out.println("学号为:"+stu.getId()+" "+"姓名为:"+stu.getName()+"的同学没有被"+s.getName()+"录取,该学校的录取分数线为:"+s.getLine())
}
}
public static void main(String[] args){
School school1=new School("清华大学",680)
School school2=new School("北京大学",660)
Student stu1=new Student("2012121201","小红",690,80)
Student stu2=new Student("2012121201","谨滚小明",650,80)
Student stu3=new Student("2012121201","张三",670,80)
Student stu4=new Student("2012121201","李四",640,80)
Pass p=new Pass()
p.status(school1, stu1)
p.status(school1, stu2)
p.status(school2, stu3)
p.status(school2, stu4)
}
}
运行结果为:
学号为:2012121201 姓名为:小红的同学被清华大学录取,该学校的录取分数线为:680.0
学号为:2012121201 姓名为:小明的同学被清华大学录取,该学校的录取分数线为:680.0
学号为:2012121201 姓名为:张三的同学被北京大学录取,该学校的录取分数线为:660.0
学号为:2012121201 姓名为:李四的同学被北京大学录取,该学校的录取分数线为:660.0
这里有一个类实现学生学号,数学,语文,英语成绩录入
并且计算平均成绩,按照平均成绩高低输出信息
你可以改改!
//实现简单的学生信息输入输出和初步的成绩孙缺排雀郑序
public
class
student
{
private
int
id
//学号
private
int
mathscore
//数学成绩
private
int
chinscore
//语文成绩
private
int
forescore
//外语成绩
public
student()
{
id
=
0
mathscore
=
0
chinscore
=
0
forescore
=
0
}
public
student(int
newid,
int
newmathscore,
int
newchinsvore,
int
newforescore)
{
id
=
newid
mathscore
=
newmathscore
chinscore
=
newchinsvore
forescore
=
newforescore
}
public
double
getaveragescore()
{
//求平均成绩
double
averagescore
=
((double)
mathscore
+
chinscore
+
forescore)
/
3
return
averagescore
}
public
void
output(student
student)
{
//输出对象的内容
system.out.println("
"
+
student.id
+
"
"
+
student.mathscore
+
"
"
+
student.chinscore
+
"
"
+
student.forescore
+
"
"
+
student.getaveragescore())
}
public
int
max(student
a[],
int
n)
{
//student类对象数组的前n项中的成绩最顷凯颂大值的索引
int
position
=
0
for
(int
i
=
1
i
<
n
i++)
{
if
(a[i].getaveragescore()
>
a[position].getaveragescore())
{
//比较平均成绩
position
=
i
}
}
return
position
}
public
void
selectsort(student
a[])
{
//student类对象数组的选择排序
for
(int
n
=
a.length
n
>
1
n--)
{
int
i
=
max(a,
n)
student
temp
=
a[i]
a[i]
=
a[n
-
1]
a[n
-
1]
=
temp
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)