CECS 277                                                  LAB ASSIGNMENT  #9
Assigned date: 5/8
Due date: 5/10

10 points

Problem 1 - 5 points

Given the main method below and its output:

public class TwoThreadsDemo {
public static void main (String[] args) {
new SimpleThread("CECS 277").start();
new SimpleThread("OOP in Java").start();
}
}

Output

0 OOP in Java
0 CECS 277
1 OOP in Java
2 OOP in Java
1 CECS 277
3 OOP in Java
4 OOP in Java
2 CECS 277
5 OOP in Java
3 CECS 277
4 CECS 277
5 CECS 277
6 OOP in Java
6 CECS 277
7 OOP in Java
7 CECS 277
8 CECS 277
8 OOP in Java
9 CECS 277
DONE! CECS 277
9 OOP in Java
DONE! OOP in Java

Implement the class SimpleThread.

Problem 2- 4 points

The class TaskThread performs some tasks and then periodically reports what percent of the task it has completed:

import java.util.*;
public class TaskThread implements Runnable {
private int taskNumber;

TaskThread(int number) {
taskNumber = number;
}
public void run() {
for (int i=0;i<=100;i+=20) {
// Perform some task ...
System.out.println("Task number: " + taskNumber
+ ", percent complete: " + i );
try {
Thread.sleep((int)(Math.random() * 1000));
}
catch (InterruptedException e)
{
}
}//end for
}//end main
}//end class

Write a main method to produce the following ouput by using only two threads:

Task number: 1, percent complete: 0
Task number: 0, percent complete: 0
Task number: 1, percent complete: 20
Task number: 0, percent complete: 20
Task number: 1, percent complete: 40
Task number: 1, percent complete: 60
Task number: 0, percent complete: 40
Task number: 0, percent complete: 60
Task number: 1, percent complete: 80
Task number: 1, percent complete: 100
Task number: 0, percent complete: 80
Task number: 2, percent complete: 0
Task number: 2, percent complete: 20
Task number: 0, percent complete: 100
Task number: 2, percent complete: 40
Task number: 3, percent complete: 0
Task number: 3, percent complete: 20
Task number: 3, percent complete: 40
Task number: 2, percent complete: 60
Task number: 3, percent complete: 60
Task number: 3, percent complete: 80
Task number: 2, percent complete: 80
Task number: 2, percent complete: 100
Task number: 3, percent complete: 100

Grading

Problem 3 - 1 point

Write a program that can dynamically change the font and the color of a message to be displayed on a panel. The message can be displayed in bold and italic at the same time, or can be displayed at the center of the panel. Use check boxes to select bold, italic or centered. User can select the font name or font size from combo boxes, or select a color from the radio buttons.

gui

Link to the problem 2 solution file.

GRADING