Results 1 to 13 of 13
Thread: Weird data output
- 12-11-2007, 02:42 AM #1
Member
- Join Date
- Nov 2007
- Posts
- 38
- Rep Power
- 0
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:
Here is my code:FT@19821f
FT@addbf1
Employee Class:
FullTime Class: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
}
Main Class:public class FT extends Employee {
protected static double salary = 1600.0;
public FT () {
super();
}
public FT (String nm, int ext){
super(nm, ext);
}
}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 02:45 AM.
- 12-11-2007, 02:46 AM #2
Senior Member
- Join Date
- Nov 2007
- Location
- Newport, WA
- Posts
- 141
- Rep Power
- 0
You are printing out the class, not any of the data in it.Java Code:System.out.println( "test: " + e1 ) ;
That will only work if the main class is in the same package as everything else (since name is protected).Java Code:System.out.println( "test: " + e1.name)
- 12-11-2007, 03:27 AM #3
Member
- Join Date
- Nov 2007
- Posts
- 38
- Rep Power
- 0
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 09:21 PM.
- 12-11-2007, 04:50 AM #4
Senior Member
- Join Date
- Nov 2007
- Location
- Newport, WA
- Posts
- 141
- Rep Power
- 0
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.
- 12-11-2007, 04:56 AM #5
Member
- Join Date
- Nov 2007
- Posts
- 38
- Rep Power
- 0
Can you give me an example as this is all new to me. Thanks
- 12-11-2007, 05:13 AM #6
Member
- Join Date
- Nov 2007
- Posts
- 38
- Rep Power
- 0
I tried the following:
And I got this output:Java Code:ListIterator vIter = vec.listIterator() ; while ( vIter.hasNext() ) { System.out.println( vec ) ; vIter.next() ; }
Here is the whole code for Directory(storage):[FT@19821f, FT@addbf1]
[FT@19821f, FT@addbf1]Last edited by Shaolin; 12-11-2007 at 09:22 PM.
- 12-11-2007, 05:24 AM #7
Senior Member
- Join Date
- Nov 2007
- Location
- Newport, WA
- Posts
- 141
- Rep Power
- 0
Well all these variables are different types at the moment:
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:Java Code:protected int workid ; protected String name ; protected int tel ; protected static int lastid = 100000 ; protected double pay ;
Java 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());
- 12-11-2007, 05:27 AM #8
Senior Member
- Join Date
- Nov 2007
- Location
- Newport, WA
- Posts
- 141
- Rep Power
- 0
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:I tried the following
Java Code:System.out.println(vec.next());
- 12-11-2007, 05:43 AM #9
Member
- Join Date
- Nov 2007
- Posts
- 38
- Rep Power
- 0
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());
- 12-11-2007, 05:57 AM #10
Senior Member
- Join Date
- Nov 2007
- Location
- Newport, WA
- Posts
- 141
- Rep Power
- 0
The next() method is not part of Vector, its part of Iterator:
Java Code:Vector<Employee> data = new Vector<Employee>(); Iterator<String> ir = data.iterator(); while(ir.hasNext()) System.out.println(ir.next());
- 12-11-2007, 06:13 AM #11
Member
- Join Date
- Nov 2007
- Posts
- 38
- Rep Power
- 0
That didn't work. Here are the error messages I get:
Java 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 09:22 PM.
- 12-11-2007, 06:43 AM #12
Member
- Join Date
- Nov 2007
- Posts
- 38
- Rep Power
- 0
OK so I've been messing around with the code and I this is what I have at the moment:
It works, but the output is as follows:Java Code:ListIterator vIter = vec.listIterator() ; while ( vIter.hasNext() ) { System.out.println( vIter.next() ) ; }
I know that Im printing the vector, not the actual content. How do I print the content ?Java Code:FT@19821f FT@addbf1
- 12-11-2007, 04:27 PM #13
Member
- Join Date
- Nov 2007
- Posts
- 38
- Rep Power
- 0
Similar Threads
-
need help, weird question kinda.
By carlos123 in forum New To JavaReplies: 6Last Post: 01-22-2008, 03:19 AM -
output
By Camden in forum New To JavaReplies: 3Last Post: 12-01-2007, 10:34 PM -
weird looking shape JButton is it possible?
By unhurt in forum AWT / SwingReplies: 8Last Post: 11-03-2007, 09:10 AM -
How to redirect the output
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:30 PM -
get the output from whoami
By gary in forum Advanced JavaReplies: 2Last Post: 06-12-2007, 01:05 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks