全国
Java--教育路上

栏目导航

全国站 > Java > Java初学
需求

构造方法为成员变量赋值

摘要:构造方法为成员变量赋值。以下是我们为大家整理的,相信大家阅读完后肯定有了自己的选择吧。

标签: 成员变量
发布时间:
2024-05-02 13:11
信息来源:
网络推荐
浏览次数:
1671
构造方法为成员变量赋值

package zhang7;
import zhang7.student;

public class test {

	public static void main(String[] args) {
		student.schoolname="重庆中学";
		student s1=new student();
		s1.setxx("zhangsan", 90.6f, 98.5f, 87.9f);
		s1.count();
		System.out.println("zhangsan"+s1.schoolname +s1.getaverage()+s1.dengji());
	

	}

}



package zhang7;

public class student {
	private String name;
	private float ywscore;
	private float sxscore;
	private float yyscore;
	static String schoolname;
	private float average;
	
	void setxx(String name,float ywscore,float sxscore,float yyscore) {
		this.name=name;
		this.ywscore=ywscore;
		this.sxscore=sxscore;
		this.yyscore=yyscore;
	}
	
	student(){
		
	}
	
	student(String name,float ywscore,float sxscore,float yyscore){
		this.name=name;
		this.ywscore=ywscore;
		this.sxscore=sxscore;
		this.yyscore=yyscore;
	}
	
	void count() {
		this.average=(ywscore+sxscore+yyscore)/3;
	}
	
	float getaverage() {
		return average;
	}
	
	String dengji() {
		String str="";
		if(average>90)
			str="优秀";
		else if(average>80)
			str="良好";
		return str;
	}
	

}

上一篇:
student学生类的封装和构造方法..
下一篇:
Java 构造方法的定义
相关推荐
最近更新
学校免费发布信息关闭
如有图片请发邮件到:edu63@foxmail.com,审核后显示

 换一张

确认提交
完善补充本文信息关闭
非常感谢您帮助完善补充本文信息


 换一张

确认提交