File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes cant print Date or time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "cant print Date or time" Watch "cant print Date or time" New topic
Author

cant print Date or time

Iain Linton
Greenhorn

Joined: Jan 24, 2006
Posts: 21
Hi all I am having a problem on my coursework it has been asked to print the details of a job to the Terminal Window, but in doing so I get this output.

refNo = 20102 Staff Name = Micky Mouse Number of Pages = 12 Number of copies = 1 Double sided = true
Submitted Date = 01/01/2000 Cost = 24 p Time = 00:00

even if the date is set to a new Date I still get 01/01/2000 also even if time is set to new Time I still get 00:00.

Any pointers would be great.

[ January 26, 2006: Message edited by: Iain Linton ]
[ January 29, 2006: Message edited by: Iain Linton ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39570
    
  27
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 ]

Ping & DNS - updated with new look and Ping home screen widget
Iain Linton
Greenhorn

Joined: Jan 24, 2006
Posts: 21
Here is the thing I have to create a system within 'BlueJ'

you have a Time Class, a Date Class, a Job Class and a DayLog Class

when a job is created it gets its date format from the Date Class also its time format from the Time Class.

Then the Job Object is passed to the DayLog class and stored in an ArrayList.

Then the method to print the DayLog report is called and I get the printout:

refNo = 20102 Staff Name = Micky Mouse Number of Pages = 12 Number of copies = 1 Double sided = true Submitted Date = 01/01/2000 Cost = 24 p Time = 00:00

I have set the date and time using the Date Class and the Time Class

Still don't understand why it is not working
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13883
    
  10

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 ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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.

Layne


Java API Documentation
The Java Tutorial
Iain Linton
Greenhorn

Joined: Jan 24, 2006
Posts: 21
As I said before I am using Blue J and this has built in debugger.

but facing the problem of pulling the cost of each job out of the ArrayList and returning the total cost of all the jobs.

I also have to print big jobs ie jobs over 15 pages, I think I need to access the ArrayList and pull out the number of pages of each job and do a System.out.println.

Any help would be great.

Thank you.
[ January 27, 2006: Message edited by: Iain Linton ]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13883
    
  10

Any help would be great.

Did you understand my reply above? If not, please explain what you didn't understand and feel free to ask more questions.
Iain Linton
Greenhorn

Joined: Jan 24, 2006
Posts: 21
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 ]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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.

Layne
Iain Linton
Greenhorn

Joined: Jan 24, 2006
Posts: 21
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.

could you please give me an example

sorry
[ January 27, 2006: Message edited by: Iain Linton ]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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.

Layne
Iain Linton
Greenhorn

Joined: Jan 24, 2006
Posts: 21
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.

Line 111.

please rember I am using BlueJ Bluej Home Page
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Where is line 111? I can't count that high.

Layne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cant print Date or time
 
Similar Threads
Printing Object form an ArrayList
Constructing a Date from a long
Printing a total cost from collection of job Objects in Arraylist
boolean always returned as false
ArrayList