jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Java advanced objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java advanced objects" Watch "Java advanced objects" New topic

Java advanced objects

Simon Rop

Joined: Oct 02, 2008
Posts: 1
1. Create an interface called limb and modify your arm and leg classes so that they implement it.
2. Create a new abstract class called Mammal and move any properties and methods that all mammals have from your Human to the Mammal class.
3. Ensure that your mammal has a private property which is an collection of limbs and protected methods to add, remove and retrieve the limbs (alternative solution would be to have protected collection of limbs and protected constructor in which you can pass collection of limbs to add).
4. Modify your Human to extend Mammal.
5. Add methods to your Human that return collections of arms and legs. implement these methods by iterating through the collection of limbs and checking what type of limb they are. Note that you will need to use the instanceOf keyword but we haven't covered it so you will need to research it.
6. Create three new classes that represent pets. They should all be mammals but have some unique characteristics.
7. Create a Family class that creates two humans (yourself and your ideal partner) and three pets.
8. Extend the Human class to create two new classes Adult and Child.
9. Make sure your human has an age property.
10. Modify your family so it includes a child.
11. Add an abstract canWatchMovie method to the Human which takes a parameter specifying the movie rating.
12. Create a MovieRating class that contains a private map with rating as the key and minimum age as the value, populate this map when the class is instantiated. Also include a method which takes two parameters, rating and age and checks the minimum age in the map and returns true or false to indicate whether or not a human with the specified age is allowed to watch a movie with the specified rating.
13. Implement the canWatchMovie method in the child and adult, in the adult always return true but in the child use the MovieRating class to determine whether the child can watch the movie.
14. Add a getMovieGoers method to the family that takes a rating as a parameter and returns a collection of all the family members that can watch the movie.
15. Demonstrate the use on the getMovieGoers method by calling it twice from within the main method of the family and prints out the names of the family members that can watch the movie.
Taariq San
Ranch Hand

Joined: Nov 20, 2007
Posts: 192
Nice one, have fun.
Please come back with specific questions once your head hurts.
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

This is not really an intermediate level topic. there's not even a question here. Even if someone would want to help you, it would be impossible since these tasks seem to rely on the fact that you already have some code written - i.e. "modify your arm and leg classes..." - and we don't have that code.

If you want to get the most out of this site, I strongly recommend you read all of this, but in particular ShowSomeEffort, NotACodeMill, and DoYourOwnHomework.

If you come back with specific, FOCUSED questions, people here will bend over backwards to help you. If you instead post "do my homework for me so I can hang out with my friends and not learn anything", as you seem to have done here, you will mostly be met with resounding silence.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

Good one!!! I will steal that for my own courses.
I agree. Here's the link: http://aspose.com/file-tools
subject: Java advanced objects
It's not a secret anymore!