It's hard to tell what a program might do without seeing the program. Why don't you post a short relevant excerpt of the code that uses these classes.
A year of 2000 makes it sound as if the setters are never called, because the Date class interprets 0 (the default int value) as the year 2000.
To make reading the code easier by keeping its formatting intact, you can use the CODE tags, which are accessed via the CODE button underneath the text entry field when entering you post. You can also edit your previous post and add the tags to it. [ January 26, 2006: Message edited by: Ulf Dittmer ]
The code you posted is not the complete program, because I don't see the main(...) method anywhere.
Where are you creating the Date objects in your program? You need to use the constructor that takes three arguments. The constructor without parameters sets the Date to 01/01/2000.
Ok, I had another look. Look at this method in your class Job:
Do you understand what it does? It sets the member variable called 'adate' to a new Date object. You don't pass any parameters to the constructor of the Date class, so the date is set to 01/01/2000 (because that's what the constructor of class Date sets it to).
The parameter 'adate' of the method setDateRequired is not used at all. Are you sure you didn't mean this:
[ January 26, 2006: Message edited by: Jesper de Jong ]
This sounds very similar to one of your earlier questions (I set variable X to value Y but it prints out as Z). It sounds like you need to learn how to debug your own programs to track down these kinds of problems. The most basic technique is to add System.out.println() (SOP) calls that display information about which line of code is executing and values of variables at that point in the code. For example, doing something like
can help you figure out these kinds of problems. The skill to learn here is to figure out where to put these SOP calls.
You might also want to download an IDE that has a visual debugger. This tool lets you step through the code line-by-line, set breakpoints that halt execution at a given line in the code, and "watch" the values of variables. It will be worth your time to learn how to use these kinds of tools so you can track down bugs yourself.
Did you understand my reply above? If not, please explain what you didn't understand and feel free to ask more questions.
Joined: Jan 24, 2006
I did not really understand what you are trying to tell me.
I may have allready asked this but if you look at my code below, I am trying to inclued within the DayLog Class .
'totalCost' this should store the total cost of the completed Jobs
But the completed Jobs are in the ArrayList, I need to know how to get the cost out of all the completed Jobs objects and store it so it can be printed when the printReport method is envoked. [ January 29, 2006: Message edited by: Iain Linton ]
Joined: Dec 06, 2001
Since BlueJ has a built-in debugger, it will be worth your time learnign how to use it, if you haven't already. With that said, let's see what we can do to help you. First, does your Job class have a getCost() method? If so, when you are iterate through the list to print the jobs, you can use this to compute the total cost of all the completed jobs.
If you are not sure how to do this, I think it will help if you step back from this program and write a small program that will help you learn some of the ideas here. In particular, I think you should write a program that let's the user input a number n and totals all the numbers from 1 to n. Do you think you can write this program? If so, I strongly suggest it since it will give you experience totalling a list of numbers. Another variation on this is to ask the user to continue entering numbers and calculating the total of the numbers entered. You can have the user enter a special value, such as -1, when they are done entering the actual data.
If you can write both of these small example programs, it will help you get away from the aditional complexities in your current project and concentrate on the steps necessary to find the total of a list of numbers. I think this will help you a lot so that you can come back and add it to the larger project you are working on.
Joined: Jan 24, 2006
Yes I have the getCost method in the Job Class and is returning the correct results.
When you said I could get this by iterating through the jobs, I understand that but what I do not understand is would the program store the numbers then total them if so would it store the numbers localy.
but I still don't understand how to compute the total cost when iterating through the jobs.
Originally posted by Iain Linton: but I still don't understand how to compute the total cost when iterating through the jobs. [ January 27, 2006: Message edited by: Iain Linton ]
This is exactly why I suggest that you put this project aside for a moment and write a small example program. The program should ask the user to input a list of 10 numbers and print out the total of those numbers. Do you think you can write this program? It should take you less than an hour and less than 25 lines of code.
Joined: Jan 24, 2006
This is the full message I get when compiling.
int cannot be Dereferenced
You are using Dot notation to access a field or method of another Object, however, the variable you are using is not of an Object type � it does not have Fields or Methods.