Java Programming Please help me with this Java Progamming project NOT GRADED. Practice homework Please comment the code well and organize the classes so I can understand. Thank you! If solution if the one that is desirable, I will upvote! I really appreciate this, Bartleby! Waiting Times should not be negative. You sent back a solution but the waiting time was negative and that was incorrect. Please take your time and help me with this.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Java Programming

Please help me with this Java Progamming project

NOT GRADED. Practice homework

Please comment the code well and organize the classes so I can understand. Thank you!

If solution if the one that is desirable, I will upvote! I really appreciate this, Bartleby!

Waiting Times should not be negative. You sent back a solution but the waiting time was negative and that was incorrect. Please take your time and help me with this.

**Task Set**

Consider the following task set:

| Task Name | Priority (when applicable) | CPU burst (ms) |
|-----------|----------------------------|----------------|
| T1        | 2                          | 20             |
| T2        | 4                          | 25             |
| T3        | 3                          | 25             |
| T4        | 3                          | 15             |
| T5        | 1                          | 10             |

**Task Set Details:**
- Priorities range from 1 to 4, where a lower numeric value indicates a higher relative priority.
- For round-robin scheduling, the length of a time quantum is 10 milliseconds.

**Scheduling Algorithms:**
Implement the following four scheduling algorithms in four different threads using the Java programming language. The main thread will print on the console the generated schedule using a modified Gantt chart, average waiting time, and average turnaround time for each algorithm.

1. **First-come, first-served (FCFS):** 
   - Assumes all the tasks arrive at the same time.

2. **Shortest-job-first (SJF):** 
   - Assumes all the tasks arrive at the same time.
   - Breaks ties randomly.

3. **Preemptive priority scheduling (PS):**
   - Uses the given priorities and a random arrival time (in ms) in the interval [0, 100] for each task.
   - Random arrival times must be generated using a Java random number generator.
   - Print arrival times before printing the schedule.

4. **Round-robin (RR) scheduling:**
   - Each task runs for a time quantum (or for the remainder of its CPU burst).
Transcribed Image Text:**Task Set** Consider the following task set: | Task Name | Priority (when applicable) | CPU burst (ms) | |-----------|----------------------------|----------------| | T1 | 2 | 20 | | T2 | 4 | 25 | | T3 | 3 | 25 | | T4 | 3 | 15 | | T5 | 1 | 10 | **Task Set Details:** - Priorities range from 1 to 4, where a lower numeric value indicates a higher relative priority. - For round-robin scheduling, the length of a time quantum is 10 milliseconds. **Scheduling Algorithms:** Implement the following four scheduling algorithms in four different threads using the Java programming language. The main thread will print on the console the generated schedule using a modified Gantt chart, average waiting time, and average turnaround time for each algorithm. 1. **First-come, first-served (FCFS):** - Assumes all the tasks arrive at the same time. 2. **Shortest-job-first (SJF):** - Assumes all the tasks arrive at the same time. - Breaks ties randomly. 3. **Preemptive priority scheduling (PS):** - Uses the given priorities and a random arrival time (in ms) in the interval [0, 100] for each task. - Random arrival times must be generated using a Java random number generator. - Print arrival times before printing the schedule. 4. **Round-robin (RR) scheduling:** - Each task runs for a time quantum (or for the remainder of its CPU burst).
[Scheduling Algorithm Name:]
[Arrival Times (only for PS algorithm)]
[A textual presentation of the Gantt chart of the generated schedule (see example)]
[Avg. waiting time: …]

[Avg. turnaround time: …]

Example:

**FCFS:**
- T1 [0 – 20], T2 [24 – 45], T3 [45 – 70], …
- Avg. waiting time: 12.3
- Avg. turnaround time: 12.3

**SJF:**
- …..
- …..
- …..

**PS:**
- Arrival Times: T1 = 10, T2 = 70, T3 = 30, …
- T1 [10 – 30], T3 [….
- …..
- …..

**RR:**
- …..
- …..
- …..

**Note:** T1 [0 – 20] means that the task T1 is run from 0 to 20 ms. Please don’t show your outputs in any other formats (e.g., by adding extra commas, symbols, etc.).
Transcribed Image Text:[Scheduling Algorithm Name:] [Arrival Times (only for PS algorithm)] [A textual presentation of the Gantt chart of the generated schedule (see example)] [Avg. waiting time: …] [Avg. turnaround time: …] Example: **FCFS:** - T1 [0 – 20], T2 [24 – 45], T3 [45 – 70], … - Avg. waiting time: 12.3 - Avg. turnaround time: 12.3 **SJF:** - ….. - ….. - ….. **PS:** - Arrival Times: T1 = 10, T2 = 70, T3 = 30, … - T1 [10 – 30], T3 […. - ….. - ….. **RR:** - ….. - ….. - ….. **Note:** T1 [0 – 20] means that the task T1 is run from 0 to 20 ms. Please don’t show your outputs in any other formats (e.g., by adding extra commas, symbols, etc.).
Expert Solution
Step 1: Algorithm for Task Scheduling with Multiple Algorithms
  1. Import necessary Java libraries (ArrayList, Collections, List, and Random).
  2. Define a Task class to represent tasks with attributes such as name, priority, burst time, and arrival time. Initialize these attributes through a constructor.
  3. Create a public class named SchedulingAlgorithms.
  4. In the main method:
    • Initialize the task set using the initializeTaskSet method.
    • Create and start four threads to execute different scheduling algorithms: FCFS, SJF, Priority Scheduling, and Round-Robin.
  5. Implement the initializeTaskSet method:
    • Initialize the taskSet as an ArrayList.
    • Create Task objects and add them to the task set.
    • Assign random arrival times in the range [0, 100].
    • Sort tasks based on arrival time in ascending order.
  6. Implement the executeFCFS method:
    • Calculate the wait time, turnaround time, and update the current time.
    • Print the schedule for each task.
    • Initialize variables to keep track of current time, total wait time, and total turnaround time.
    • For each task in the task set:
    • Calculate and print the average waiting and turnaround times.
  7. Implement the executeSJF method:
    • Sort tasks based on burst time in ascending order.
    • Call the executeFCFS method to execute Shortest Job First (SJF) scheduling.
  8. Implement the executePriority method:
    • Calculate the wait time, turnaround time, and update the current time.
    • Print the schedule for each task.
    • Initialize variables to keep track of current time, total wait time, and total turnaround time.
    • For each task in the task set:
    • Calculate and print the average waiting and turnaround times.
  9. Implement the executeRoundRobin method:
    • For each task in the list of remaining tasks:
      • Calculate the remaining burst time, wait time, and turnaround time.
      • Update the current time, task's burst time, and remove the task if it's completed.
    • Initialize variables to keep track of current time, total wait time, total turnaround time, and define the time quantum.
    • Create a list of remaining tasks as a copy of the task set.
    • While there are remaining tasks:
    • Calculate and print the average waiting and turnaround times.
  10. Implement the printAverages method:
    • Calculate the average waiting and turnaround times.
    • Print the calculated average waiting and turnaround times.
  11. End of the algorithm.

This algorithm describes the high-level steps for scheduling tasks using First-Come-First-Serve (FCFS), Shortest Job First (SJF), Priority Scheduling, and Round-Robin scheduling algorithms as implemented in the provided Java code.

steps

Step by step

Solved in 6 steps with 7 images

Blurred answer
Knowledge Booster
Files and Directory
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education