Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Java] Class Hierarchy Design
#1
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:

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;
    
}
}
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.
Reply


Messages In This Thread
[Java] Class Hierarchy Design - by Conciente - 2009-01-30, 10:31 AM
[Java] Class Hierarchy Design - by ShadowFusion - 2009-01-30, 12:01 PM
[Java] Class Hierarchy Design - by Nikkey - 2009-01-30, 12:22 PM
[Java] Class Hierarchy Design - by Conciente - 2009-01-30, 01:02 PM
[Java] Class Hierarchy Design - by Nikkey - 2009-01-30, 02:16 PM
[Java] Class Hierarchy Design - by Conciente - 2009-01-30, 04:34 PM
[Java] Class Hierarchy Design - by Nikkey - 2009-01-30, 06:39 PM
[Java] Class Hierarchy Design - by Stereo - 2009-01-30, 09:23 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)