Java: конструктор не определен? ⇐ JAVA

Программисты JAVA общаются здесь
Anonymous
Java: конструктор не определен?

Сообщение Anonymous »

Я пишу программу планирования для школы. Драйвер (Project3.java) вызывает запуск расписания занятий. Мне нужно написать классы (FirstComeFirstServe, ShortestJobFirst, Priority, RoundRobin и PriorityRoundRobin). Моя проблема связана с двумя последними созданными мной классами: RoundRobin и PriorityRoundRobin. Я не могу изменить какой-либо код в Project3.java согласно инструкциям. Однако я получаю следующие ошибки:
ошибка в Project3.java
Вот как я настраиваю RoundRobin и PriorityRoundRobin:

Код: Выделить всё

public class PriorityRoundRobin implements Algorithm {
private List taskList;   // List of tasks to be scheduled
private int timeQuantum;       // Time quantum for round-robin scheduling

// Constructor: Pass task list to create an instance of this class
public PriorityRoundRobin(List taskList) {
this.taskList = new LinkedList(taskList);  // Copy task list for manipulation
}

// Set the time quantum outside of the constructor
public void setTimeQuantum(int timeQuantum) {
this.timeQuantum = timeQuantum;
}

@Override
public void schedule() {
while (!taskList.isEmpty()) {
Task nextTask = pickNextTask();  // Get the next task with the highest priority

if (nextTask != null) {
int burstTime = nextTask.getBurst();  // Get the burst time of the task

// If the burst time is greater than the time quantum
if (burstTime > timeQuantum) {
CPU.run(nextTask, timeQuantum);  // Run task for time quantum
nextTask.setBurst(burstTime - timeQuantum);  // Reduce burst time by time quantum
taskList.add(nextTask);  // Re-add the task to the end of the list
} else {
CPU.run(nextTask, burstTime);  // Run task for remaining burst time
}
}
}
}

@Override
public Task pickNextTask() {
if (taskList.isEmpty()) {
return null;  // No more tasks
}

// Sort the tasks based on priority (lower priority value = higher priority)
taskList.sort((task1, task2) -> Integer.compare(task1.getPriority(), task2.getPriority()));

return taskList.remove(0);  // Remove and return the first (highest-priority) task in the list
}
}
====================================== =============================================== =====

Код: Выделить всё

public class RoundRobin implements Algorithm {
private List taskList;  // List of tasks to be scheduled
private int timeQuantum;      // Time quantum for the round-robin scheduling

// Constructor: Pass task list to create an instance of this class
public RoundRobin(List taskList) {
this.taskList = new LinkedList(taskList);  // Copy task list for manipulation
}

// Set the time quantum outside of the constructor
public void setTimeQuantum(int timeQuantum) {
this.timeQuantum = timeQuantum;
}

@Override
public void schedule() {
while (!taskList.isEmpty()) {
Task nextTask = pickNextTask();  // Get the next task

if (nextTask != null) {
int burstTime = nextTask.getBurst();  // Get the burst time of the task

// If the burst time is greater than the time quantum
if (burstTime > timeQuantum) {
CPU.run(nextTask, timeQuantum);  // Run task for time quantum
nextTask.setBurst(burstTime - timeQuantum);  // Reduce burst time by time quantum
taskList.add(nextTask);  // Re-add the task to the end of the list
} else {
CPU.run(nextTask, burstTime);  // Run task for remaining burst time
}
}
}
}

@Override
public Task pickNextTask() {
if (taskList.isEmpty()) {
return null;  // No more tasks
}

return taskList.remove(0);  // Remove and return the first task in the list
}
}
Я несколько раз пытался изменить конструктор. Изначально у меня было два аргумента. Однако Project3.java ищет только один аргумент. Итак, я скорректировал его и удалил квантовое время за пределами конструктора, но ошибки остались. Я не уверен, что еще делать. Я новичок в Java.
Project3.java (который нельзя изменить)

Код: Выделить всё

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Program3
{
private static BufferedReader inFile = null;
private static Scanner input = null;

//***************************************************************
//
//  Method:       main
//
//  Description:  The main method of the program
//
//  Parameters:   String array
//
//  Returns:      N/A
//
//**************************************************************
public static void main(String[] args)
{
Program3 obj = new Program3();

input = new Scanner(System.in);

obj.developerInfo();
obj.mainlineProcess();
}

//***************************************************************
//
//  Method:       mainlineProcess
//
//  Description:  This method starts the program
//
//  Parameters:   None
//
//  Returns:      N/A
//
//**************************************************************
public void mainlineProcess()
{
String scheduleName = null;
String algorithmFilename = null;

displayMessage();
scheduleName = getUserInput("Enter the algorithm type: ");
while (!scheduleName.equalsIgnoreCase("End"))
{
algorithmFilename = getUserInput("Enter the schedule filename: ");

openAlgorithmFile(algorithmFilename);
List queue = createPopulateQueue();
processAlgorithm(scheduleName, queue);

try {
if (inFile != null)
inFile.close();
}
catch (IOException exp)
{
System.err.println("Error - Input/Output Exception. Good Bye!");
System.exit(1);
}
catch (Exception exp)
{
System.err.println("Error - Unknown Exception. Good Bye!");
System.exit(1);
}

displayMessage();
scheduleName = getUserInput("Enter the algorithm type or \"End\" to exit: ");
}

System.out.println("\nThanks for using the CPU scheduler - Bye!");
}

//***************************************************************
//
//  Method:       getUserInput
//
//  Description:  This method gets the user input data
//
//  Parameters:   String prompt
//
//  Returns:      String
//
//**************************************************************
public String getUserInput(String prompt)
{
System.out.print(prompt);

String inputData = input.nextLine();

return inputData;
}

//***************************************************************
//
//  Method:       openAlgorithmFile
//
//  Description:  This opens the algorithm file
//
//  Parameters:   String input (File)
//
//  Returns:      N/A
//
//**************************************************************
public void openAlgorithmFile(String input)
{
try {
inFile = new BufferedReader(new FileReader(input));
}
catch (FileNotFoundException exp)
{
System.err.println("Error - The Schedule file was not found.  Good Bye!");
System.exit(1);
}
}

//***************************************************************
//
//  Method:       openAlgorithmFile
//
//  Description:  This method reads in the tasks and populates
//                the ready queue
//
//  Parameters:   None
//
//  Returns:      List
//
//**************************************************************
public List createPopulateQueue()
{
// create the queue of tasks
List queue = new ArrayList();

String scheduleRecord;

// read in the tasks and populate the ready queue
try {
while ((scheduleRecord = inFile.readLine()) != null)
{
String[] tokens = scheduleRecord.split(",\\s*");
queue.add(new Task(tokens[0], Integer.parseInt(tokens[1]), Integer.parseInt(tokens[2])));
}
}
catch (IOException exp)
{
System.err.println("Error - Input/Output Exception. Good Bye!");
System.exit(1);
}
catch (NumberFormatException exp)
{
System.err.println("Error - Number Format Exception. Good Bye!");
System.exit(1);
}
catch (Exception exp)
{
System.err.println("Error - Unknown Exception. Good Bye!");
System.exit(1);
}

return queue;
}

//***************************************************************
//
//  Method:       processAlgorithm
//
//  Description:  A method to call the CPU schedule algorithms
//
//  Parameters:   String choice
//                List queue
//
//  Returns:      N/A
//
//**************************************************************
public void processAlgorithm(String choice, List queue)
{
Algorithm scheduler = null;

switch(choice)
{
case "FCFS":
scheduler = new FirstComeFirstServed(queue);
break;
case "SJF":
scheduler = new ShortestJobFirst(queue);
break;
case "PRI":
scheduler = new Priority(queue);
break;
case "RR":
scheduler = new RoundRobin(queue);
break;
case "PRI-RR":
scheduler = new PriorityRoundRobin(queue);
break;
default:

System.err.println("Invalid algorithm. Good Bye!!");
System.exit(0);
}

// start the scheduler
scheduler.schedule();
}

//***************************************************************
//
//  Method:       displayMessage
//
//  Description:  This method displays a message to the screen
//
//  Parameters:   None
//
//  Returns:      N/A
//
//***************************************************************
public void displayMessage()
{
System.out.println("Scheduling Algorithms");
System.out.println("FCFS   - First-come, first-served scheduling");
System.out.println("SJF    - Shortest-job-first scheduling");
System.out.println("PRI    - Priority scheduling");
System.out.println("RR     - Round-robin scheduling");
System.out.println("PRI-RR - Priority with round-robin scheduling\n");
}
Имя классов выше: RoundRobin.java, PriorityRoundRobin.java

Подробнее здесь: https://stackoverflow.com/questions/791 ... -undefined

Вернуться в «JAVA»