![]() |
| ||
| using Map in java Hi, I'm trying to use a map in my application. the class MovieRating which contains the map is as below: import java.util.*;I now want to use the three ratings and age in the map in a method in a different class to determine whether the various individuals of various age groups can watch a certain movie or not. the method is called getMovieGoers and is as below: NOTE: This method is in a different class called Family within the same package. It returns a collection of moviegoers from the arraylist. public void getMovieGoers(MovieRating mRt)When I run my application and call the method in the main, it does not list the moviegoers and I suspect the problem is picking the rating and age pair from the map in the MovieRating class. Some help please..... |
| ||
| Re: using Map in java well... you're code is quite unreadable. please try using code tags, it 'll make it a lot easier. you also go through a lot of effort, using HashMaps while simple int variables would suffice, but I guess that's up to you to choose. lastly, in the method you want us to check, you use the variable ourChild, while you don't show a declaration or set a value to it in the code you show, so please show the entire code, so we know what we're dealing with. also, don't it's no use creating the Collection myAdults. you already have that Collection, called ads |
| ||
| Re: using Map in java Quote:
import java.util.*; Child class class Child extends Human Family class import java.util.*; NOTE: Don't worry about the Cat, Dog and Rabbit classes. They are not included here. Adult class class Adult extends Human My main problem is the method getMovieGoers(MovieRating mRt) in Family class. and how to use rating as the key and minimum age as the value from the Map in this method to get movie goers for each rating. |
| ||
| Re: using Map in java I think you'd do better to first learn the basic logic of OO programming. you're Family class, for instance: you'd have a Family with just one adult, with (max) one child, ... next to that, the names 'me' and 'myName' are a bit ... confusing. or, of course, you want to be able to create just one family (yours), or you want to be part of every family. in a better implementation, a more OO approach, your Family.java should look more like this: public class Family{this is about all there has to be in it. about the watchin movies or not, that does not belong in family, that should be in the class that uses family |
| ||
| Re: using Map in java well there's a getMovieGoers method in the Family class that takes a rating as a parameter and returns a collection of all the family members that can watch the movie. This method is to be called in the main method of family. |
| ||
| Re: using Map in java The rating is to be picked from the Map in MovieRating class, because there are some movies which can oly be watched by Adults or Children of certain age. I hope it's not confusing. |
| ||
| Re: using Map in java Quote:
... and in the actual Family class: public Collection getMovieGoers(int rating){ |
| All times are GMT -4. The time now is 9:17 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC