2009-01-30, 10:31 AM
Hello, I need some help in this.
I'm supposed to design a class hierarchy that can manage and resolve arbitrary resistive circuits of serial/parallel combinations. These classes in the hierarchy must be able to calculate the equivalent resistance and intensities in all parts of the circuit.
Here's what I have so far, but I don't know if I'm on the right track or not:
I'm not really sure if this answers the question or not and I'm really unsure about the usage of List, foreach and "in". This is due for today and it's driving me nuts.
Any help would be greatly appreciated.
I'm supposed to design a class hierarchy that can manage and resolve arbitrary resistive circuits of serial/parallel combinations. These classes in the hierarchy must be able to calculate the equivalent resistance and intensities in all parts of the circuit.
Here's what I have so far, but I don't know if I'm on the right track or not:
Code:
public class circuit{
public int resistance();
}
public class basicCircuit extends circuit {
string name;
int res;
//constructor
public basicCircuit (string name, int res)
{
this.name = name;
this.res = res;
}
//redefine or define resistance
public int resistance ()
{
return res; //resistance is constant, doesn't need to calculate anything.
}
}
public class serialCircuit extends circuit{
List<circuit> circuits;
//constructor
public serialCircuit(List<circuit> cir){
this.circuits = cir;
}
//define resistance
public int resistance()
{
int res = 0;
foreach (circuit c in circuits)
//the sum of all the resistances of its subcircuits
{ res= res + c.resistance(); }
return res;
}
}Any help would be greatly appreciated.


![[Image: serieske3.png]](http://img142.imageshack.us/img142/8052/serieske3.png)
![[Image: paralleltv9.png]](http://img104.imageshack.us/img104/3774/paralleltv9.png)
![[Image: combosp1.png]](http://img104.imageshack.us/img104/2460/combosp1.png)
At least I hope you understood what I tried to explain and such.