Andrey Petrov

Greenhorn
+ Follow
since Sep 25, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Andrey Petrov

I am stuck. Help. It's late, I'm tired. My mind refuses to think.
One thing: Doesn't increment globalTime;
Two thing: Heap misbehaves.
Three thing: Wrong output.

The purpose of this programming project is to learn to use priority queues (a.k.a. heaps).
Overview
One common use of priority queues is in simulation. A software simulator attempts to mimic
some real-life problem based on a set of parameters and assumptions. You are to build a
simple simulator to demonstrate a how a computer’s job scheduling algorithm works. Your
simulator will use two priority queues to accomplish that, one that prioritizes events by
time, and one that prioritizes jobs based on their specified priorities.
Your simulator will read a text file containing job information, such as the job’s submission
time, execution time, and priority. Your simulator will write a text file of information about
each job’s execution, including its start time and end time.
For this project, time will be represented by integers, starting at time 0 and ending when
the last job finishes execution.
Input
Your input file will be a text file named “Jobs.txt” that will contain information about the
sequence of jobs whose execution you will simulate. Each line of the input file will
represent one job. The information about each job will consist of its job ID (a character
string without spaces), its arrival time (an integer greater than or equal to zero), its priority
(an integer between zero and 255 where a larger number indicates higher priority), and its
run time (an integer greater than zero). For example, the following is a possible input file:

Sample Jobs.txt Input File
JobID Arrival Time Priority Run Time
Job1 0 5 12
Job2 0 10 10
Job3 8 15 6
Job4 9 0 25
Job5 15 99 9
I suggest creating a Job class that to contain the information about each job. The class will
need to implement the Comparable interface, which means it will need to have a method
named compareTo() that will compare two jobs by priority.

Output
Your output will be a text file named “Schedule.txt” that will describe how the jobs got
scheduled and run according to time and priority. Each line of the output file will contain
information about one job, and the file will be ordered in the jobs’ run sequence. The
information to be output for each job will be its job ID, its start time, its end time, its
arrival time, its priority, and its run time. The following table shows what the output for
the above input would be:

Sample Schedule.txt Output File
JobID Start Time End Time Arrival Time Priority Run Time
Job2 0 10 0 10 10
Job3 10 16 8 15 6
Job5 16 25 15 99 9
Job1 25 37 0 5 12
Job4 37 62 9 0 25
Deliverables
A ZIP file containing your project.
Processing
For this project use the class MyPriorityQueue from Chapter 25 for your priority queue
objects. You will need two priority queues.
The first will contain scheduler events. It will be prioritized by event time, with an earlier
time being a higher priority. An event may be either a job arrival or a job completion.
I suggest creating a JobEvent class to represent events. The class should contain an event
type, an event time, and a Job object. This class will need to implement the Comparable
interface, including a compareTo() method that will compare two events and prioritize them
by time, with earlier times having higher priority.
You second priority queue will contain all the jobs that have arrived and are waiting to run.
It will be prioritized by job priority.
Your program will need to read the input file, build a Job object for each job, then an
arrival JobEvent for the Job, and put the arrival into the first priority queue.
Next, your program will need to process each event in the first priority queue. If the highes-
priority event is a job arrival, the job will need to be extracted from the JobEvent and
added to your second priority queue.
If the highest-priority event is a job completion, its information will be written to the outut
file. Then the next job will need to be extracted from the second priority queue, and a job
completion JobEvent constructed for its completion time, and that JobEvent added to the
first priority queue.
Processing will continue as long as there are JobEvents in the first priority queue.



My output is the following:

Sample Schedule.txt Output File
JobID Start EndTime Arrival Priority RunTime
Job1 0 12 0 5 12
Job5 0 9 15 99 9
Job4 0 25 9 0 25
Job3 0 6 8 15 6
Job2 0 10 0 10 10
13 years ago
I need someone to explain the whole concept of read in a file and, say, split the words and store in an ArrayList, or some other way. I just don't know the file input part of this. If someone could give me a small example on how to use it in my situation, I'd really appreciate it.
13 years ago
I am asked to write a program to read from a text file and display nonduplicate words in ascending order. The text file is passed as a command-line argument. Basically, I've managed to write a program to read a predefined String and display all nonduplicates. All is left to do is to read from a file. This is something I am not able to comprehend. Thanks a lot. Here is my code:

13 years ago