-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIOAssignmentEasy.java
More file actions
84 lines (73 loc) · 2.3 KB
/
IOAssignmentEasy.java
File metadata and controls
84 lines (73 loc) · 2.3 KB
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
import java.util.ArrayList;
import java.util.Scanner;
public class IOAssignmentEasy {
static ArrayList<Integer> listA = new ArrayList<Integer>();
static ArrayList<Integer> listB = new ArrayList<Integer>();
static ArrayList<Integer> listC = new ArrayList<Integer>();
static int[][] arr = new int[3][3];
final static int FINISH = 4200;
static int aCount = 1, bCount = 1, cCount = 1;
static int waitTime = 0;
private static Scanner keyboard;
public static void main(String ...strings){
addJob('A', 30, 50, 2);
addJob('B', 25, 75, 3);
addJob('C', 50, 100, 1);
keyboard = new Scanner(System.in);
System.out.println("Which question: a or b");
char c = keyboard.nextLine().charAt(0);
for(int time=1; time < FINISH; time++){
for(int j=0; j < arr.length; j++){
if(time % arr[j][2] == 0){
switch(arr[j][0]){
case 'A':
listA.add(arr[j][2]); break;
case 'B':
listB.add(arr[j][2]); break;
case 'C':
listC.add(arr[j][2]); break;
default:
System.out.println("SMTH WRONG"); System.exit(-1);
}
}
}
if(c == 'a' || c == 'A')
Q1(time);
else if(c == 'b' || c == 'B')
Q2(time);
else{
System.out.println("Wrong entry! Run again!");
System.exit(-1);
}
if(waitTime > 0) waitTime--;
}
}
public static void Q1(int time){
if(waitTime == 0){ //Only it is available
if(!listA.isEmpty()){
listA.remove(0); waitTime = 30; System.out.println("A"+(aCount++) + " : "+ time);
}else if(!listB.isEmpty()){
listB.remove(0); waitTime = 25; System.out.println("B"+(bCount++) + " : "+ time);
}else if(!listC.isEmpty()){
listC.remove(0); waitTime = 50; System.out.println("C"+(cCount++) + " : "+ time);
}
}
}
public static void Q2(int time){
if(waitTime == 0){ //Only it is available
if(!listC.isEmpty()){
listC.remove(0); waitTime = 50; System.out.println("C"+(cCount++) + " : "+ time);
}else if(!listA.isEmpty()){
listA.remove(0); waitTime = 30; System.out.println("A"+(aCount++) + " : "+ time);
}else if(!listB.isEmpty()){
listB.remove(0); waitTime = 25; System.out.println("B"+(bCount++) + " : "+ time);
}
}
}
public static void addJob(char c, int jobtime , int requesttime, int w){
int where = w-1;
arr[where][0] = c;
arr[where][1] = jobtime;
arr[where][2] = requesttime;
}
}