当前位置:首页计算机类软件水平考试初级程序员->阅读以下说明和Java代码,将应填入(n)处的语句或语句成分

阅读以下说明和Java代码,将应填入 (n) 处的语句或语句成分写在答题纸的对应栏内。

【说明】

某数据文件students.txt的内容为100名学生的学号和成绩,下面的程序将文件中的数据全部读入对象数组,按分数从高到低进行排序后选出排名前30%的学生。

【Java代码】

import java.io.*;

class Student {

private String sNO; //学号

private int Credit; //分数

public int getCredit( ){

return Credit;

}

public String toString() {

return "sNO = " + this.sNO + ", Credit = " + this.Credit;

}

Student(String sNO, int Credit){

(1) = sNO;

(2) = Credit;

}

}

public class SortStudent {

void sort(Student[ ] s) { //Sort the array s[ ] in descending order of

Credit

for (int i = 0; i < s.length-1; i++) {

for (int .j = i+1; j < s.length; j++) {

if (s[i]. (3) < s[j]. (4) ) {

Student tmp = s[i];

s[i] = s[j];

s[j] = tmp;

}

}

}

}

public static void main(String argv[ ]) {

Student[ ] testStudent = new Student[size];

try {

BufferedReader 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(",");

testStudent[i++] = (5) (tmp[0], Integer.parseInt

(tmp[1]));

} else

done = true;

}

in.close();

(6) = new SortStudent();

ss.sort(testStudent);

System.out.println("top 30%:");

for (int j = 0; j < size * 0.3; j++)

System.out.println(testStudent[j]);

} catch (IOException e) {

System.out.println("io error!");

}catch (NumberFormatException e) {

System.out.println("not a number!");

}

}

(7) int size = 100; //学生总数

}

查看答案 纠错
答案:
本题解析:

(1)this.sNO

(2)this.Credit

(3)getCredit()

(4)getCredit()

(5)new Student

(6)SortStudent ss

(7)static 或static final

首先分析程序的整体结构,本题中定义了两个类:Student和SortStudent,分别用于定义学生和进行排序。类Student的定义中,第一部分为private访问权限的成员,要对其进行访问,需要通过具有相应访问权限的成员函数。

Student类的构造器方法的参数和类中属性同名,需要用this标识符进行区分,因此前面俩空需要用this表明当前Student的属性。

SortStudent类中的成员函数sort和Student类的对象所构成的对象数组根据分数进行排序,而由于在Strdent类中学号和分数为private访问权限,不可从外部直接访问,所以要通过getCredit而得到。

Main函数中需要将学生信息读入,并根据学生信息创建对象并加入对象数组。空(5)为new Student。空(6)处根据其所在的语句右侧new SortStudent以及其后序语句ss.sort的方法调用,可知,需要声明SortStudent类的对象引用ss,所以空(6)处为SortStrdent ss。空(7)处是属性size的类型描述,size是作为作为数组大小的参数,其值不可变,因此是static 或者static final。

更新时间:2021-11-20 13:36

你可能感兴趣的试题

单选题

( )is that it provides guidance and direction on how quality will be managed and verified throughout the project.

  • A.Plan Quality Management
  • B.Manage Quality
  • C.Control Quality
  • D.Project Charter
查看答案
单选题

( )the process of determining,documenting,and managing stakeholder needs and requirements to meet Project objectives.

  • A.Plan Scope Management
  • B.Collection Requirements
  • C.Validate Scope
  • D.Control Scope
查看答案
单选题

The information security management system preserves the confidentiality,integrity and availability of information by applying a( ).

  • A.technology management process
  • B.resource management process
  • C.quality management process
  • D.risk management process
查看答案
单选题

( )is a decentralized database,ensure that the data will not be tampered with and forged.

  • A.Artificial intelligence
  • B.Blockchain
  • C.Sensing technology
  • D.Big datA
查看答案
单选题

( )puts computer resources on the web,and must meet the requirements of super capacity,super concurrency,super speed and super security.

  • A.Cloud computing
  • B.Big datA
  • C.Blockchain
  • D.Internet of things
查看答案
单选题

分配甲、乙、丙、丁四个人去完成五项任务。每人完成各项任务时间如表所示。由于任务多于人数,故规定其中有一个人可兼完成两项任务,其余三人每人完成一项。为了花费时间最少,( )应该完成两项任务。

高级信息系统项目管理师,历年真题,2021年下半年《信息系统项目管理师》真题

  • A.甲
  • B.乙
  • C.丙
  • D.丁
查看答案
单选题

已知某公司生产AB两种产品,其中生产1件A产品需要1个单位的甲资源,3个单位的丙资源;生产1件B产品需要2个单位的乙资源和2个单位的丙资源。已知现有甲乙丙三种资源4个单位、12个单位和18个单位。通过市场预测,可知A产品的单位市场利润为2元,B产品的单位市场利润为5元。该公司获得最大的市场利润应生产A产品(68)件,此时(69)资源仍有剩余。

  • A.甲
  • B.乙
  • C.丙
  • D.甲及丙
查看答案
单选题

已知某公司生产AB两种产品,其中生产1件A产品需要1个单位的甲资源,3个单位的丙资源;生产1件B产品需要2个单位的乙资源和2个单位的丙资源。已知现有甲乙丙三种资源4个单位、12个单位和18个单位。通过市场预测,可知A产品的单位市场利润为2元,B产品的单位市场利润为5元。该公司获得最大的市场利润应生产A产品(68)件,此时(69)资源仍有剩余。

  • A.0
  • B.2
  • C.4
  • D.6
查看答案
单选题

某项目2016年投资额12万元,2018年开始取得项目的净收益(产品一原料辅料及公用工程)6万元/年,2018-2021年每年还会产生其他成本(包括人员工资、管理成本、制造成本等)1.1万元/年;増值税0.35万元/年、营业税金及附加0.05万元/年。则该项目的静态投资回收期为(66)年,截止到2021年底该项目的投资收益率是(67)。

  • A.0.25
  • B.0.33
  • C.0.35
  • D.0.6
查看答案
单选题

安全审计的手段主要包括( )。

  • A.①②③
  • B.②③④
  • C.①②④
  • D.①③④
查看答案