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–2022, Robert Sedgewick and Kevin Wayne.
Last updated: Thu Aug 11 10:27:28 EDT 2022.