欢迎来到天天文库
浏览记录
ID:49937129
大小:45.00 KB
页数:6页
时间:2020-03-03
《Java初级面向对象练习题.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、l分析学生管理系统涉及到学生类,声明该类。属性:学号、姓名、年龄、计算机成绩、数学成绩、英语成绩;类变量学号最大值(或最后一个学生的学号),每次新建学生对象时,为其分配学号,学号等于学号最大值加1;实现计算平均成绩、总成绩的功能。代码:classStudent{publicstaticintstudentID=0;privateStringname;privateintage;privatedoublecomputergrade;privatedoublemathgrade;privatedoubleenglishgrade;publicStude
2、nt(){this.studentID++;}publicvoidsetName(Stringname){this.name=name;}publicStringgetName(){returnname;}publicvoidsetAge(intage){this.age=age;}publicintgetAge(){returnage;}publicvoidsetComputerGrade(doublecoputergrade){this.computergrade=computergrade;}publicdoublegetComputerGr
3、ade(){returncomputergrade;}publicvoidsetMathGrade(doublemathgrade){this.mathgrade=mathgrade;}publicdoublegetMathGrade(){returnmathgrade;}publicvoidsetEnglishGrade(doubleenglishgrade){this.englishgrade=englishgrade;}publicdoublegetEnglishGrade(){returnenglishgrade;}publicvoidse
4、tSumGrade(doublecomputergrade,doublemathgrade,doubleenglishgrade){this.computergrade=computergrade;this.mathgrade=mathgrade;this.englishgrade=englishgrade;}publicdoublegetSumGrade(){returncomputergrade+mathgrade+englishgrade;}publicvoidsetAvgGrade(doublecomputergrade,doublemat
5、hgrade,doubleenglishgrade){this.computergrade=computergrade;this.mathgrade=mathgrade;this.englishgrade=englishgrade;}publicdoublegetAvgGrade(){return(computergrade+mathgrade+englishgrade)/3;}};publicclassJavaDemo01{publicstaticvoidmain(Stringargs[]){StudentS1=newStudent();Syst
6、em.out.println(“学生ID:”+S1.studentID);//S1.Student();S1.setName("LHJ");System.out.println(“姓名:”+S1.getName());S1.setAge(20);System.out.println(“年龄:”+S1.getAge());S1.setComputerGrade(96.50);System.out.println(“计算机成绩:”+S1.getComputerGrade());S1.setMathGrade(98.00);System.out.prin
7、tln(“数学成绩:”+S1.getMathGrade());S1.setEnglishGrade(99.50);System.out.println(“英语成绩:”+S1.getEnglishGrade());S1.setSumGrade(96.50,98.00,99.50);System.out.println(“总成绩:”+S1.getSumGrade());S1.setAvgGrade(96.50,98.00,99.50);System.out.println(“平均成绩:”+S1.getAvgGrade());}}l现在要求定义一个表示雇
8、员的类,属性:雇员编号、姓名、职位、基本工资、奖金;类变量雇员编号最大值(或最后一个雇员的编号),每次新建雇员对象时,为其
此文档下载收益归作者所有