[java]代码库
package c;
import java.util.*;
public class my {
public static void main(String[] args) {
Student c1=new Student();
Student c2=new Student();
c1.setnumber(2019110105);
c1.setname("chen");
c1.setEgrade(87);
c1.setMgrade(78);
c1.setCgrade(84);
c1.Sum();
c1.equal();
System.out.println("总成绩为:"+c1.getSumgrade());
System.out.println("平均成绩为:"+c1.getequalgrade());
System.out.println(c1.toString());
c2.Student(2019110104, "fang", 70, 78, 94);
c2.Sum();
c2.equal();
System.out.println(c2.toString());
c1.Compare(c2);
}
}
class Student {
public int number;
public double Egrade,Mgrade,Cgrade,Sumgrade,equalgrade,testscore;
public String name;
public Student() {
}
public void Student(int number,String name,double Egrade,double Mgrade,double Cgrade) {//构造方法
this.number=number;
this.name=name;
this.Egrade=Egrade;
this.Cgrade=Cgrade;
this.Mgrade=Mgrade;
}
public int getnumber() {//get方法
return number;
}
public String getname() {
return name;
}
public double getEgrade() {
return Egrade;
}
public double getMgrade() {
return Mgrade;
}
public double getCgrade() {
return Cgrade;
}
public double getSumgrade() {
return Sumgrade;
}
public double getequalgrade() {
return equalgrade;
}
public void setnumber(int number) {//set方法
this.number=number;
}
public void setname(String name) {
this.name=name;
}
public void setEgrade(double Egrade) {
this.Egrade=Egrade;
}
public void setMgrade(double Mgrade) {
this.Mgrade=Mgrade;
}
public void setCgrade(double Cgrade) {
this.Cgrade=Cgrade;
}
public void setSumgrade(double Sumgrade) {
this.Sumgrade=Sumgrade;
}
public void setequalgrade(double equalgrade) {
this.equalgrade=equalgrade;
}
public void Sum() {//sum方法
Sumgrade=Egrade+Mgrade+Cgrade;
}
public void equal() {//equal方法
equalgrade=Sumgrade/3;
}
public void Compare(Student p) {//compare方法
if(this.Sumgrade>p.Sumgrade) {
System.out.println(this.name+"同学成绩高");
}
else if(this.Sumgrade==p.Sumgrade) {
System.out.println("两位同学成绩相同");
}
else
System.out.println(p.name+"同学成绩高");
}
public void testScore() {
testscore=Sumgrade/3;
}
public String toString() {//toString方法
return "Student [number=" + number + ", Egrade=" + Egrade + ", Mgrade=" + Mgrade + ", Cgrade=" + Cgrade
+ ", Sumgrade=" + Sumgrade + ", equalgrade=" + equalgrade + ", name=" + name + "]";
}
}
=============================================================================
package c;
public class my1 {
public static void main(String[] args) {
Student c1=new Student();
Student c2=new Student();
c1.setnumber(2019110105);
c1.setname("chen");
c1.setEgrade(87);
c1.setMgrade(78);
c1.setCgrade(84);
c1.Sum();
c1.equal();
System.out.println("总成绩为:"+c1.getSumgrade());
System.out.println("平均成绩为:"+c1.getequalgrade());
System.out.println(c1.toString());
c2.Student(2019110104, "fang", 70, 78, 94);
c2.Sum();
c2.equal();
System.out.println(c2.toString());
c1.Compare(c2);
StudentXW c3=new StudentXW();
c3.Student(2019110106, "xi", 60, 78, 88);
c3.getzeren("xuewei");
c3.Sum();
c3.testScore();
System.out.println(c3.toString());
StudentBZ c4=new StudentBZ();
c4.Student(2019110109, "jin", 62, 78, 94);
c4.getzeren("banzhang");
c4.Sum();
c4.equal();
c4.testScore();
System.out.println(c4.toString());
}
}
class StudentXW extends Student{
public String zeren;
public void getzeren(String zeren) {
this.zeren=zeren;
}
public String setzeren() {
return zeren;
}
public void testScore() {
testscore=Sumgrade/3+5;
}
public String toString() {
return "StudentXW [name=" + name + ", number=" + number + ", Egrade=" + Egrade + ", Mgrade=" + Mgrade
+ ", Cgrade=" + Cgrade + ", Sumgrade=" + Sumgrade + ", equalgrade=" + equalgrade + ", testscore="
+ testscore + ", zeren=" + zeren + "]";
}
}
class StudentBZ extends Student{
public String zeren;
public void getzeren(String zeren) {
this.zeren=zeren;
}
public String setzeren() {
return zeren;
}
public void testScore() {
testscore=Sumgrade/3+5;
}
public String toString() {
return "StudentXW [name=" + name + ", number=" + number + ", Egrade=" + Egrade + ", Mgrade=" + Mgrade
+ ", Cgrade=" + Cgrade + ", Sumgrade=" + Sumgrade + ", equalgrade=" + equalgrade + ", testscore="
+ testscore + ", zeren=" + zeren + "]";
}
}