【计算机类职业资格】程序员-Java程序设计(二)及答案解析.doc
《【计算机类职业资格】程序员-Java程序设计(二)及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】程序员-Java程序设计(二)及答案解析.doc(11页珍藏版)》请在麦多课文档分享上搜索。
1、程序员-Java 程序设计(二)及答案解析(总分:100.03,做题时间:90 分钟)一、试题一(总题数:1,分数:25.00)阅读以下说明和 Java代码,填补 Java代码中的空缺,将解答写在对应栏内。说明己知某公司按周给员工发放工资,其工资系统需记录每名员工的员工号、姓名、工资等信息。其中一些员工是正式的,按年薪分周发放(每年按 52周计算);另一些员工是计时工,以小时工资为基准,按每周工作小时数核算发放。下面是实现该工资系统的 Java代码,其中定义了四个类:工资系统类 PayRoll,员工类 Employee,正式工类 Salaried和计时工类 Hourly,Salaried 和
2、Hourly是 Employee的子类。Java代码abstract class Employeeprotected String name; /员工姓名protected int empCode; /员工号protected double salary; /周发放工资publ ic Employee(int empCode,String name)this.empCode=empCode;this.name=name;public double getSalary()return this.salary;public abstract void pay();class Salaried _
3、Employeeprivate double annualSalary;Salaried(int empCode,String name,double payRate)super(empCode,name);this.annualSalary=payRate;public void pay()salary=_;/计算正式员工的周发放工资数System.out.printin(this.name+“:“+this.salary);class Hourly _ Empioyeeprivate double hourlyPayRate;private int hours;Hourly(int emp
4、Code,String name,int hours,double payRate)super(empCode,name);this.hourlyPayRate=payRate;this.hows=hours,public void pay()salary=_;/计算计时工的周发放工资数System.out.printin(this.name+“:“+this.salary);public class PayRollprivate _ employees=new Salaried(1001,“Zhang San“,58000.00),/此处省略对其他职工对象的生成new Hourly(1005
5、,“Li“,12,50.00);public void pay(Employee e)for(int i=0;ie.length;i+)ei.pay();public static void main(Stringrgs)PayRoll payRoll=new PayRoll();payRoll.pay(_);double total=0.0;for(int i=0;ipayRoll.employees.length;i+)/统计周发放工资总额total+=payRoll.employeesi.getSalary();System.out.printin(total);(分数:25.02)填空
6、项 1:_填空项 1:_填空项 1:_填空项 1:_填空项 1:_填空项 1:_二、试题二(总题数:1,分数:25.00)阅读以下说明和 Java程序,填充程序中的空缺,将解答填入对应栏内。说明下面的程序用来计算并寻找平面坐标系中给定点中最近的点对(若存在多对,则输出其中的一对即可)。程序运行时,先输入点的个数和一组互异的点的坐标,通过计算每对点之间的距离,从而确定出距离最近的点对。例如,在图所示的 8个点中,点(1,1)与(2,0.5)是间距最近的点对。(分数:25.00)填空项 1:_填空项 1:_填空项 1:_填空项 1:_填空项 1:_三、试题三(总题数:1,分数:25.00)阅读以下
7、说明和 Java代码,将应填入_处的语句或语句成分写在对应栏内。说明某数据文件 students.txt的内容为 100名学生的学号和成绩,下面的程序将文件中的数据全部读入对象数组,按分数从高到低进行排序后选出排名前 30%的学生。Java代码import Java.io.*;class Studentprivate String sNO; /学号private int Credit; /分数public int getCredit()return Credit;public String toString()return“sNO=“+this.sNO+“,Credit=“+this.Cred
8、it;Student(String sNO,int Credit)_=sNO;_=Credit;public class SortStudentvoid sort(Students)/Sort the array s in decending order of Creditfor(int i=0;is.length-1;i+)for(int j=i+1;js.length;j+)if(si._sj._)Student tmp=si;si=sj;sj=tmp;public static void main(String argv)Student testStudent=new Studentsi
9、ze;tryBufferedReader in=new BufferedReader(new FileReader(“students.txt“);boolean done=false;int i=0;while(!done)String s=in.readLine(); /每次读取一个学生的学号和成绩if(s!=rimll)String tmp=s.split(“,“);testStudenti+=_(tmp0,Integer.parseInt(tmp1);elsedone=true;in.closeo();_=new SortStudent();ss.Soft(testStudent);S
10、ystem.out.printin(“top 30%:“);for(int j=0;jsize*0.3;j+)System.out.printin(testStudentj);catch(IOException e)System.out.printin(“io error!“);catch(NumberFormatException e)System.out.println(“not a number!“);_int size=100; /学生总数(分数:25.02)填空项 1:_填空项 1:_填空项 1:_填空项 1:_填空项 1:_填空项 1:_四、试题四(总题数:1,分数:25.00)阅
11、读以下说明和 Java代码,将应填入_处的语句或语句成分写在对应栏内。说明某数据文件 students.txt的内容为 100名学生的学号和成绩,下面的程序将文件中的数据全部读入对象数组,按分数从高到低进行排序后选出排名前 30%的学生。Java代码import java.io.*;class Studentprivate String sNO;/学号private int Credit;/分数public int getCredit()return Credit;public string toString()return“sNO=“+this.sNO+“,Credit=“+this.Cre
12、dit;Student(String sNO,int Credit)_=sNO;_=Credit;public class SortStudentvoid sort(Students)/Sort the array s in decending order of Creditfor(int i=0;is.length-1;i+)for(int j=i+1:js.length;j+)if(si._sj._)Student tmp=si;si=sj;sj=tmp;public static void main(String argv)Student testStudent=new Students
13、iZe;tryBufferedReader in=new BufferedReader(new FileReader(“students.txt“);boolean done=false;int i=0;while(!done)String s=in.readLine(); /每次读取一个学生的学号和成绩if(s!=null)String tmp=s.split(“,“);testStudenti+=_(tmp0,Integer.parseInt(tmp1);elsedone=true;in.closeo();_=new SortStudent();ss.sort(testStudent);S
14、ystem.out.printin(“top 30%:“);for(int j=0;jsize*0.3;j+)System.out.printin(testStudentj);catch(IOException e)System.out.printin(“io error!“);catch(NumberFormatException e)System.out.printin(“not a number!“);_int size=100; /学生总数(分数:24.99)填空项 1:_填空项 1:_填空项 1:_填空项 1:_填空项 1:_填空项 1:_填空项 1:_程序员-Java 程序设计(二
15、)答案解析(总分:100.03,做题时间:90 分钟)一、试题一(总题数:1,分数:25.00)阅读以下说明和 Java代码,填补 Java代码中的空缺,将解答写在对应栏内。说明己知某公司按周给员工发放工资,其工资系统需记录每名员工的员工号、姓名、工资等信息。其中一些员工是正式的,按年薪分周发放(每年按 52周计算);另一些员工是计时工,以小时工资为基准,按每周工作小时数核算发放。下面是实现该工资系统的 Java代码,其中定义了四个类:工资系统类 PayRoll,员工类 Employee,正式工类 Salaried和计时工类 Hourly,Salaried 和 Hourly是 Employee
16、的子类。Java代码abstract class Employeeprotected String name; /员工姓名protected int empCode; /员工号protected double salary; /周发放工资publ ic Employee(int empCode,String name)this.empCode=empCode;this.name=name;public double getSalary()return this.salary;public abstract void pay();class Salaried _ Employeeprivate
17、double annualSalary;Salaried(int empCode,String name,double payRate)super(empCode,name);this.annualSalary=payRate;public void pay()salary=_;/计算正式员工的周发放工资数System.out.printin(this.name+“:“+this.salary);class Hourly _ Empioyeeprivate double hourlyPayRate;private int hours;Hourly(int empCode,String name
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 程序员 JAVA 程序设计 答案 解析 DOC
