BEGINNER Java payroll

  • (5 Pages)
  • +
  • « First
  • 3
  • 4
  • 5

64 Replies - 11699 Views - Last Post: 21 June 2009 - 06:56 PM Rate Topic: -----

#61 inf4mi5   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 14-June 09

Re: BEGINNER Java payroll

Posted 19 June 2009 - 09:43 AM

Okay. So I read up on Objects and Constructors. From my understanding, I need to create an Object, then store the information in that object. And lastly, call that Object with a Constructor. Am I getting closer?

This is my first attempt at creating the Object "Employee". Am I missing anything?
import java.util.Scanner;
	public class Employee {
		Object Employee = new Employee			
	
	}	


This post has been edited by inf4mi5: 19 June 2009 - 10:18 AM

Was This Post Helpful? 0
  • +
  • -

#62 pillpusher   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 48
  • Joined: 13-May 09

Re: BEGINNER Java payroll

Posted 19 June 2009 - 11:22 AM

View Postinf4mi5, on 19 Jun, 2009 - 10:43 AM, said:

Okay. So I read up on Objects and Constructors. From my understanding, I need to create an Object, then store the information in that object. And lastly, call that Object with a Constructor. Am I getting closer?


Closer. An object is "instantiated" from a class (in other words it is an instance of a class). What you should do is create the "Employee" objects from your main class.

This is how your Employee class might look:

public class Employee {

		   Employee(String nameIn, double hoursIn, double rateIn) {
				   String name = nameIn;
				   double hours = hoursIn;
				   double rate = rateIn;
				   double totalPay = hours * rate;
			} //end constructor

} // end Employee class



To create one of these "Employee" objects, you put the following code in your PayRoll.java file

Employee someNewEmployee = new Employee("John Doe", 40.00, 10.00);



Now you have one new "Employee" object with a name, hours, rate, and total pay. You access those variables by using the object name then a "dot" then the variable name. ex:

someNewEmployee.totalPay

will give you the totalPay for that employee.

Now your next problem is that in order to store all the employees, you'll need to put them in an array of Employee objects or a Vector or an ArrayList.

Good Luck!

This post has been edited by pillpusher: 19 June 2009 - 08:29 PM

Was This Post Helpful? 1
  • +
  • -

#63 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: BEGINNER Java payroll

Posted 19 June 2009 - 06:31 PM

62 replies for a "Beginner Java Payroll"
you guys should start to think about openening your own forum :D
Was This Post Helpful? 0
  • +
  • -

#64 inf4mi5   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 14-June 09

Re: BEGINNER Java payroll

Posted 21 June 2009 - 09:41 AM

hahaha the reason for so many replies is probably because I'm such a slow learner. ^_^
Was This Post Helpful? 0
  • +
  • -

#65 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: BEGINNER Java payroll

Posted 21 June 2009 - 06:56 PM

View Postinf4mi5, on 21 Jun, 2009 - 08:41 AM, said:

hahaha the reason for so many replies is probably because I'm such a slow learner. ^_^

May be but nobody will have the patience to scan +60 posts tring to help you
Topic closed... if you haven't understood in 60 topics you will never :D
and there is no "pedagogic" reason to keep a topic open for more than 3 pages
Was This Post Helpful? 0
  • +
  • -

  • (5 Pages)
  • +
  • « First
  • 3
  • 4
  • 5