Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implement a class Employee

 
Rob Samberg
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An employee has a name (a string) and salary (a double). I'm supposed to write a default constructor, a constructor with two parameters (name and salary), and methods to return the name and salary. Then I have to write a small program that tests my class.
Please help!!!
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you have so far?
 
Rob Samberg
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did mention I'm brand new to this I hope. Well I am. I really don't know what the heck I'm doing. I'd appreciate anything at all that you think might help!
I don't mind reading and figuring stuff out, but I don't even know where to look.
Thanks,
Rob
[code]
public class Employee
{

public Employee()
{
name = "unknown";
}

public Employee()
{
salary = 0;
}


public class EmployeeTester
{

public EmployeeTester ()
{
name = "Robert Samberg";
salary = 50000;

System.out.println("name" "salary")

public void newSalary(double amount)
{
double newSalary = salary + (salary/20.0);
salary = newSalary;
}
[code]

Can someone tell me what if anything is right with this code?
[ January 28, 2006: Message edited by: Rob Samberg ]
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I'll try to help a little with what you do have. I'll start with the Emplyee class:

The Java compiler won't let you do this. If you have two constructors they must have different signitures meaning, the must take a different number or type of parameters. These two constructors should be combined to give you your default constructor:

As for this bit:

You should avoid putting a main() method into this class at all, leave that for your EmployeeTester class. Instead you should write getter and setter methods to access your Employee object's name and salary i.e. getName(), setName(), getSalary(), setSalary(). These methods can be called by the main() method in your EmployeeTester class to mutate and access information regarding any Employee object. Hope this can get you started.

Garrett
 
Rob Samberg
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok - that's great - I'm going to work on that for a while. Thanks. If you can think of anything else that might help, even if it's just general Java stuff for a beginner, I'd appreciate it.
Thanks again.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Samberg:
... If you can think of anything else that might help, even if it's just general Java stuff for a beginner, I'd appreciate it...

Use Code Tags to preserve your formatting.
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you guys using an IDE? Creating getters and setters are catchy the first two times after that it is just tiresome. IDE's will help a lot with that.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gerardo Tasistro:
Are you guys using an IDE? Creating getters and setters are catchy the first two times after that it is just tiresome. IDE's will help a lot with that.


IMO for a beginner, it is necessary to write getters and setters by hand. No IDE, just a text editor. In much the same way that many simple arithmetic problems can be solved on a calculator, it is a lot more educational to learn to do it yourself first. You know "Give a man a fish..."
[ January 28, 2006: Message edited by: Garrett Rowe ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic