This is what I have to do:
1. Create the following exception hierarchy:
ReactorException extends Exception
TooHot extends ReactorException
TooCold extends ReactorException
2. Complete the implementation of Reactor.java
3. Add a try/catch block to the control loop in Console.java
4. Test
here is what I have:
import java.util.*;
public class Console {
private Scanner kbd = new Scanner(System.in);
private Reactor reactor = new Reactor();
public void controlLoop() {
while(true) {
// add a try/catch block here
System.out.print("-> ");
String cmmd = kbd.next();
if (cmmd.equals("quit")) break;
else if (cmmd.equals("dec")) reactor.dec(5);
else if (cmmd.equals("inc")) reactor.inc(15);
else System.out.println("unrecognized command: " + cmmd);
System.out.println("temperature = " + reactor.getTemp() + " degrees");
}
System.out.println("bye");
}
public static void main(String[] args) {
Console console = new Console();
console.controlLoop();
}
}
import java.util.*;
public class Console {
private Scanner kbd = new Scanner(System.in);
private Reactor reactor = new Reactor();
public void controlLoop() {
while(true) {
// add a try/catch block here
System.out.print("-> ");
String cmmd = kbd.next();
if (cmmd.equals("quit")) break;
else if (cmmd.equals("dec")) reactor.dec(5);
else if (cmmd.equals("inc")) reactor.inc(15);
else System.out.println("unrecognized command: " + cmmd);
System.out.println("temperature = " + reactor.getTemp() + " degrees");
}
System.out.println("bye");
}
public static void main(String[] args) {
Console console = new Console();
console.controlLoop();
}
}
I know I'm suppose to make a TooHot and TooCold class that extends ReactorExtension but I have no clue how.
Please help asap it's due today!!
Comments
:
: This is what I have to do:
:
: 1. Create the following exception hierarchy:
:
: ReactorException extends Exception
: TooHot extends ReactorException
: TooCold extends ReactorException
:
: 2. Complete the implementation of Reactor.java
:
: 3. Add a try/catch block to the control loop in Console.java
:
: 4. Test
:
: here is what I have:
:
: import java.util.*;
:
: public class Console {
: private Scanner kbd = new Scanner(System.in);
: private Reactor reactor = new Reactor();
: public void controlLoop() {
: while(true) {
: // add a try/catch block here
: System.out.print("-> ");
: String cmmd = kbd.next();
: if (cmmd.equals("quit")) break;
: else if (cmmd.equals("dec")) reactor.dec(5);
: else if (cmmd.equals("inc")) reactor.inc(15);
: else System.out.println("unrecognized command: " + cmmd);
: System.out.println("temperature = " + reactor.getTemp() + " degrees");
: }
: System.out.println("bye");
: }
:
: public static void main(String[] args) {
: Console console = new Console();
: console.controlLoop();
: }
: }
:
:
:
:
: import java.util.*;
:
: public class Console {
: private Scanner kbd = new Scanner(System.in);
: private Reactor reactor = new Reactor();
: public void controlLoop() {
: while(true) {
: // add a try/catch block here
: System.out.print("-> ");
: String cmmd = kbd.next();
: if (cmmd.equals("quit")) break;
: else if (cmmd.equals("dec")) reactor.dec(5);
: else if (cmmd.equals("inc")) reactor.inc(15);
: else System.out.println("unrecognized command: " + cmmd);
: System.out.println("temperature = " + reactor.getTemp() + " degrees");
: }
: System.out.println("bye");
: }
:
: public static void main(String[] args) {
: Console console = new Console();
: console.controlLoop();
: }
: }
:
: I know I'm suppose to make a TooHot and TooCold class that extends ReactorExtension but I have no clue how. Please help asap it's due today!!
:
:
Create an new class "ReactorExtension" which extends "Exception". Then you can create the classes TooHot and TooCold.
: :
: : This is what I have to do:
: :
: : 1. Create the following exception hierarchy:
: :
: : ReactorException extends Exception
: : TooHot extends ReactorException
: : TooCold extends ReactorException
: :
: : 2. Complete the implementation of Reactor.java
: :
: : 3. Add a try/catch block to the control loop in Console.java
: :
: : 4. Test
: :
: : here is what I have:
: :
: : import java.util.*;
: :
: : public class Console {
: : private Scanner kbd = new Scanner(System.in);
: : private Reactor reactor = new Reactor();
: : public void controlLoop() {
: : while(true) {
: : // add a try/catch block here
: : System.out.print("-> ");
: : String cmmd = kbd.next();
: : if (cmmd.equals("quit")) break;
: : else if (cmmd.equals("dec")) reactor.dec(5);
: : else if (cmmd.equals("inc")) reactor.inc(15);
: : else System.out.println("unrecognized command: " + cmmd);
: : System.out.println("temperature = " + reactor.getTemp() + " degrees");
: : }
: : System.out.println("bye");
: : }
: :
: : public static void main(String[] args) {
: : Console console = new Console();
: : console.controlLoop();
: : }
: : }
: :
: :
: :
: :
: : import java.util.*;
: :
: : public class Console {
: : private Scanner kbd = new Scanner(System.in);
: : private Reactor reactor = new Reactor();
: : public void controlLoop() {
: : while(true) {
: : // add a try/catch block here
: : System.out.print("-> ");
: : String cmmd = kbd.next();
: : if (cmmd.equals("quit")) break;
: : else if (cmmd.equals("dec")) reactor.dec(5);
: : else if (cmmd.equals("inc")) reactor.inc(15);
: : else System.out.println("unrecognized command: " + cmmd);
: : System.out.println("temperature = " + reactor.getTemp() + " degrees");
: : }
: : System.out.println("bye");
: : }
: :
: : public static void main(String[] args) {
: : Console console = new Console();
: : console.controlLoop();
: : }
: : }
: :
: : I know I'm suppose to make a TooHot and TooCold class that extends ReactorExtension but I have no clue how. Please help asap it's due today!!
: :
: :
: Create an new class "ReactorExtension" which extends "Exception". Then you can create the classes TooHot and TooCold.
:
What do I put in the TooHot and TooCold classes
: : :
: : : This is what I have to do:
: : :
: : : 1. Create the following exception hierarchy:
: : :
: : : ReactorException extends Exception
: : : TooHot extends ReactorException
: : : TooCold extends ReactorException
: : :
: : : 2. Complete the implementation of Reactor.java
: : :
: : : 3. Add a try/catch block to the control loop in Console.java
: : :
: : : 4. Test
: : :
: : : here is what I have:
: : :
: : : import java.util.*;
: : :
: : : public class Console {
: : : private Scanner kbd = new Scanner(System.in);
: : : private Reactor reactor = new Reactor();
: : : public void controlLoop() {
: : : while(true) {
: : : // add a try/catch block here
: : : System.out.print("-> ");
: : : String cmmd = kbd.next();
: : : if (cmmd.equals("quit")) break;
: : : else if (cmmd.equals("dec")) reactor.dec(5);
: : : else if (cmmd.equals("inc")) reactor.inc(15);
: : : else System.out.println("unrecognized command: " + cmmd);
: : : System.out.println("temperature = " + reactor.getTemp() + " degrees");
: : : }
: : : System.out.println("bye");
: : : }
: : :
: : : public static void main(String[] args) {
: : : Console console = new Console();
: : : console.controlLoop();
: : : }
: : : }
: : :
: : :
: : :
: : :
: : : import java.util.*;
: : :
: : : public class Console {
: : : private Scanner kbd = new Scanner(System.in);
: : : private Reactor reactor = new Reactor();
: : : public void controlLoop() {
: : : while(true) {
: : : // add a try/catch block here
: : : System.out.print("-> ");
: : : String cmmd = kbd.next();
: : : if (cmmd.equals("quit")) break;
: : : else if (cmmd.equals("dec")) reactor.dec(5);
: : : else if (cmmd.equals("inc")) reactor.inc(15);
: : : else System.out.println("unrecognized command: " + cmmd);
: : : System.out.println("temperature = " + reactor.getTemp() + " degrees");
: : : }
: : : System.out.println("bye");
: : : }
: : :
: : : public static void main(String[] args) {
: : : Console console = new Console();
: : : console.controlLoop();
: : : }
: : : }
: : :
: : : I know I'm suppose to make a TooHot and TooCold class that extends ReactorExtension but I have no clue how. Please help asap it's due today!!
: : :
: : :
: : Create an new class "ReactorExtension" which extends "Exception". Then you can create the classes TooHot and TooCold.
: :
:
: What do I put in the TooHot and TooCold classes
:
:
You probably don't need to place anything in those classes. They are defined to allow programmers to create specialized catch blocks:
[code]
try
{
// Monitor reactor temperature
}
catch (TooCold)
{
// Apply heat
}
catch (TooHot)
{
// Remove heat
}
catch (Exception)
{
// Call engineer
}
[/code]