Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 instance variable. Resistance is computed by the formula given above. Must override inherited getResistance method.

Parallel subclass of Circuit. Contains an ArrayList instance variable. Resistance is computed by the formula given above. Must override inherited getResistance method.

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Sham Navathe

4th Edition

0321122267, 978-0321122261

Students also viewed these Databases questions

Question

Write short notes on Interviews.

Answered: 1 week ago

Question

Define induction and what are its objectives ?

Answered: 1 week ago

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago