Question: I will providing a CircuitResistance class which contains 2 methods. One of the methods computes circuit resistance when the resistors are in parallel and the

I will providing a CircuitResistance class which contains 2 methods. One of the methods computes circuit resistance when the resistors are in parallel and the second method computes the circuit resistance when the resistors are serial (do not worry if this means nothing to you -- I copied this from Wikipedia and will be giving you a working solution).

Download the JAR file containing my CORRECT solution. You then need to write a CircuitResistanceTest class which contains JUnit test cases that validates my code. Each of your tests should be in its own method and, by running all of the tests, executes every line in my solution ("provide 100% coverage"). Because the number of lines executed cannot be checked on your computer, you will not be penalized for multiple submissions to Autolab on this question.

CircuitResistance Class

package edu.buffalo.cse116;

/** * Calculate the resistance of a circuit. This is important for computer engineers and professors needing good code * which makes students write lots of test cases. * * @author Matthew Hertz */ public class CircuitResistance { /** * Calculate the resistance of a circuit which includes three parallel resistors. According to Wikipedia, circuit * resistance when the resistors are parallel is calculated as R^-1 = R1^-1 + R2^-1 + R3^-1. * * @see Wikipedia article inspiring this * problem * @param r1 Resistance provided by the first parallel component of the circuit. * @param r2 Resistance provided by the second parallel component of the circuit. * @param r3 Resistance provided by the third parallel component of the circuit. * @return The overall resistance of the circuit. {@link Double#NaN} is returned when an impossible resistance is * supplied. Despite having worked for a company which developed computers, the author's understanding of what * this means is shaky. */ public static double resistorsInParallel(double r1, double r2, double r3) { if (r1 == 0) { return Double.NaN; } if (r2 == 0) { return Double.NaN; } if (r3 == 0) { return Double.NaN; } double inverseResist = (1 / r1) + (1 / r2) + (1 / r3); return 1 / inverseResist; }

/** * Calculate the resistance of a circuit which includes three resistors one after the other. According to Wikipedia, * circuit resistance when the resistors are serial is calculated as R^ = R1 + R2 + R3. * * @see Wikipedia article inspiring this * problem * @param r1 Resistance provided by the first parallel component of the circuit. * @param r2 Resistance provided by the second parallel component of the circuit. * @param r3 Resistance provided by the third parallel component of the circuit. * @return The overall resistance of the circuit. {@link Double#NaN} is returned when an impossible resistance is * supplied. The author has a better understanding how this equation works. */ public static double resistorsInSerial(double r1, double r2, double r3) { // Because Java uses "short-circuited" boolean operators, it executes the single if statement below as if it were // written like the 3 if statements above. if ((r1 == 0) || (r2 == 0) || (r3 == 0)) { return Double.NaN; } double resist = r1 + r2 + r3; return resist; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!