全国
Java--教育路上

栏目导航

全国站 > Java > 课堂作业
需求

java为被封装的数据赋值,getxx获取被封装的数据

摘要:java为被封装的数据赋值,getxx获取被封装的数据调用setxx方法,为数据赋值 s1.count();//调用count方法。以下是我们为大家整理的,相信大家阅读完后肯定有了自己的选择吧。

标签: getxx
发布时间:
2024-05-13 08:18
信息来源:
网络推荐
浏览次数:
230
java为被封装的数据赋值,getxx获取被封装的数据

package mianxiangduixiang; public class student { public static void main(String[] args) { student s1=new student();//创建学生对象 s1setxx("张三", 90, 80, 78);//调用setxx方法,为数据赋值 s1count();//调用count方法,获取平均值 studentschoolname="重庆中学"; Systemoutprintln("张三"+s1schoolname+s1getaverage()+s1denji()); student s2=new student("lisi",896f,857f,985f);//调用学生方法,为数据赋值 s2count();//调用count方法,获取平均值 Systemoutprintln("李四"+s2schoolname+s2getaverage()+s2denji()); float pingjun = (s2getaverage()+s1getaverage())/2;//两个人的平均分 Systemoutprintln(pingjun); } private String name;//private封装数据,使其不易被访问 private float ywscore; private float yyscore; private float sxscore; static String schoolname; private float average; void setxx(String name,float ywscore,float yyscore,float sxscore) {/txx为被封装的数据赋值 thisname=name; this ywscore= ywscore; thisyyscore=yyscore; thissxscore=sxscore; } student(String name,float ywscore,float yyscore,float sxscore){//构造学生方法 thisname=name; this ywscore= ywscore; thisyyscore=yyscore; thissxscore=sxscore; } student(){ } void count() { thisaverage=(ywscore+yyscore+sxscore)/3;//创建方法 } float getaverage() {//getxx获取被封装的数据 return average; } String denji() { String s=""; if(average>90) s="优秀"; else if(average>80) s="良好"; return s; } }

上一篇:
java私有成员变量,若访问需要s..
下一篇:
java创建一个形状类
相关推荐
最近更新
学校免费发布信息关闭
如有图片请发邮件到:edu63@foxmail.com,审核后显示

 换一张

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


 换一张

确认提交