Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
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 05-05-2008, 04:47 AM
Member
 
Join Date: May 2008
Posts: 12
ubermeister is on a distinguished road
[SOLVED] few steps i need help with
ok this is what my assignment calls for. i need to create a main() function that would implement as having the following steps:

1. creating an object employee1 w/out perameter
2.creating an object employee2 with the following parameters (mary,1111,42000)
3.display employee1 data
4.display employee2 data
5. calling getData function to enter data for employe1
6.redisplaying employee1 data
7. creating an arrary of employee objects with 3 members
8. writing the loop statment to accept data and print data for each of the array member.

this is what i have so far:
Code:
public class TestEmployeeClass { public static void main(String[] args) { EmployeeClass s1= new EmployeeClass(); s1.display(); s1.displayTotal(); EmployeeClass s1= new EmployeeClass(MARY,1111,7500); s1.display(); s1.displayTotal();


THIS code below is the 2nd part to it. (the code below works fine, use as guide for the one above)

Code:
import java.util.Scanner; public class EmployeeClass { static int total=0; //member data String name; int id; double salary; //constructor EmployeeClass() { name=""; id=0; salary=0.0; } EmployeeClass(String n,int i, double s) { name=n; id=i; salary=s; } public void getdata() { Scanner kb= new Scanner(System.in); String s; System.out.print("Enter Name : "); name=kb.nextLine(); System.out.print("Enter ID : "); id=kb.nextInt(); //class buffer s=kb.nextLine(); System.out.print("Enter Salary : "); name=kb.nextLine(); } public void display() { System.out.printf("NAME = %s\n",name); System.out.printf("ID = %s\n",id); System.out.printf("SALARY = %s\n",salary); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-05-2008, 04:52 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,168
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Hi ubermeister,

Welcome to our community.

Seems to me your application is ok, so what is your question there?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best?Vote Now
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-05-2008, 04:54 AM
Member
 
Join Date: May 2008
Posts: 12
ubermeister is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Hi ubermeister,

Welcome to our community.

Seems to me your application is ok, so what is your question there?
thanks i need help with steps 1-8 for the first code I put above. I think i have followed 1-4 so its just steps 5-8 i need assistance doing.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-05-2008, 04:57 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,168
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
You have to get data at the TestEmployeeClass I think. Then after using instance and appropriate constructors do the processing. Got it?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best?Vote Now
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-05-2008, 05:02 AM
Member
 
Join Date: May 2008
Posts: 12
ubermeister is on a distinguished road
ya i know that has to be done but HOW do you go about doing that.

take step 5.

i wouldn't know what to do after this

public void getdata()
{
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-05-2008, 05:09 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,168
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
You asking that how to implement that method? There have few errors in your code. Try this.

Code:
// Collect data from the user public void getdata() { Scanner kb = new Scanner(System.in); System.out.print("Enter Name : "); name = kb.nextLine(); System.out.print("Enter ID : "); id = kb.nextInt(); System.out.print("Enter Salary : "); salary = kb.nextInt(); }
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best?Vote Now
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-05-2008, 05:12 AM
Member
 
Join Date: May 2008
Posts: 12
ubermeister is on a distinguished road
Quote:
Originally Posted by Eranga View Post
You asking that how to implement that method? There have few errors in your code. Try this.

Code:
// Collect data from the user public void getdata() { Scanner kb = new Scanner(System.in); System.out.print("Enter Name : "); name = kb.nextLine(); System.out.print("Enter ID : "); id = kb.nextInt(); System.out.print("Enter Salary : "); salary = kb.nextInt(); }
nonono thats not the code i'm referring to.
i'm talking about the FIRST code i have up i need to ADD a getData function with employee1 info in the main() function.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-05-2008, 05:16 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,168
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Ah, you asking how to call that function on an employee object.

Code:
public static void main(String[] args) { EmployeeClass s1= new EmployeeClass(); s1.display(); EmployeeClass s2= new EmployeeClass("MARY",1111,7500); s2.display(); EmployeeClass s3 = new EmployeeClass(); s3.getdata(); s3.display(); }
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best?Vote Now
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 05-05-2008, 05:22 AM
Member
 
Join Date: May 2008
Posts: 12
ubermeister is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Ah, you asking how to call that function on an employee object.

Code:
public static void main(String[] args) { EmployeeClass s1= new EmployeeClass(); s1.display(); EmployeeClass s2= new EmployeeClass("MARY",1111,7500); s2.display(); EmployeeClass s3 = new EmployeeClass(); s3.getdata(); s3.display(); }
yes!!! ty ty now how do you redisplay employee1 data
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 05-05-2008, 05:27 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,168
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
As like this.

Code:
s1.display();
Since you have set the default values, display that. If you want to get the data from the user and display, call the getData() first and then display them.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best?Vote Now

Last edited by Eranga : 05-05-2008 at 05:29 AM.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 05-05-2008, 05:52 AM
Member
 
Join Date: May 2008
Posts: 12
ubermeister is on a distinguished road
Quote:
Originally Posted by Eranga View Post
As like this.

Code:
s1.display();
Since you have set the default values, display that. If you want to get the data from the user and display, call the getData() first and then display them.
thank you very much my last question is how you do step 8?
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 05-05-2008, 05:57 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,168
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Did you create an array of Employee objects? If so, loop them on each and do the same process.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best?Vote Now
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 05-05-2008, 06:25 AM
Member
 
Join Date: May 2008
Posts: 12
ubermeister is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Did you create an array of Employee objects? If so, loop them on each and do the same process.
Code:
EmployeeClass[] students= new EmployeeClass[3]; for(int k =0;k < employee.length; k++) { System.out.printf("\nWorking on employee : %d\n", (k+1)); // create an instance for each member employees[k] = new StudentClass(); employees[k].getdata(); employees[k].display(); employees[k].displayTotal();
thats my array i just don't know what to WRITE for the loops.
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 05-05-2008, 06:31 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,168
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
In simple way you can do this pal.

Code:
EmployeeClass[] collection = new EmployeeClass[] {new EmployeeClass(), new EmployeeClass(), new EmployeeClass()}; for(int i = 0; i < collection.length; i ++) { collection[i].getdata(); } for(int j = 0; j < collection.length; j++) { collection[j].display(); }
What is displayTotal() do. I can't see anything about it.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best?Vote Now
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 05-05-2008, 06:45 AM
Member
 
Join Date: May 2008
Posts: 12
ubermeister is on a distinguished road
i'm taking those out
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 05-05-2008, 06:47 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,168
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Is that what you looking for?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best?Vote Now
Bookmark Post in Technorati
Reply With Quote
  #17 (permalink)  
Old 05-05-2008, 06:51 AM
Member
 
Join Date: May 2008
Posts: 12
ubermeister is on a distinguished road
ya that last bit of code was it now i'm just debugging thanks for all your help!!!
Bookmark Post in Technorati
Reply With Quote
  #18 (permalink)  
Old 05-05-2008, 06:52 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,168
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Oki, do it and let me know what happened. And there are so many way to do this.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best?Vote Now
Bookmark Post in Technorati
Reply With Quote
  #19 (permalink)  
Old 05-05-2008, 07:05 AM
Member
 
Join Date: May 2008
Posts: 12
ubermeister is on a distinguished road
ya theirs a million way to do this yet 1 mistake screws everythign up >_< (i'm more of a networking guy!!)

these are my errors

Code:
C:\Documents and Settings\Beserk\Desktop\TestEmployeeClass.java:24: cannot find symbol symbol : variable employee location: class TestEmployeeClass for(int k =0;k < employee.length; k++) ^ C:\Documents and Settings\Beserk\Desktop\TestEmployeeClass.java:28: cannot find symbol symbol : variable employees location: class TestEmployeeClass employees[k] = new EmployeeClass(); ^ C:\Documents and Settings\Beserk\Desktop\TestEmployeeClass.java:29: cannot find symbol symbol : variable employees location: class TestEmployeeClass employees[k].getdata(); ^ C:\Documents and Settings\Beserk\Desktop\TestEmployeeClass.java:30: cannot find symbol symbol : variable employees location: class TestEmployeeClass employees[k].display();

final code

Code:
public class TestEmployeeClass { public static void main(String[] args) { EmployeeClass s1= new EmployeeClass(); s1.display(); EmployeeClass s2= new EmployeeClass("MARY",1111,75000); s2.display(); EmployeeClass s3 = new EmployeeClass(); s3.getdata(); s3.display(); s1.display(); //array EmployeeClass[] students= new EmployeeClass[3]; for(int k =0;k < employee.length; k++) { System.out.printf("\nWorking on employee : %d\n", (k+1)); // create an instance for each member employees[k] = new EmployeeClass(); employees[k].getdata(); employees[k].display(); EmployeeClass[] collection = new EmployeeClass[] {new EmployeeClass(), new EmployeeClass(), new EmployeeClass()}; for(int i = 0; i < collection.length; i ++) { collection[i].getdata(); } for(int j = 0; j < collection.length; j++) { collection[j].display(); } } } }
Bookmark Post in Technorati
Reply With Quote
  #20 (permalink)  
Old 05-05-2008, 07:14 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,168
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Yes, there is a big error. I can't find any array named employee there. It should be students

Did you use any IDE for coding?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best?Vote Now
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes