Hello,

I have a Java assignment and I am stuck at this point. Below is the requirement:

1. Create a WindowMalfunction and PowerOut Events to simulate problems that may occur in a GreenhouseControls. The event should set the following boolean variables as appropriate in GreenhouseControls:

windowok = false;
poweron = false;

After setting the variables, WindowMalfunction or PowerOut should throw an exception specifying the faulty condition. Create a ControllerException class that extends Exception for this purpose.

2. If an exception is thrown from WindowMalfunction or PowerOut, the Controller catches the exception, then initiates an emergency shutdown with an appropriate message. Add a method to Controller called shutdown, and override this method in GreenhouseControls to accomplish the shutdown.

Here is my code:

 
import java.io.*;
import java.util.Calendar;
import java.util.Scanner;
 
import tme3.*;
 
public class GreenhouseControls extends Controller {
  private boolean windowok = false;
  private boolean poweron = false;
  private boolean fans=false;	
  private boolean light = false;
  private boolean water = false;
  private String thermostat = "Day";
  private String eventsFile = "examples1.txt";
 
 
 public class WindowMalfunction extends Event{
	 ControllerException newExcep= new ControllerException("Error:");
	 public WindowMalfunction(long delayTime) { super(delayTime); }
	    public void action() throws ControllerException {
 
 
	    }
}
 
 
  public class FansOn extends Event {
	    public FansOn(long delayTime) { super(delayTime); }
	    public void action() {
	      // Put hardware control code here to
	      // physically turn on the fan.
	      fans = true;
	    }
	    public String toString() { return "Fans are on"; }
}
 
public class FansOff extends Event {
	    public FansOff(long delayTime) { super(delayTime); }
	    public void action() {
	      // Put hardware control code here to
	      // physically turn off the fan.
	      fans = false;
	    }
	    public String toString() { return "Fans are off"; }
}
 
 
  public class LightOn extends Event {
    public LightOn(long delayTime) { super(delayTime); }
    public void action() {
      // Put hardware control code here to
      // physically turn on the light.
      light = true;
    }
    public String toString() { return "Light is on"; }
  }
  public class LightOff extends Event {
    public LightOff(long delayTime) { super(delayTime); }
    public void action() {
      // Put hardware control code here to
      // physically turn off the light.
      light = false;
    }
    public String toString() { return "Light is off"; }
  }
  public class WaterOn extends Event {
    public WaterOn(long delayTime) { super(delayTime); }
    public void action() {
      // Put hardware control code here.
      water = true;
    }
    public String toString() {
      return "Greenhouse water is on";
    }
  }
  public class WaterOff extends Event {
    public WaterOff(long delayTime) { super(delayTime); }
    public void action() {
      // Put hardware control code here.
      water = false;
    }
    public String toString() {
      return "Greenhouse water is off";
    }
  }
  public class ThermostatNight extends Event {
    public ThermostatNight(long delayTime) {
      super(delayTime);
    }
    public void action() {
      // Put hardware control code here.
      thermostat = "Night";
    }
    public String toString() {
      return "Thermostat on night setting";
    }
  }
  public class ThermostatDay extends Event {
    public ThermostatDay(long delayTime) {
      super(delayTime);
    }
    public void action() {
      // Put hardware control code here.
      thermostat = "Day";
    }
    public String toString() {
      return "Thermostat on day setting";
    }
  }
  // An example of an action() that inserts a
  // new one of itself into the event list:
  public class Bell extends Event {
    public Bell(long delayTime) { super(delayTime); }
    public void action() {
	// Bell rings
    addEvent(new Bell(2000));
    addEvent(new Bell(2000));
    addEvent(new Bell(2000));
    addEvent(new Bell(2000));
    addEvent(new Bell(2000));
 
  }
 
    public String toString() { return "Bing!"; }
  }
 
  public class Restart extends Event {
    public Restart(long delayTime, String filename) {
      super(delayTime);
      eventsFile = filename;
 
    }
 
    public void action() {
 
    	Scanner scan= null;
    	try{
    		scan= new Scanner(new java.io.File(eventsFile));
    		while(scan.hasNextLine()){
 
    			final String line=scan.nextLine();
 
    			final Scanner lineScanner= new Scanner(line);
    		}
    	}catch(FileNotFoundException e){
    		throw new RuntimeException("Evenetsfile"+eventsFile+" couldn't be found");
    	}
 
    	finally{
    		if(null!=scan){
    			scan.close();
    		}
    	}
    }
    public String toString() {
      return "Restarting system";
    }
  }
 public class Terminate extends Event {
    public Terminate(long delayTime) { super(delayTime); }
    public void action() { System.exit(0); }
    public String toString() { return "Terminating";  }
  }
 
 
  public static void printUsage() {
    System.out.println("Correct format: ");
    System.out.println("  java GreenhouseControls -f <filename>, or");
    System.out.println("  java GreenhouseControls -d dump.out");
  }
 
//---------------------------------------------------------
    public static void main(String[] args) throws ControllerException {
	try {
	    String option = args[0];
	    String filename = args[1];
 
	    if ( !(option.equals("-f")) && !(option.equals("-d")) ) {
		System.out.println("Invalid option");
		printUsage();
	    }
 
	    GreenhouseControls gc = new GreenhouseControls();
 
	    if (option.equals("-f"))  {
		gc.addEvent(gc.new Restart(0,filename));
	    }
 
	    gc.run();
	}
	catch (ArrayIndexOutOfBoundsException e) {
	    System.out.println("Invalid number of parameters");
	    printUsage();
	}
    }
 
} ///:~

Here is the rest:

package tme3;
 
public class ControllerException extends Exception{
 
	public ControllerException(String except){
 
		super(except);
	}
 
public String getMessage(){
 
	return super.getMessage();
}
public void shutdown(){
 
}
}

Need help to complete the rest of it. Any tip appreciated. There are also two other classes that are part of this code; if necessary I will post them. I realize it is too much code to review, that's why I haven't posted the rest of the code.

Thanks.