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.
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.
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.
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.
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.
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.”
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.
Re: iCritter Project
Please post your specific questions and the code that is giving you the problem.