Class Toilet

java.lang.Object
  |
  +--Toilet
Direct Known Subclasses:
AutoToilet

public class Toilet
extends java.lang.Object

This class approximates the standard interface to a physical toilet. The current implementation is a stub that mostly just prints stuff. We could replace it later with a more detailed implementation that manipulates the chain, the siphon jet, the ball float, the filler valve, etc. All of these would be handled with private methods and variables, because the user shouldn't have to know how the toilet works in order to use it.


Field Summary
private static float CLOG_PROBABILITY
          Probability that the toilet will clog and overflow if you try to flush TrashWaste.
protected  Waste contents
          Whatever's in the toilet.
private static java.util.Random random
           
protected  boolean seatup
          True iff the seat is up.
 
Constructor Summary
Toilet()
           
 
Method Summary
 void deposit(Waste w)
          Place something in the toilet.
 void flush()
          Make the contents of the toilet (if any) go away.
 boolean isYucky()
          Does the toilet need flushing?
static void main(java.lang.String[] args)
          This isn't necessarily the real main program, but it will be run if we type "java Toilet", so it is a good way to test the Toilet class.
 void raiseSeat(boolean b)
          Change the seat position.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

contents

protected Waste contents
Whatever's in the toilet.


seatup

protected boolean seatup
True iff the seat is up. Can be changed but isn't really used yet.


CLOG_PROBABILITY

private static final float CLOG_PROBABILITY
Probability that the toilet will clog and overflow if you try to flush TrashWaste. This is a static field, so it is shared by all toilets - it cannot vary from toilet to toilet. It is also a final field, i.e., a constant that can't be changed or overridden.

See Also:
Constant Field Values

random

private static java.util.Random random
Constructor Detail

Toilet

public Toilet()
Method Detail

deposit

public void deposit(Waste w)
Place something in the toilet.

Parameters:
w - The waste to deposit.

isYucky

public boolean isYucky()
Does the toilet need flushing?

Returns:
true if it does, false otherwise.

flush

public void flush()
           throws FloatingOverflowException
Make the contents of the toilet (if any) go away.

Throws:
FloatingOverflowException - If the toilet happened to clog. In this case it needs to be reflushed (after you clean up the bathroom), although it might clog again.

raiseSeat

public void raiseSeat(boolean b)
Change the seat position.

Parameters:
b - true to raise it, false to lower it.

main

public static void main(java.lang.String[] args)
                 throws FloatingOverflowException
This isn't necessarily the real main program, but it will be run if we type "java Toilet", so it is a good way to test the Toilet class. If the toilet overflows, we will crash with a FloatingOverflowException; the method's signature warns about this, as required.

FloatingOverflowException