Question
must be in java: need help with corrected the code to have the outcom of 75.0 ]my code : // parent class public class Circuit
must be in java:
need help with corrected the code to have the outcom of 75.0
]my code :
// parent class public class Circuit { // single method // has no resistors therefore the resistance is always 0 public double getResistance() { return 0; } }
public class Resistor extends Circuit { // helps with t public double resistance; public Resistor(double r) { r = resistance; } // Needs to override the getResistance method from the superclass Circuit // compute the value of the Resistor object
public double getResistance() { return resistance; }
import java.util.ArrayList; public class Serial extends Circuit { // variable sum helps return double sum =0; // serial from below helps with -> serial.add public ArrayList
// is needfore for arrayList
import java.util.ArrayList; public class Parallel extends Circuit { // the sum below helps with the total in the getResistance method double sum=0; // instance variable public ArrayList
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"); } }
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