Skip to content

Commit 4de335b

Browse files
committed
Employee salary updating program with enum constants
1 parent 4f61709 commit 4de335b

14 files changed

+470
-0
lines changed

src/com/lab/dec_26/Test1.java

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.lab.dec_26;
2+
3+
public class Test1
4+
{
5+
public static void main(String args[])
6+
{
7+
{
8+
new Thread()
9+
{
10+
@SuppressWarnings("unused")
11+
public void run()
12+
{
13+
for(int i=1;i<=(3^5);i++)
14+
{
15+
System.out.println("Enjoy Your NewPlatForm..."+i);
16+
break;
17+
}
18+
}
19+
}.start();
20+
21+
new Thread()
22+
{
23+
public void run()
24+
{
25+
for(int i=1;i<=(3^5);i++)// 3 XOR 5 = 6
26+
{
27+
28+
if(i==(3^4))//3 XOR 4 = 7
29+
System.out.println("Experience this NewPlatForm..."+i);
30+
}
31+
}
32+
}.start();
33+
34+
}
35+
}
36+
}
37+
38+

src/com/lab/dec_26/Test2.java

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.lab.dec_26;
2+
3+
public class Test2
4+
{
5+
public static void main(String args[])
6+
{
7+
Runnable r1=new Runnable()
8+
{
9+
public void run()
10+
{
11+
System.out.println("How about your NewPlatForm?");
12+
}
13+
};
14+
15+
Runnable r2=new Runnable()
16+
{
17+
public void run()
18+
{
19+
System.out.println("Are you Enjoying NewPlatform?");
20+
}
21+
};
22+
Thread t1=new Thread(r1);
23+
Thread t2=new Thread(r2);
24+
25+
t1.start();
26+
t2.start();
27+
}
28+
}
29+
/*
30+
* Output
31+
* How about your NewPlatForm?
32+
* Are you Enjoying NewPlatform?
33+
*/
34+

src/com/lab/dec_26/Test3.java

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.lab.dec_26;
2+
3+
class Test31 extends Thread
4+
{
5+
public void run()
6+
{
7+
for(int i=0; i<=3; i++)
8+
{
9+
System.out.println("Hello Welcome here.."+i);
10+
}
11+
}
12+
}
13+
class Test3
14+
{
15+
public static void main(String[] args)
16+
{
17+
Test31 t = new Test31();
18+
t.start();
19+
@SuppressWarnings("unused")
20+
Test31 t2= new Test31();
21+
t.start(); // IlligalThreadStateException [ Thread can not be restart ]
22+
}
23+
}

src/com/lab/dec_26/Test4.java

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.lab.dec_26;
2+
3+
public class Test4
4+
{
5+
6+
public static void main(String args[])
7+
{
8+
{
9+
new Thread()
10+
{
11+
@SuppressWarnings("unused")
12+
public void run()
13+
{
14+
for(int i=1;i<=(3^5);i++)
15+
{
16+
System.out.println("Enjoy Your NewPlatForm..."+i);
17+
break;
18+
}
19+
}
20+
}.start();
21+
22+
new Thread()
23+
{
24+
public void run()
25+
{
26+
for(int i=1;i<=(3^5);i++)
27+
{
28+
int n=10;
29+
if(i==(n/=n/=2))
30+
System.out.println("Experience this NewPlatForm..."+i);
31+
}
32+
}
33+
}.start();
34+
35+
}
36+
}
37+
}
38+
39+
/*
40+
Enjoy Your NewPlatForm...1
41+
Experience this NewPlatForm...2
42+
*/

src/com/lab/dec_26/Test5.java

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.lab.dec_26;
2+
3+
public class Test5
4+
{
5+
/*
6+
wait(), notify() & notifyAll() are methods of which class or interface?
7+
8+
A)Thread class
9+
B)Runnable interface
10+
C)Object
11+
D)None
12+
13+
=> wait(), notify() & notifyAll()
14+
This three methods are the methods of object class
15+
because wait notify and notifyAll methods work on
16+
synchronized block which is internally working on
17+
object lock that is located in object class
18+
*/
19+
20+
21+
}

src/com/lab/dec_26/Test6.java

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.lab.dec_26;
2+
3+
public class Test6
4+
{
5+
/*
6+
7+
What are valid statements for yield method?
8+
=> yield()
9+
method when called on thread gives a hint to the thread scheduler that
10+
the current thread is willing to yield its current use of processor.
11+
The thread scheduler is free to ignore this hint.
12+
13+
yield() method stops thread for unpredictable time.
14+
15+
yield() is a static method, hence calling Thread.yield()
16+
causes currently executing thread to yield.
17+
18+
19+
*/
20+
}

src/com/lab/dec_26/Test7.java

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.lab.dec_26;
2+
3+
class NewPlatForm6 implements Runnable
4+
{
5+
public void run()
6+
{
7+
System.out.printf("%d", 3);
8+
}
9+
}
10+
11+
public class Test7
12+
{
13+
public static void main(String[] args) throws InterruptedException
14+
{
15+
Thread thread = new Thread(new NewPlatForm6());
16+
thread.start();
17+
System.out.printf("%d", 1);
18+
thread.join();
19+
System.out.printf("%d", 2);
20+
}
21+
}
22+
23+

src/com/lab/dec_26/Test8.java

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.lab.dec_26;
2+
3+
4+
class CheckingMyDaemonThread extends Thread
5+
{
6+
public void run()
7+
{
8+
if (Thread.currentThread().isDaemon())
9+
{
10+
System.out.println("I am daemon thread and I am working");
11+
}
12+
else
13+
{
14+
System.out.println("I am user thread and I am working");
15+
}
16+
}
17+
}
18+
public class Test8
19+
{
20+
public static void main(String[] args)
21+
{
22+
CheckingMyDaemonThread t1= new CheckingMyDaemonThread();
23+
CheckingMyDaemonThread t2= new CheckingMyDaemonThread();
24+
CheckingMyDaemonThread t3= new CheckingMyDaemonThread();
25+
t1.start();
26+
t2.start();
27+
t3.start();
28+
t2.setDaemon(true); // IllegalThreadStateException
29+
// We are setting thread as daemon after its execution
30+
}
31+
}
32+

src/com/lab/dec_26/Test9.java

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.lab.dec_26;
2+
3+
class TickTock
4+
{
5+
int count;
6+
public synchronized void increment()
7+
{
8+
count++;
9+
}
10+
}
11+
12+
public class Test9
13+
{
14+
public static void main(String[] args) throws Exception
15+
{
16+
TickTock tt = new TickTock();
17+
Thread t1 = new Thread(new Runnable()
18+
{
19+
public void run()
20+
{
21+
for (int i = 0; i < 100000; i++) {
22+
tt.increment();
23+
}
24+
}
25+
});
26+
Thread t2 = new Thread(new Runnable()
27+
{
28+
public void run()
29+
{
30+
for (int i = 0; i < 100000; i++) {
31+
tt.increment();
32+
}
33+
}
34+
});
35+
t1.start();
36+
t2.start();
37+
t1.join();
38+
t2.join();
39+
System.out.println("Count : " + tt.count);
40+
}
41+
}

src/com/lab/dec_27/Clerk.java

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.lab.dec_27;
2+
3+
public class Clerk extends Employee
4+
{
5+
6+
private int speed;
7+
private int accuracy;
8+
private int extraGiven;
9+
10+
public Clerk()
11+
{
12+
super();
13+
}
14+
15+
public Clerk(String name, int employeeId, double salary, int speed, int accuracy)
16+
{
17+
super(name, employeeId, salary);
18+
this.speed = speed;
19+
this.accuracy = accuracy;
20+
}
21+
22+
public int getSpeed()
23+
{
24+
return speed;
25+
}
26+
27+
public void setSpeed(int speed)
28+
{
29+
this.speed = speed;
30+
System.out.println(getName()+" speed updated to "+ this.speed);
31+
if(extraGiven<2)
32+
{
33+
this.setSalary(super.getSalary());
34+
extraGiven++;
35+
}
36+
}
37+
38+
public int getAccuracy()
39+
{
40+
return accuracy;
41+
}
42+
43+
public void setAccuracy(int accuracy)
44+
{
45+
this.accuracy = accuracy;
46+
if(extraGiven<2)
47+
{
48+
this.setSalary(super.getSalary());
49+
extraGiven++;
50+
}
51+
}
52+
53+
public void setSalary(double salary)
54+
{
55+
if(speed > 70 && accuracy > 80)
56+
super.setSalary(salary+1000);
57+
else
58+
super.setSalary(salary);
59+
}
60+
61+
}
62+
63+

0 commit comments

Comments
 (0)