Hi I'm just starting out with OOPin JAVA and thought i was getting the hang of it but i've been given an assignment and it's got me stumped.

here is the code i have been given

public class FrogCalculator
{
   
   private Frog operand1Frog;
   private Frog operand2Frog;
   private Frog unitsFrog;
   private Frog tensFrog;
   private OUColour colour;
   
   
   
  /**
   * Constructor for objects of class FrogCalculator 
   */
   public FrogCalculator()
   {
      Super();
     
   }

   
   /* instance methods */

   /**
    * Returns the receiver's operand1Frog
    */
   public Frog getOperand1Frog()
   {
      return operand1Frog;
      
   }

   /**
    * Sets the receiver's operand1Frog
    */
   public void setOperand1Frog(Frog operand1Frog)
   {
      this.operand1Frog = operand1Frog;
   }

   /**
    * Returns the receiver's operand2Frog
    */
   public Frog getOperand2Frog()
   {
      return operand2Frog;
   }

   /**
    * Sets the receiver's operand2Frog
    */
   public void setOperand2Frog(Frog operand2Frog)
   {
      this.operand2Frog = operand2Frog;
   }

   /**
    * Returns the receiver's unitsFrog
    */
   public Frog getUnitsFrog()
   {
      return unitsFrog;
   }

   /**
    * Sets the receiver's unitsFrog
    */
   public void setUnitsFrog(Frog unitsFrog)
   {
      this.unitsFrog = unitsFrog;
   }
     
   /**
    * Returns the receiver's tensFrog
    */
   public Frog getTensFrog()
   {
      return tensFrog;
   }

   /**
    * Sets the receiver's tensFrog
    */
   public void setTensFrog(Frog tensFrog)
   {
      this.tensFrog = tensFrog;
     
   }


}

here is what i am being asked to do;

Write code in the FrogCalculator class to modify the signature of the default constructor for FrogCalculator such that it takes four arguments of type Frog. The positions of the two Frog instances referenced by the first and second arguments represent the first and second operands, respectively. The positions of the two Frog
instances referenced by the third and fourth arguments represent the result of the calculation: the third Frog instance being the ‘tens’ frog and the fourth Frog instance being the ‘units’ frog.
The constructor should assign the arguments directly to the four corresponding private instance variables and then set the frog referenced by tensFrog to brown and the frog referenced by unitsFrog to yellow.

But i just don't know how?? I know that FrogCalculator class willinherit the positon and colour of the superclass frog, but i'm at a loss for what code i have to add.

can anyone help me??

Recommended Answers

All 3 Replies

public class FrogCalculator
{

private Frog operand1Frog;
private Frog operand2Frog;
private Frog unitsFrog;
private Frog tensFrog;
private OUColour colour;



/**
* Constructor for objects of class FrogCalculator
*/
public FrogCalculator()
{
Super();

}


/* instance methods */

/**
* Returns the receiver's operand1Frog
*/
public Frog getOperand1Frog()
{
return operand1Frog;

}

/**
* Sets the receiver's operand1Frog
*/
public void setOperand1Frog(Frog operand1Frog)
{
this.operand1Frog = operand1Frog;
}

/**
* Returns the receiver's operand2Frog
*/
public Frog getOperand2Frog()
{
return operand2Frog;
}

/**
* Sets the receiver's operand2Frog
*/
public void setOperand2Frog(Frog operand2Frog)
{
this.operand2Frog = operand2Frog;
}

/**
* Returns the receiver's unitsFrog
*/
public Frog getUnitsFrog()
{
return unitsFrog;
}

/**
* Sets the receiver's unitsFrog
*/
public void setUnitsFrog(Frog unitsFrog)
{
this.unitsFrog = unitsFrog;
}

/**
* Returns the receiver's tensFrog
*/
public Frog getTensFrog()
{
return tensFrog;
}

/**
* Sets the receiver's tensFrog
*/
public void setTensFrog(Frog tensFrog)
{
this.tensFrog = tensFrog;

}


}

Code tags.

[code=JAVA] // code goes here

[/code]

You need to format your code too so it's readable.

But i just don't know how?? I know that FrogCalculator class willinherit the positon and colour of the superclass frog, but i'm at a loss for what code i have to add.

You haven't said there was a superclass in the code.

public class FrogCalculator

If Frog is the superclass, declare that to be the case.

public class FrogCalculator extends Frog

Thanks, and apologies for the missing info. i'm new to all this and i'm also over 60 so it's a bit of a steep learning curve for me!!

thank again

It's hard to speculate what needs to be done since I don't know what the Frog class and the rest of the project looks like. If you were given the code, I would double-check to make sure that FrogCalculator is in fact a subclass of Frog since the sample code given to you doesn't have the word extends Frog in it. I'm assuming this is a program that simulates an elementary school manual calculator similar to an abacus with frogs instead of beads? It's part of a program where frogs are drawn and moved along the sticks?

Java is case sensitive. I think (not 100% positive) that the call to Super () will fail. Try changing it to super () .

[edit]
Didn't notice you had marked this solved earlier.
[/edit]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.