Question
For today's lab we will be completing Exercise P9.5 from the book. IMPORTANT!! All of your method/class names need to match what is shown in
For today's lab we will be completing Exercise P9.5 from the book.
IMPORTANT!! All of your method/class names need to match what is shown in this document. This is the public interface of your class. The classes and methods you need to implement are as follows:
Circuit single method getResistance. Note that this is simply an empty circuit with no resistors, and therefore the resistance is always 0 for objects of this class. This is the parent class.
Resistor subclass of Circuit. Represents a single resistor. Needs to override the getResistance method from the superclass Circuit. To compute the value of the Resistor object you simply return the resistance value.
Serial subclass of Circuit. Contains an ArrayList
Parallel subclass of Circuit. Contains an ArrayList
Choice 1: You should add multiple circuits to the CircuitDemo.java file to verify that your program works as expected. Take screen-shots or capture the output text and include this in your project folder. Sample output from a working project using the given CircuitDemo.java file is shown below.
Combined resistance: 75.0
Expected: 75.0
public class CircuitDemo
{ /**
method that implements tests for Circuit class and sublclasses
@param args - Not Used.
*/
public static void main(String[] args)
{
Parallel circuit1 = new Parallel();
circuit1.add(new Resistor(100));
Serial circuit2 = new Serial();
circuit2.add(new Resistor(100));
circuit2.add(new Resistor(200));
circuit1.add(circuit2);
System.out.println("Combined resistance: " + circuit1.getResistance());
System.out.println("Expected: 75.0");
}
}
public class CircuitTester01
{
public static void main(String[] args)
{
Serial c1 = new Serial();
c1.add(new Resistor(100));
c1.add(new Resistor(200));
c1.add(new Resistor(150));
System.out.println("c1 total R = " + c1.getResistance());
Parallel c2 = new Parallel();
c2.add(new Resistor(100));
c2.add(new Resistor(100));
c2.add(new Resistor(100));
System.out.println("c2 total R = " + c2.getResistance());
Serial c3 = new Serial();
c3.add(c1);
c3.add(c2);
System.out.println("c3 total R = " + c3.getResistance());
Parallel c4 = new Parallel();
c4.add(c1);
c4.add(c2);
System.out.println("c4 total R = " + c4.getResistance());
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started