Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: iCritter Project

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    3
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation iCritter Project

    I need some real help in my Object Oriented Programming class. I have a project that is due by Wednesday and I need some guidance in how to complete this project. I have attached a .zip file of the source code that I created in Eclipse. Thanks to anyone who can provide a quick response and any help / guidance.

    I have not been able to find a tutor around my area for Java and want to become proficient.

    ---------------------------------------------------
    The View
    Create a separate package in your workspace called view, and within that package, create a class called ICritterUpdate. This class defines what type of update an Observer should perform (provided that the Observer is aware of the iCritterUpdate class).

    It is very simple, and contains the following members/methods:
    public static final int UPDATE_ICRITTER = 0x1;
    public static final int UPDATE_OWNER = 0x2;
    public static final int UPDATE_NONE = 0x0;
    private int updateType;
    public ICritterUpdate( int updateType );

    This method assigns this.updateType to updateType. The constructor should make sure that updateType is either UPDATE_iCRITTER or UPDATE_OWNER, and if it is not, it should assign it UPDATE_NONE.
    public int getUpdateType();
    Get the updateType member.

    When calling notifyObservers( Object o ) within iCritter or Owner, you should pass an instance of ICritterUpdate as the Object. If iCritter calls notifyObservers( Object o ), you should pass an instance of ICritterUpdate where updateType is set to UPDATE_iCRITTER. If Owner calls notifyObservers( Object o ), you should pass an instance of ICritterUpdate where updateType is set to UPDATE_OWNER. Additionally, you should create a class in the view package called ICritterView. This class should be an extension of JPanel, should implement Observer, and should implement the following methods:
    ICritterView( Owner theOwner )
    This method creates all of the Swing components needed and combines them into the GUI. It should call updateiCritterComponents()and updateOwnerComponents() to the appropriate components' values.
    public void updateiCritterComponents( iCritter theCritter )
    This method updates all of the iCritter-related components in the GUI to reflect the data within the given iCritter instance. It should be called from the update() method inherited from Observer, and even then it should only be called if the Object passed to update() is an instance of ICritterUpdate, and that instance's updateType member is equal to ICritterUpdate.UPDATE_iCRITTER.
    public void updateOwnerComponents( Owner theOwner )
    This method updates all of the Owner-related components of the GUI to reflect the data within the given Owner instance. It should be called from the update() method inherited from Observer, and even then it should only be called if the Object passed to update() is an instance of ICritterUpdate, and that instance's updateType member is equal to ICritterUpdate.UPDATE_OWNER.


    The Controller
    Create a separate package in your workspace called controller. In this package, create a class called ICritterController that extends JFrame. It should implement the following methods:
    ICritterController( String iCritterName )
    The constructor should create an Owner instance who is named after you, and the critter is named after iCritterName. It should also set its layout to BorderLayout and should add a new instance of view.ICritterView to itself at the location BorderLayout.CENTER. You should pass the Owner instance to the new view.ICritterView instance.
    Remember, since ICritterController is a JFrame, you will need to call this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ) somewhere in this method if you want your program to exit when the window is closed.
    Also, make sure to call this.pack() when you have finished adding all of your components.
    public static void main( String[] args )
    Create a new iCritterController and make it visible in this method.
    The controller package should also contain all of the ActionListener implementations that need to access ICritterController's Owner instance and any data within it.


    Overview
    In this phase of iCritter, you will be adding exceptions and exception handling to our project. In this part of the assignment you will be expected to modify two methods to throw exceptions and add exception handling to an iCritter's interact method.

    Design
    KeywordCollection.interestCorrelation(KeywordColle ction oColl) – This method should throw a NoInterestsException (see below) when neither KeywordCollection contains any interests.
    Owner.adjustCredits(Integer amount) – This method should throw a NotEnoughCreditsException (see below) when the amount would cause the Owner's credits to fall below 0. Remember that this method should add the amount given to the Owner's credits.
    Owner.buyCheapTreat() and Owner.buyFancyTreat() - You should modify these methods to catch NotEnoughCreditsExceptions and when the exception is caught, you should not buy the treat you wanted to buy. If the exception was not thrown then you know the adjustCredits() call was successful and you can finish buying the Treat.

    New Exceptions
    Your new exception classes should be placed in a new exceptions package. Both exceptions should extend RuntimeException.
    NotEnoughCreditsException – This exception is thrown when there is an attempt to remove more credits than the Owner has. The constructor for NotEnoughCreditsException should take two integers, the first representing the amount of credits we tried to remove (this should be a positive number), the second represents the amount of credits the Owner had at the time of the call (this too should be positive). The constructor should then call its super class's constructor passing in the message “Attempted to removexx credits, but only had yy credits.” Where xx and yy are the integers passed in by the constructor.
    NoInterestsException – This exception is thrown when we attempt to get the correlation between two empty KeywordCollection classes. The constructor for this exception should call its super's constructor and supply the message “There are no interests to use.”

    New iCritter
    For this assignment we will implement another ICritter that only adds friends if it and the ICritter it interacts with have no interests. We will call this new ICritter an ICritterSlug since slugs don't have any interests in general .
    ICritterSlug will extend LandICritter. You are expected to use exception handling to complete this interact method; failure to use exception handling will result in a loss of points.
    Since we now have an exception to worry about when interacting with other ICritters, you should modify the interact() method in LandICritter and MarineICritter to handle the new exception as if the correlation was 1/1.
    Attached Files Attached Files


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: iCritter Project

    Please post your specific questions and the code that is giving you the problem.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Need some help on my HS Project
    By ntilli in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 12th, 2011, 09:22 PM
  2. Help with Project
    By rawrxeroes in forum Object Oriented Programming
    Replies: 1
    Last Post: October 12th, 2011, 07:12 AM
  3. need help in my project
    By flana in forum The Cafe
    Replies: 4
    Last Post: October 11th, 2011, 06:13 AM
  4. help with project
    By pairenoid in forum Object Oriented Programming
    Replies: 1
    Last Post: May 7th, 2010, 08:55 AM
  5. Need a project
    By helloworld922 in forum Project Collaboration
    Replies: 6
    Last Post: July 31st, 2009, 08:30 AM

Tags for this Thread