Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-11-2007, 04:42 AM
Member
 
Join Date: Nov 2007
Posts: 36
Shaolin is on a distinguished road
Weird data output
Hi Guys,

I have a main class, an employee class and a fullTime class which is a subclass of employee. I am trying to output some hard written data in the main class but I get the following characters when I run it:

Quote:
FT@19821f
FT@addbf1
Here is my code:

Employee Class:
Quote:
public abstract class Employee {

protected int workid ;
protected String name ;
protected int tel ;
protected static int lastid = 100000 ;
protected double pay ;

public Employee() {
name = "" ;
tel = 0;
workid = lastid++ ;
pay = 0.0 ;
}

public Employee (String nm, int ext) {
name = nm ;
tel = ext ;
workid = lastid++ ;
pay = 0.0 ;
}

public abstract void calculatePayment(); // abstract method

}
FullTime Class:
Quote:
public class FT extends Employee {

protected static double salary = 1600.0;

public FT () {
super();
}

public FT (String nm, int ext){
super(nm, ext);
}
}
Main Class:
Quote:
public class main {

public static void main( String[] args )
{
FT e1 = new FT ( "John", 1237 ) ;
FT e2 = new FT ( "Michelle", 1291 ) ;

System.out.println( "test: " + e1 ) ; // Output data

}


}

Last edited by Shaolin : 12-11-2007 at 04:45 AM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-11-2007, 04:46 AM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
Code:
System.out.println( "test: " + e1 ) ;
You are printing out the class, not any of the data in it.
Code:
System.out.println( "test: " + e1.name)
That will only work if the main class is in the same package as everything else (since name is protected).
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-11-2007, 05:27 AM
Member
 
Join Date: Nov 2007
Posts: 36
Shaolin is on a distinguished road
Thanks. its not in the same package.

What if I want to use a vector/iterator to output the data? I tried it and it gave me the same output outlined in the first post.

What adjustments will I need to make in order to get it to work ?

Last edited by Shaolin : 12-11-2007 at 11:21 PM.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-11-2007, 06:50 AM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
A solution would be to store all of the data in the Employee class as a single Vector: the name work id, pay, etc.

Then return that data and iterate it.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 12-11-2007, 06:56 AM
Member
 
Join Date: Nov 2007
Posts: 36
Shaolin is on a distinguished road
Can you give me an example as this is all new to me. Thanks
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 12-11-2007, 07:13 AM
Member
 
Join Date: Nov 2007
Posts: 36
Shaolin is on a distinguished road
I tried the following:
Code:
ListIterator vIter = vec.listIterator() ; while ( vIter.hasNext() ) { System.out.println( vec ) ; vIter.next() ; }
And I got this output:

Quote:
[FT@19821f, FT@addbf1]
[FT@19821f, FT@addbf1]
Here is the whole code for Directory(storage):

Last edited by Shaolin : 12-11-2007 at 11:22 PM.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 12-11-2007, 07:24 AM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
Well all these variables are different types at the moment:
Code:
protected int workid ; protected String name ; protected int tel ; protected static int lastid = 100000 ; protected double pay ;
You those all have to become Strings and be placed inside a vector. I dont know if you want that but here is an example:
Code:
String s = "s"; int i = 5; Vector<String> data = new Vector<String>(); data.add(s); data.add(String.valueOf(i)); Iterator<String> ir = data.iterator(); while(ir.hasNext()) System.out.println(ir.next());
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 12-11-2007, 07:27 AM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
Quote:
I tried the following
Good try, but you are printing out the vector, not the item inside it. You need to print out the content of the vector if you want to see any meaningful data. So you need:

Code:
System.out.println(vec.next());
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 12-11-2007, 07:43 AM
Member
 
Join Date: Nov 2007
Posts: 36
Shaolin is on a distinguished road
I tried that and got the following error:

Directory.java:56: cannot find symbol
symbol : method next()
location: class java.util.Vector<Employee>
System.out.println(vec.next());
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 12-11-2007, 07:57 AM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
The next() method is not part of Vector, its part of Iterator:
Code:
Vector<Employee> data = new Vector<Employee>(); Iterator<String> ir = data.iterator(); while(ir.hasNext()) System.out.println(ir.next());
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 12-11-2007, 08:13 AM
Member
 
Join Date: Nov 2007
Posts: 36
Shaolin is on a distinguished road
That didn't work. Here are the error messages I get:

Code:
Directory.java:59: incompatible types found : java.util.Iterator<Employee> required: java.util.Iterator<java.lang.String> Iterator<String> vIter = vec.iterator() ; ^

Last edited by Shaolin : 12-11-2007 at 11:22 PM.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 12-11-2007, 08:43 AM
Member
 
Join Date: Nov 2007
Posts: 36
Shaolin is on a distinguished road
OK so I've been messing around with the code and I this is what I have at the moment:

Code:
ListIterator vIter = vec.listIterator() ; while ( vIter.hasNext() ) { System.out.println( vIter.next() ) ; }
It works, but the output is as follows:

Code:
FT@19821f FT@addbf1
I know that Im printing the vector, not the actual content. How do I print the content ?
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 12-11-2007, 06:27 PM
Member
 
Join Date: Nov 2007
Posts: 36
Shaolin is on a distinguished road
Fixed problem.

Last edited by Shaolin : 12-11-2007 at 11:21 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help, weird question kinda. carlos123 New To Java 6 01-22-2008 05:19 AM
output Camden New To Java 3 12-02-2007 12:34 AM
weird looking shape JButton is it possible? unhurt AWT / Swing 8 11-03-2007 11:10 AM
How to redirect the output JavaBean Java Tips 0 10-04-2007 11:30 PM
get the output from whoami gary Advanced Java 2 06-12-2007 03:05 PM


All times are GMT +3. The time now is 03:53 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org