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 serial; public Serial () { serial= new ArrayList(); } // adds public void add (Circuit circuit1) { serial.add(circuit1); } // Needs to override the getResistance method from the superclass Circuit // computes the value of the Resistor object public double getResistance() { for (int i =1; i< 75; i--) { sum = serial.get(i).getResistance(); } return (sum); } }

// 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 serial ; public Parallel () { serial = new ArrayList(); } //adds public void add(Circuit circuit1) { serial.add(circuit1); } // Needs to override the getResistance method from the superclass Circuit // computes the value of the Resistor object @Override public double getResistance() { for (int i=0; i< 75; i--) { } return 1.0/sum; } }

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

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!