ThreadGroup problem
This is an assignment, so I am not looking for anyone to do the coding for me, but I am stuck and any guidance would be appreciated. I have modified existing code to achieve the first part of the assignment and it works fine. The next step is to:
Add a ThreadGroup object called eventgroup and use it the set the maximum priority for all the event threads. Set the priority for each event thread to that maximum.
I can not get a ThreadGroup to even compile and have tried several different things.
The working code is
abstractclass Eventextends Thread{
privatelong delay;
public Event(long delayTime){
delay = delayTime;
start();
}
publicvoid run(){
ThreadGroup t =new ThreadGroup("eventGroup");
try{
sleep(delay);
}catch(InterruptedException e){
System.out.println(
"InterruptedException = " + e);
}
action();
if(description().length()>0)
System.out.println(description());
System.out.println(getThreadGroup());
}
abstractpublicvoid action();
abstractpublic String description();
}
and
class GreenhouseControls{
privateboolean light =false;
privateboolean water =false;
private String thermostat ="Day";
privateclass LightOnextends Event{
public LightOn(long delayTime){
super(delayTime);
}
publicvoid action(){
light =true;
}
public String description(){
return"Light is on";
}
}
privateclass LightOffextends Event{
public LightOff(long delayTime){
super(delayTime);
}
publicvoid action(){
light =false;
}
public String description(){
return"Light is off";
}
}
privateclass WaterOnextends Event{
public WaterOn(long delayTime){
super(delayTime);
}
publicvoid action(){
water =true;
}
public String description(){
return"Greenhouse water is on";
}
}
privateclass WaterOffextends Event{
public WaterOff(long delayTime){
super(delayTime);
}
publicvoid action(){
water =false;
}
public String description(){
return"Greenhouse water is off";
}
}
privateclass ThermostatNightextends Event{
public ThermostatNight(long delayTime){
super(delayTime);
}
publicvoid action(){
thermostat ="Night";
}
public String description(){
return"Thermostat on night setting";
}
}
privateclass ThermostatDayextends Event{
public ThermostatDay(long delayTime){
super(delayTime);
}
publicvoid action(){
thermostat ="Day";
}
public String description(){
return"Thermostat on day setting";
}
}
privateclass Bellextends Event{
public Bell(long delayTime){
super(delayTime);
}
publicvoid action(){
System.out.println("Bing!");
}
public String description(){
return"";
}
}
privateclass Finishextends Event{
public Finish(long delayTime){
super(delayTime);
}
publicvoid action(){
System.out.println("Restarting System");
}
public String description(){
return"Terminating";
}
}
class Restartextends Event{
public Restart(long delayTime){
super(delayTime);
}
publicvoid action(){
new Bell(0);
new ThermostatNight(100);
new LightOn(200);
new LightOff(300);
new WaterOn(800);
new WaterOff(900);
new ThermostatDay(1000);
new Finish(2000);
}
public String description(){
return"";
}
}
}
publicclass Tme3Question1{
publicstaticvoid main(String[] args){
GreenhouseControls gc =new GreenhouseControls();
gc.new Restart(1000);
}
}/* Output:
Bing!
Thermostat on night setting
Light is on
Light is off
Greenhouse water is on
Greenhouse water is off
Thermostat on day setting
Restarting system
Terminating
*///:~
I have been stuck on this for over a week and tried everything I can think of. Any guidance would be greatly appreciated.

