提交的话,需要将hrrf改为Main,package去掉
package pta;
import java.util.*;
class Work{
String workName; //workName用来记录作业名
float finishTime; //finishTime记录作业完成时间
float arriveTime; //arriveTime记录作业到达时间
float turnAroundTime; //turnAroundTime记录作业周转时间
float daiTime; //daiTime记录作业带权周转时间
float serviceTime; //serviceTime记录作业服务时间
float priority; //priority记录作业优先级;
}
public class hrrf {
public static void main(String[] args) {
Scanner writer=new Scanner(System.in);
//System.out.println("请输入作业数量:");
int numb=writer.nextInt();
Work example=new Work();
Work[] work=new Work[numb];
//System.out.printf("请输入%d个作业名:\n",numb);
for(int i=0;i<numb;i++) {
work[i]=new Work();
work[i].workName=writer.next();
}
//System.out.printf("请输入%d个作业到达时间:\n",numb);
for(int i=0;i<numb;i++) {
work[i].arriveTime=writer.nextFloat();
}
//System.out.printf("请输入%d个作业服务时间:\n", numb);
for(int i=0;i<numb;i++) {
work[i].serviceTime=writer.nextFloat();
}
for(int i=0;i<numb-1;i++) { //根据到达时间排序第一次
for(int j=i+1;j<numb;j++) {
if(work[i].arriveTime>work[j].arriveTime) {
example=work[j];
work[j]=work[i];
work[i]=example;
}
}
}
for(int i=0;i<numb;i++) {
if(i>0) {
work[i].priority=(work[i-1].finishTime-work[i].arriveTime)/work[i].serviceTime;
}
for(int j=i;j<numb;j++) {
if(i==0) {
work[i].finishTime=work[i].arriveTime+work[i].serviceTime;
break;
}
else {
if(work[i-1].finishTime>=work[j].arriveTime) {
work[j].priority=(work[i-1].finishTime-work[j].arriveTime)/work[j].serviceTime;
if(work[j].priority>work[i].priority) {
example=work[j];
work[j]=work[i];
work[i]=example;
}
work[i].finishTime=work[i-1].finishTime+work[i].serviceTime;
}
else if(work[i-1].finishTime<work[i].arriveTime){
work[i].finishTime=work[i].arriveTime+work[i].serviceTime;
break;
}
}
}
work[i].turnAroundTime=work[i].finishTime-work[i].arriveTime;
work[i].daiTime=work[i].turnAroundTime/work[i].serviceTime;
}
// for(int i=0;i<numb;i++) {
// System.out.printf("%.0f",work[i].arriveTime);
// }
for(int i=0;i<numb-1;i++) { //根据到达时间排序第二次
for(int j=i+1;j<numb;j++) {
if(work[i].arriveTime>work[j].arriveTime) {
example=work[j];
work[j]=work[i];
work[i]=example;
}
}
}
System.out.printf("作 业 名:"); //输出作业名
for(int i=0;i<numb;i++) {
if(i<numb-1){
System.out.printf("%s ",work[i].workName);
}
else {
System.out.printf("%s",work[i].workName);
}
}
System.out.printf("\n到达时间:"); //输出到达时间
for(int i=0;i<numb;i++) {
if(i<numb-1){
System.out.printf("%.0f ",work[i].arriveTime);
}
else {
System.out.printf("%.0f",work[i].arriveTime);
}
}
System.out.printf("\n服务时间:"); //输出服务时间
for(int i=0;i<numb;i++) {
if(i<numb-1){
System.out.printf("%.0f ",work[i].serviceTime);
}
else {
System.out.printf("%.0f",work[i].serviceTime);
}
}
System.out.printf("\n完成时间:"); //输出完成时间
for(int i=0;i<numb;i++) {
if(i<numb-1){
System.out.printf("%.0f ",work[i].finishTime);
}
else {
System.out.printf("%.0f",work[i].finishTime);
}
}
System.out.printf("\n周转时间:"); //输出周转时间
for(int i=0;i<numb;i++) {
if(i<numb-1){
System.out.printf("%.0f ",work[i].turnAroundTime);
}
else {
System.out.printf("%.0f",work[i].turnAroundTime);
}
}
System.out.printf("\n带权周转时间:"); //输出带权周转时间
for(int i=0;i<numb;i++) {
if(i<numb-1){
System.out.printf("%.2f ",work[i].daiTime);
}
else {
System.out.printf("%.2f",work[i].daiTime);
}
}
}
}