• Post Reply Bookmark Topic Watch Topic
  • New Topic

class hierarchy problem with loop constructs!  RSS feed

 
Hugh Mclaughlin
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to design class hierarchy which has a super-class Pythagoras and two sub-classes (Vieta and Wallis), which can be used to produce estimates of PI, using either the method proposed by Vieta or that of Wallis. The only input by the user is a "number of terms"

Vieta's method:

2/Pi = SQRT(2)/2 *sqrt(2+sqrt(2))/2 *sqrt(2+sqrt(2+sqrt(2)))/2 etc etc


Wallis's method:

PI/2 = 2/1 * 2/3 * 4/3 * 4/5 etc

i know this requires a sort of loop construct but am having difficulty writing the methods for the two directions of the loop....here's my code can anyone help?


/ **************************************************
**/
/* */
/* PYTHAGORAS CLASS */
/* */
/ **************************************************
**/

class PythagorasClass {

//----------------------------FIELDS-----------------------------

private int numberOfTerms;
private int firstTerm;

//----------------------------CONSTRUCTORS-----------------------

/* Constructor */

public PythagorasClass (int numN, int fTerm) {
numberOfTerms = numN;
firstTerm = fTerm;
}

/ **************************************************
**/
/* */
/* VIETA CLASS */
/* */
/ **************************************************
**/


class VietaClass extends PythagorasClass {

//----------------------------FIELDS------------------------------

private static double sqrt;
private static double (sqrt + 2);
private double variable1 = 0;
private double variable2 = 0;

//---------------------------CONSTRUCTORS-------------------------

public VietaClass (int numN, int fTerm) {
super(numN, fTerm);

}

//--------------------------METHODS-------------------------------


/* Output terms method */

public void outputTerms() {
int loopParameter;
final int START_CONDITION = 0;

for(loopParameter = START_CONDITION;
loopParameter < numberOfTerms;loopParameter++)
System.out.print(WHAT TO PUT HERE?); <<<<<<<<<<
System.out.print("\n\n");
}

/ **************************************************
**/
/* */
/* WALLIS CLASS */
/* */
/ **************************************************
**/


class WallisClass extends PythagorasClass {

//---------------------------FIELDS-------------------------------

private static double 1;
private static double 2;
private static double 3;
private static double 4;
private static double 5;
private double variable1 = 0;
private double variable2 = 0;

//--------------------------CONSTRUCTORS---------------------------

public WallisClass (int numN) {
super(numN);

//--------------------------METHODS--------------------------------



}
}


[ November 25, 2004: Message edited by: bert McG ]
[ November 25, 2004: Message edited by: Marilyn de Queiroz ]
 
Marilyn de Queiroz
Sheriff
Posts: 9082
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bert,

We like to help people learn Java. We are volunteers. We try not to give people the answers to their homework problems, but to help them understand how to write the answers themselves.

What specific problem are you encountering when you try to solve this problem?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!