test.java
来自「继承和多态 实验目的: 1、 掌握继承和多态的概念与实现方法 2、 掌握如」· Java 代码 · 共 90 行
JAVA
90 行
package generalSort;
/**
* <p>Title: Test</p>
*
* <p>Description: A class to test the function of the generalSort algorithm</p>
*
* <p>Copyright: Copyright (c) 2008 All rights reserved</p>
* <p>Organization :Shandong University </p>
* @Email:ruohanxiao@yahoo.com.cn
* @author: Xiao Ruohan
* @version 1.0
*/
public class Test {
public Test() {
}
public static String print(Object ob[]) {
String str = "";
for (int i = 0; i < ob.length; i++) {
//System.out.println(ob[i].toString());
str += ob[i].toString() + "\n";
}
return str;
}
public static void main(String[] args) {
Student s[] = new Student[5];
int s_len = s.length;
Rectangle r[] = new Rectangle[5];
int r_len = r.length;
Student s_temp;
Rectangle r_temp;
SortTest st = new SortTest();
FileRecord fr = new FileRecord();
int i = 0;
int j = 0;
int scale = 26;
String befSort =
"**************************Before sorting**************************";
String aftSort =
"**************************After sorting**************************";
String endStr =
"<---------------------------Report ends------------------------------->";
//System.out.println(befSort);
fr.append_tofile(befSort);
for (i = 0; i < s_len; i++) {
s[i] = new Student((int) (scale * Math.random()) + 1,
StringPlus.randomString(), 2);
}
fr.append_tofile(print(s));
for (i = 0; i < r_len; i++) {
r[i] = new Rectangle((int) (scale * Math.random()) + 1,
(int) (scale * Math.random()) + 1);
}
fr.append_tofile(print(r));
//System.out.println(aftSort);
fr.append_tofile(aftSort);
for (i = 0; i < s_len; i++) {
for (j = 1; j < s_len - i; j++) {
if (st.compare(s[j], s[j - 1]) < 0) {
st.swapObject(s, j, j - 1);
}
}
}
fr.append_tofile(print(s));
for (i = 0; i < r_len; i++) {
for (j = 1; j < r_len - i; j++) {
if (st.compare(r[j], r[j - 1]) < 0) {
st.swapObject(r, j - 1, j);
}
}
}
fr.append_tofile(print(r));
fr.append_tofile(endStr);
fr.open_file();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?