Results 1 to 4 of 4
  1. #1
    Monkeeboy is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default Help with creating new class as a subclass in Java

    Hello,

    i'm new to Java and trying to learn but i'm having trouble creating a new class - as a subclass.
    here is what i'm being asked to do;
    Create MoneyFrog as a subclass of Frog. In addition to those inherited from the Frog class, instances of the MoneyFrog class should have three additional private instance variables - two boolean variables called lastReceived and lastGiven and a third type Account called account. Write declarations for these instance variables together with public getter and setter methods for the boolean instance variables lastReceived and lastGiven and a public getter method for account.

    here's what i've managed to do but the class will not compile
    Java Code:
    /**
     * Class MoneyFrog 
     * 
     */
    public class MoneyFrog extends Frog
    {
    	/* instance variables */
    	private Account account;
    	private boolean lastReceived;
    	private boolean lastGiven;
    
    	/**
    	 * Constructor for objects of class MoneyFrog
    	 */
    	public MoneyFrog()
    	{
    		super();
    		this.account;
    		this.lastReceived = false;
    		this.lastGiven = false;		
    	}
    
    	/* instance methods */ // i'm not sure what to do here but i've tried//
    
    	/**
    	 *  returns the receivers account  	 
    	 */
    	public void account()
    	{
    		
    	}
    	
    	/**
    	 *  returns the value of the amount lastGiven to the receiver  
    	 */
    	public boolean lastGiven()
    	{
    		return this.lastGiven;	
    	}
    	
    	/**
    	 *  returns the value of the amount lastReceived by the receiver  
    	 */
    	public boolean lastReceived()
    	{
    		return this.lastReceived;	
    	}
    
    }
    any help would be appreciated

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    the Account getter method should be named getAccount and should return the Account object held by the account variable, not a void.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Also you need to write your two setter methods. An example of a setter method for an int variable myIntVariable is something like so:

    Java Code:
    public void setMyIntVariable(int myIntVariable) {
       this.myIntVariable = myIntVariable;  // set the class's myIntVariable with the parameter's value
    }

  4. #4
    Monkeeboy is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

Similar Threads

  1. Super class refering to subclass
    By sujith123 in forum New To Java
    Replies: 3
    Last Post: 10-05-2009, 10:00 AM
  2. Custom Class, Wrapper/Subclass?
    By Moncleared in forum Advanced Java
    Replies: 3
    Last Post: 02-10-2009, 12:08 AM
  3. Super class and Subclass in same source file
    By makbar24 in forum New To Java
    Replies: 17
    Last Post: 09-10-2008, 02:24 PM
  4. subclass vs inner class
    By bugger in forum New To Java
    Replies: 1
    Last Post: 01-13-2008, 08:31 PM
  5. which class is superclass and subclass?
    By java_fun2007 in forum New To Java
    Replies: 0
    Last Post: 12-11-2007, 09:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •