Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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 System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago