Basically its simple java code that is suppose to print out the latest, earliest, and current dates however, its not compiling and I keep getting "incompatible error" i'll put an error by where the error keeps popping. I'm not really familiar with java nor am I not that good at java and programming therefore, I'm asking for help, if anybody could help me. Please & thank you
//YOU DO THIS
//Print the average year of the dates in the dates array
//You may want to call getYear to get the year from each date
I am afraid there is a lot which I think should be changed. The most serious error, in my opinion, is that you are not using object‑orientation. Nowhere are you creating an object from that class. And why haven't you got a Date class? [Beware of confusion; there are already two classes in the standard API called Date.]
Why have you got the keyword static in so many places? Do you know what static actually means?
Have you read the documentation for StringTokenizer[←link]? You ought not to use it, and the documentation tells you what to use instead.
Piet Souris wrote:And about the use of the word 'static': the methods are called from within main(), what else would you expect?
I'm with Campbell.
If you're going to learn an OO language, then you should at least use basic OO design from the start, so your main should create an instance of the enclosing class and then call a non-static method of that class.
The beginner may not understand why it is done that way yet, but it is always better to introduce good practice as early as possible.
They can learn the 'why' later.
Piet Souris wrote:@Campbell...Give Lesly a break! Read what he/she says in the first paragraph, consider that this forum is called 'Beginning Java',
and you're criticizing the lack of OO!
Piet, EaseUp. Campbell's been on these forums for a long time, and definitely knows what he's talking about.
Me, I've been in IT for 35 years, and my major regret was that somebody didn't (or couldn't) teach me about Object-Orientation from the get go.
@Lesly: You plainly know a bit about methods and modularization, so that you don't repeat logic and don't plough everything into your main() method. Learning to create classes and objects to do what you want is just the next step along that road (albeit a major one ).
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
posted 6 years ago
Thank you everybody.
If you are learning to drive a car, you learn to drive on the roads.
If you are going to use an object‑oriented language, you need to learn to use objects.
I know there are books which hardly show creation of objects, or use of their public interface, and even the Java Tutorials fall into that trap. I do not know whether there is teaching which follows similar paths, but I suspect there is. The repeated use of static is often the result of failure to create objects; Stuart A Burkett has shown the correct way to do call methods from the main method.
posted 6 years ago
first of all: my remarks were certainly not meant to be offensive in any way, or to doubt anyone's expertise.
If it was nevertheless found to be offensive, then I sincerely apologize.
I was thinking of the classical question: if someone is hungry, do you give him a fish or do you start learning
him how to fish? In that respect, I thought that Jeanne's remarks were spot on.