| | |
Creating and Using Exceptions
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2008
Posts: 24
Reputation:
Solved Threads: 0
look at the method below
javaAddict is telling me :"You are making the same mistake with addMovieGoers. You are supposed to take the argument and add it to the ArrayList. The user calling the method will set which "humans" will "watch" the movie. And again you are using fixed values. It is as if the method has no meaning of existence since it makes no difference what the argument is since you don't use it"
So can you help me correct this?
Java Syntax (Toggle Plain Text)
public void addMovieGoers(Human h) throws IllegalAgeException { Human a = new Adult("Joe",43); Human b = new Adult("Sue",39); Human c = new Adult("Tracy",20); Human d = new Child("Sammy",17); Human e = new Child("Julie",12); Human f = new Child("Mona",6); hm.add(a);hm.add(b);hm.add(c);hm.add(d); hm.add(e);hm.add(f); hm.trimToSize(); String toPrint = ""; if(movieNew.getRating()!=null && movieNew.getTitle()!=null) { if(mrPG.equals(movieNew.getRating())) //movies rated PG { System.out.println("The following can only watch under parental guidance:"); for(int i = 0; i < hm.size(); i++) { Human test = (Human)hm.get(i); if ( test instanceof Child) { if(toPrint.equals("")) { System.out.println(test); } else { System.out.println("Children: " + toPrint); } } } } else if(mrA.equals(movieNew.getRating())) //movies rated Adult { System.out.println("The following can watch..."); for ( int i = 0; i < hm.size(); i++) { Human test = (Human)hm.get(i); if ( test instanceof Adult) { if(toPrint.equals("")) { System.out.println(test); } else { System.out.println("Adults: " + toPrint); } } } } else if(mrG.equals(movieNew.getRating()))//Movies rated G { System.out.println("This is movie rated G. So the following can watch"+ ": "+hm+""); } else { throw new IllegalAgeException("You may not be old enough to watch a movie."); } } }
javaAddict is telling me :"You are making the same mistake with addMovieGoers. You are supposed to take the argument and add it to the ArrayList. The user calling the method will set which "humans" will "watch" the movie. And again you are using fixed values. It is as if the method has no meaning of existence since it makes no difference what the argument is since you don't use it"
So can you help me correct this?
The argument: Human h is the one to be added in the ArrayList.
The way you have it. no matter what the argument is, you will always insert the same values:
It is the argument that you need to insert. Of course before adding it do whatever checks are necessary.
The way you have it. no matter what the argument is, you will always insert the same values:
Java Syntax (Toggle Plain Text)
Human a = new Adult("Joe",43); Human b = new Adult("Sue",39); Human c = new Adult("Tracy",20); Human d = new Child("Sammy",17); Human e = new Child("Julie",12); Human f = new Child("Mona",6); hm.add(a);hm.add(b);hm.add(c);hm.add(d); hm.add(e);hm.add(f);
It is the argument that you need to insert. Of course before adding it do whatever checks are necessary.
Check out my New Bike at my Public Profile at the "About Me" tab
![]() |
Similar Threads
- Updated : Simple ASP.Net Login Page (ASP.NET)
- Creating a Library (C++)
- creating an instant messenger program in java (Java)
- help with creating and calling a function (C++)
- OutOfMemory Error (Java)
- weird exceptions:( (Python)
- Creating a .EXE file (Java)
- Playing with RMI in Tiger (Java)
- Cannot get CF set up on server (ColdFusion)
- creating a frame with four clocks (Java)
Other Threads in the Java Forum
- Previous Thread: joining 2 database tables in a single query instead of arraying it and making a mess
- Next Thread: Java lang exception thrown
| Thread Tools | Search this Thread |
Tag cloud for Java
actionlistener android api apple applet application apps arguments array arrays automation balls binary bluetooth card chat class classes client code component consumer database draw eclipse ee error event exception fractal free game gameprogramming gis givemetehcodez graphics gui helpwithhomework html ide image input integer j2me j2seprojects java javaprojects jmf jni jpanel julia jvm key linux list loop machine map method methods migrate mobile myaggfun netbeans newbie nextline nls notdisplaying number oracle output print problem program programming project recursion recursive scanner screen security server set size sms socket sort spamblocker sql sqlite string sun swing terminal test threads time tree trolltech windows






