这次是用String的一位数组加上list来实现的,上一次写短进程优先的时候,认为用date类太麻烦了。所以这次直接用String,没想到,还是一样的麻烦,因为我想要表示小时,分钟,秒数,三个时间单位,而不是两个时间单位。所以在从String转换成int,并进行计算的时候,比较麻烦。其中用到了简单的正则表达式,并将时间先转化成秒进行计算。
附上源码:
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
public class Priority {
private static String[] PCB = {"0进程名", "1运行状态", "2优先级", "3提交时间", "4需要运行时间", "5完成时间", "6周转时间", "7响应比", "8已执行次数"};
//记录当前时间
static String now = "00:00:00";
//时间片
static int timeSlice = 500;
//用String一维数组先建立几个进程
private static String[] process1 = {"process1", "0", "1", "00:08:20", "00:10:56", "", "", "", ""};
private static String[] process2 = {"process2", "0", "3", "00:01:08", "01:00:02", "", "", "", ""};
private static String[] process3 = {"process3", "0", "2", "00:01:01", "00:10:02", "", "", "", ""};
private static String[] process4 = {"process4", "0", "4", "00:01:01", "00:05:02", "", "", "", ""};
private static String[] process5 = {"process5", "0", "7", "00:01:08", "00:00:02", "", "", "", ""};
private static String[] process6 = {"process6", "0", "9", "00:02:08", "00:30:02", "", "", "", ""};
private static String[] process7 = {"process7", "0", "4", "00:03:08", "00:03:01", "", "", "", ""};
private static String[] process8 = {"process8", "0", "2", "00:05:01", "00:00:02", "", "", "", ""};
private static String[] process9 = {"process9", "0", "1", "00:00:13", "00:11:02", "", "", "", ""};
public static void main(String[] args) {
List list = new ArrayList();
list.add(process1);
list.add(process2);
list.add(process3);
list.add(process4);
list.add(process5);
list.add(process6);
list.add(process7);
list.add(process8);
list.add(process9);
System.out.println(PCB[0] + " " + PCB[1] + " " + PCB[2] + " " + PCB[3] + " " + PCB[4]
+ " " + PCB[5] + " " + PCB[6] + " " + PCB[7] + " " + PCB[8]);
startUp(list);
}
//修复String格式转换为long之后再转换为String而造成的格式不正确
public static String modify(String string) {
int i = string.length();
if (i &#