• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Implement a class Employee

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you have so far?
 
Rob Samberg
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic