Repository navigation
Expand file tree
/
Copy pathtest.java
More file actions
266 lines (223 loc) · 4.81 KB
/
Copy pathtest.java
File metadata and controls
266 lines (223 loc) · 4.81 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
package reid;
import java.util.Random;
import java.io.*;
interface SharedConstants {
int NO = 0;
int YES = 1;
int MAYBE = 2;
int LATER = 3;
int SOON = 4;
int NEVER = 5;
}
class Question implements SharedConstants {
Random rand = new Random();
int ask() {
int prob = (int)(100 * rand.nextDouble());
if (prob < 30)
return NO;
else if (prob < 60)
return YES;
else if (prob < 75)
return LATER;
else if (prob < 98)
return SOON;
else
return NEVER;
}
}
class AskMe implements SharedConstants {
static void answer(int result) {
switch(result){
case NO:
System.out.println("NO");
break;
case YES:
System.out.println("YES");
break;
case MAYBE:
System.out.println("MAYBE");
break;
case LATER:
System.out.println("LATER");
break;
case SOON:
System.out.println("SOON");
break;
case NEVER:
System.out.println("NEVER");
break;
}
}
}
/*
interface Callback {
void callback(int param);
}
class Client implements Callback {
public void callback(int param) {
System.out.println("callback: " + param);
}
void nonIfaceMeth() {
System.out.println("nonIfaceMeth");
}
}
class AnotherClient implements Callback {
public void callback(int param) {
System.out.println("Another version of callback");
System.out.println("param squared is " + (param*param));
}
}
*/
class NewThread implements Runnable {
String name;
Thread t;
NewThread(String threadname) {
name = threadname;
t = new Thread(this, name);
System.out.println("New Thread: " + t);
t.start();
}
public void run() {
try {
for (int i=5; i>0; i--) {
System.out.println(name + ": " + i);
Thread.sleep(1000);
}
}catch(InterruptedException e) {
System.out.println(name + "Interrupted");
}
System.out.println(name + " exiting.");
}
}
class Clicker implements Runnable {
Thread t;
int click = 0;
private volatile boolean running = true;
public Clicker(int p){
t = new Thread(this);
t.setPriority(p);
}
public void run() {
while(running) {
click++;
}
}
public void start() {
t.start();
}
public void stop() {
running = false;
}
}
public class test {
public static void main(String[] args) throws IOException{
//Callback cb = new Client();
//cb.callback(11);
/*
Callback cb = new Client();
AnotherClient ob = new AnotherClient();
cb.callback(11);
cb = ob;
cb.callback(11);*/
/*
Question q = new Question();
AskMe.answer(q.ask());
AskMe.answer(q.ask());
AskMe.answer(q.ask());
AskMe.answer(q.ask());*/
/*
new NewThread("One");
new NewThread("Two");
new NewThread("Three");
try {
Thread.sleep(10000);
}catch(InterruptedException e) {
System.out.println("Main thread Interrupted");
}
System.out.println("Main thread exiting.");*/
/*
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
Clicker hi = new Clicker(Thread.NORM_PRIORITY + 2);
Clicker lo = new Clicker(Thread.NORM_PRIORITY - 2);
lo.start();
hi.start();
try {
Thread.sleep(10000);
}catch(InterruptedException e) {
System.out.println("Main thread Interrupted.");
}
lo.stop();
hi.stop();
try {
lo.t.join();
hi.t.join();
}catch(InterruptedException e) {
System.out.println("InterruptedException caught.");
}
System.out.println("Low-priority thread: " + lo.click);
System.out.println("High-priority thread: " + hi.click);*/
/*
char c;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter characters, 'q' to quit.");
//read characters
do {
c = (char)br.read();
System.out.println(c);
}while(c != 'q');*/
/*
String str;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter lines of text.");
System.out.println("Enter 'stop' to quit.");
do {
str = br.readLine();
System.out.println(str);
}while(!str.equals("stop"));*/
/*
int b;
b = 'A';
System.out.write(b);
System.out.write('\n');*/
/*
PrintWriter pw = new PrintWriter(System.out, true);
pw.println("This is a string.");
int i = 7;
double d = 4.5e-7;
pw.println(i);
pw.println(d);*/
int i;
FileInputStream fin;
FileOutputStream fout;
try {
//open input file
try {
fin = new FileInputStream(args[0]);
}catch(FileNotFoundException e) {
System.out.println("Input File Not Found");
return;
}
//open output file
try {
fout = new FileOutputStream(args[1]);
}catch(FileNotFoundException e) {
System.out.println("Error Opening Output File");
return;
}
}catch(ArrayIndexOutOfBoundsException e) {
System.out.println("Usage: CopyFile From To");
return;
}
try {
do {
i = fin.read();
if(i != -1)
fout.write(i);
}while(i != -1);
}catch(IOException e) {
System.out.println("File Error");
}
fin.close();
fout.close();
}
}