Series.java


Below is the syntax highlighted version of Series.java from §3.6 Case Study: Purple America.


/******************************************************************************
 *  Compilation:  javac Series.java
 *  Execution:    java Series
 *
 ******************************************************************************/

public class Series extends Circuit {
    private Circuit a;
    private Circuit b;

    public Series(Circuit a, Circuit b) {
        this.a = a;
        this.b = b;
    }
        
    public double getResistance() {
        return a.getResistance() + b.getResistance();
    }
        
    public double getPotentialDiff() {
        return a.getPotentialDiff() + b.getPotentialDiff();
    }
        
    public void applyPotentialDiff(double V) {
        double current = V / getResistance();
        a.applyPotentialDiff(current * a.getResistance());
        b.applyPotentialDiff(current * b.getResistance());
    }
}


Copyright © 2000–2017, Robert Sedgewick and Kevin Wayne.
Last updated: Fri Oct 20 14:12:12 EDT 2017.