2009-01-30, 09:23 PM
I think I'd stick to 2-element or basic resistors.
Eg.
class Resistor() {
int resistance;
int resistance() {
return resistance;
}
}
class serialResistor extends Resistor() {
Resistor[] resistors;
int resistance() {
resistance = 0;
for (i = 0; i < resistors.length; i++) {
resistance += resistors[i].resistance();
}
return resistance;
}
class parallelResistor extends Resistor() {
Resistor[] resistors;
int resistance() {
double invr = 0;
for (i = 0; i < resistors.length; i++) {
invr += 1/resistors[i];
}
return 1/invr;
}
}
I think that's what the question is asking for. A circuit would just be an instance of a series resistor, possibly with 1 element.
Eg.
class Resistor() {
int resistance;
int resistance() {
return resistance;
}
}
class serialResistor extends Resistor() {
Resistor[] resistors;
int resistance() {
resistance = 0;
for (i = 0; i < resistors.length; i++) {
resistance += resistors[i].resistance();
}
return resistance;
}
class parallelResistor extends Resistor() {
Resistor[] resistors;
int resistance() {
double invr = 0;
for (i = 0; i < resistors.length; i++) {
invr += 1/resistors[i];
}
return 1/invr;
}
}
I think that's what the question is asking for. A circuit would just be an instance of a series resistor, possibly with 1 element.

