You already have the six println statements at the bottom of the printMovieInfo() method that print various information about the movie, right? Each of those println statements goes something like this:
System.out.println("A short message to the user: " + (name_of_a_variable));
Now what you need to do is add another println statement that is almost the same as the others, except it goes something like this:
System.out.println("Total money made from rentals: " + some_method_name());
So you have to replace "some_method_name()" with the name of a method (not a variable) that calculates the total money made.
BTW, what textbook are you using?
Joined: Jul 16, 2005
These are some of the things I have tried that didn't work...
As a comment:
Didn't work == err or 'cannot find symbol - variable rentalMoneyTotals'
Separately, together... Movie.calculate...line give me "non-static method calculteRentalMoneyTotals() cannot be referenced from a static context. If I //that out and just leave the second line I get 'cannot find symbol - method rentalMoneyTotals().
I think I am on the right track...just using the wrong info?
My problem is all my other lines 'title', 'director'...are defined in my constructor. The rental totals one is defined in the method and I am not sure how to get something defined in one method called in another method.
The text is Objects First with Java: A practical introduction using Java.
The book doesn't even have a 'definition' section or list definitions in it's index. For a beginners manual, I think that is ridiculous. I finally went to one of those 1/2 price computer book stores and sat there for an hour going thru book after book until I found one that was pretty good. Not specifically OO, but lots of examples and definitions. Everything a beginner needs.
An OO method is the same thing as a non-OO function, with one subtle difference: the context in which it is run. That is, unlike non-OO languages such as C, where we call a function on the program context as a whole:
x = sqrt(y);
with a method in an OO language, the context for a method must either be (a) an object/instance of the class to which the method belongs or (b) the class as a whole. We use "dot notation" to prefix a method call with the name of the object or class that is to serve as the method's context.
There are three scenarios:
1. If the method is declared to be a static method, it can be invoked from client code -- i.e., from code outside of the class itself -- on the class as a whole to which it belongs:
Your calculateRentalMoneyTotals() method is not static -- nor should it be! -- which is why you got the compilation error that you did.
2. If a method is not a static method, it can be invoked from client code on an instance of the class; e.g.,
3. If one method foo() belonging to class X is going to call another method bar() declared in that same class X, the dot notation prefix can be omitted entirely, because in such a case, the DEFAULT context is understood to be the object upon which method foo() was running when bar() was called. That is,
Then, in client code, I might write:
such that someObject is the context for method foo() and, hence, the default context for bar() when called from within foo().
I hope this helps ... you are indeed close!
P.S. Look at your compiler error:
DO you have a method with that name???
Remember: the compiler is your friend! Pay close attention to what it is saying, and often (not always, but often) your "pain" will be lessened! [ July 17, 2005: Message edited by: Jacquie Barker ]
Lisa, please consider taking a look at my book, Beginning Java Objects; the kinds of problems you are having relate to fundamental concepts that many beginning level books don't bother to explain (e.g., the fact that a method needs a context for its execution).
Having taught Java for many years at the university level, I know first-hand what sorts of conceptual issues new Java programmers struggle with:
1. The scope of a variable 2. The case sensitivity of Java 3. What really happens when we instantiate an object 4. What a reference variable is all about
etc. -- things that a Java-knowledgable person who hasn't had the opportunity to teach might just assume everyone understands. In B.J.O., I leave nothing to the imagination!
Stuart...I read your post the first time at 3am. And it all went right over my head...hence the reply. (I shouldn't be working on java at 3am with no sleep!) But Ernest's reply to go back, and Jacquie's reply about my 'this is not a method' error, sent me back up to you post. I went back to that and got it! And now it seems so simple! I feel like an idiot for not getting it.
Jacquie your info is fabulous!!! (I have printed everything out.) Your comment about my error message (no it is NOT a method) sent me back to Stuarts post. And I am going to head over to our local book store and see if they have the book you mentioned. I am sorry I didn't know about your book on Friday when I went and pick up, what looks to be, an inferior book.
I think my main problem with java right now is terminology. The text really hasn't taught us that, and for a beginner, it is very frustrating.
What I need is to see a piece of java (doesn't matter if I understand what it will do) and have it taken apart piece by piece and have those pieces given a 'name' and defined.
I will never forget what a method name is now!
Thank you all again!
Joined: Apr 21, 2005
Stuart...I read your post the first time at 3am. And it all went right over my head...hence the reply. (I shouldn't be working on java at 3am with no sleep!)
Soon you will learn that this is not just a good time, but the only time to be working on Java
Seriously, I have read some of your other posts and it seems clear to me that you want to learn rather than just being given the answers. With that attitude progress will take a lot less time that you think!