用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

主方法中声明类的数组

2021-11-12 作者: GuanTou举报

[java]代码库

package student;

public class Student {
     	public int number;
        public double Egrade,Mgrade,Cgrade,Sumgrade,equalgrade,testscore;
        public String name;
        public Student(){
        }
		public Student(final int number_,final String name_,final double Egrade_,final double Mgrade_,final 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;
            this.Sumgrade=Sum();
        }
        public void setMgrade(double _Mgrade) {
            this.Mgrade=_Mgrade;
            this.Sumgrade=Sum();
        }
        public void setCgrade(double _Cgrade) {
            this.Cgrade=_Cgrade;
            this.Sumgrade=Sum();
        }
        public void setSumgrade(double _Sumgrade) {
            this.Sumgrade=_Sumgrade;
        }
        public void setequalgrade(double _equalgrade) {
            this.equalgrade=_equalgrade;
        }
        public double Sum() {//sum方法
        	this.Sumgrade=this.Cgrade+this.Egrade+this.Mgrade;
            return(this.Cgrade+this.Egrade+this.Mgrade);
        }
        public void equal() {//equal方法
            equalgrade=Sumgrade/3;
        }
        public void Compare(Student p) {//compare方法
            if(this.getSumgrade()>p.getSumgrade()) {
                System.out.println(this.getname()+"总分大于"+p.getname());
            }
            else if(this.Sumgrade==p.Sumgrade) {
            	System.out.println(this.getname()+"总分等于"+p.getname());
            }
            else
            	System.out.println(this.getname()+"总分小于"+p.getname());
        }
        public double testScore() {//testScore平均分
            return(this.Sumgrade/3);
        }
        public String toString() {//toString方法
            return ("学号"+this.number+"\n姓名:"+name+"\n英语:"+this.Egrade+"\n数学:"+this.Mgrade+"\n计算机:"+this.Cgrade+"\n总分:"+Sum());
        }
}
================================================
package student;
public class StudentBZ extends Student{
     public String zeren;
     public StudentBZ() {
     	super();
     }
     public StudentBZ(int number_,String name_,double Egrade_,double Mgrade_,double Cgrade_,String zeren_) {
     	super(number_,name_,Egrade_,Mgrade_,Cgrade_);
     	zeren=zeren_;
     }
	public double testScore() {
     	return(this.Sumgrade/3+5);
     }
     public String toString() {//toString方法
         return ("学号"+this.number+"\n姓名:"+name+"\n英语:"+this.Egrade+"\n数学:"+this.Mgrade+"\n计算机:"+this.Cgrade+"\n总分:"+Sum()+"\n职位:"+this.zeren);
     }
}

====================================================
package student;
public class StudentXW extends Student{
    public String zeren;
    public StudentXW() {
    	super();
    }
    public StudentXW(int number_,String name_,double Egrade_,double Mgrade_,double Cgrade_,String zeren_) {
    	super(number_,name_,Egrade_,Mgrade_,Cgrade_);
    	zeren=zeren_;
    }
	public double testScore() {
    	return(this.Sumgrade/3+3);
    }
    public String toString() {//toString方法
        return ("学号:"+this.number+"\n姓名:"+name+"\n英语:"+this.Egrade+"\n数学:"+this.Mgrade+"\n计算机:"+this.Cgrade+"\n总分:"+Sum()+"\n职位:"+this.zeren);
    }
}
===========================================
package student;
import java.text.DecimalFormat;
import student.Student;
import student.StudentBZ;
import student.StudentXW;
public class TextStudent {
	public static void main(String[] args) {
		Student student[]={
		        new Student(1,"赵一",70.00f,80.00f,90.00f),
		        new Student(2,"赵二",75.00f,85.00f,90.50f),
		        new Student(3,"赵三",80.00f,86.00f,99.00f),
		        new StudentBZ(4,"赵四",88.0,75.0,90.0,"班长"),
		       	new StudentXW(5,"赵五",81.0,74.0,91.0,"学习委员")
		};
		for(int i=0;i<5;i++) {
		System.out.println(student[i].toString());
			System.out.println("学生名字:"+student[i].getname()+"\t:评测成绩"+new DecimalFormat("0.00").format(student[i].testScore()));
		}
	}
}




网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...