-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput.java
90 lines (64 loc) · 1.47 KB
/
Input.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Queue;
import java.util.LinkedList;
public class Input
{ public Queue<Job> jobs;
public int count;
int min;
int max;
int total;
int n; // number of jobs
public Input()
{ jobs= new LinkedList<Job>();
count= 0;
min= 256;
max= 0;
total= 0;
n= (int)((Math.random()*(500 - 100) + 100)); }
public Job generateJob()
{ int id= count++;
int ecu= (int)((Math.random()*(512 - 16) + 16));
int jobSize= (int)((Math.random()*(256 - 16) + 16));
if(jobSize < min)
min= jobSize;
if(max < jobSize)
max= jobSize;
total += jobSize;
Job obj= new Job(id, ecu, jobSize);
return obj; }
public void generateInput()
{ File f= new File("Jobs.txt");
FileOutputStream fOut;
PrintWriter writer;
try
{ fOut = new FileOutputStream(f);
writer= new PrintWriter(fOut);
Job obj= null;
for(int i= 0; i < n; i++)
{ obj= generateJob();
writer.println(obj.jID + "\t" + obj.ECU + "\t" + obj.jobSize + "\n"); }
writer.close();
fOut.close(); }
catch (Exception e)
{ e.getMessage(); } }
public void fillJQueue()
{ File f= new File("Jobs.txt");
Scanner input;
try
{ input= new Scanner(f);
Job obj;
int id;
int ecu;
int size;
while(input.hasNext())
{ id= input.nextInt();
ecu= input.nextInt();
size= input.nextInt();
obj= new Job(id, ecu, size);
jobs.add(obj); }
input.close(); }
catch (Exception e)
{ e.getMessage(); } } }