Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Employee class  RSS feed

 
Amber Green
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Working on a simple Java assignment but not sure if I'm totally off or have correct code. Take a look and let me know!

The required functionality & components are:
1. An Employee class that contains data about individual employees
a. Fields:
i. Strings: lastName, firstName, department
ii. ints: id, jobCode
b. Methods:
i. Set: One “set” method (e.g., setLastName) for each field, which accepts the field’s type as a parameter and sets the field’s value to that parameter
ii. Get: One “get” method (e.g., getLastName) for each field, with the same return type as the field (e.g, a String for getLastName) and leaves the field unchanged
2. A Database class that maintains records of employees:
a. Method shells (headers only, no method bodies required yet)
i. match: Requires two Strings as parameters, named field and matchValue. Returns a boolean value. You may include a return false statement in the method body to remove the error caused by the missing return type.
ii. modify: Requires two Strings as parameters, named field and newValue. Returns nothing (void).
iii. add: Requires three Strings (named lastName, firstName, and department), two ints (named id and jobCode), and an Employee array (e) as parameters. Returns void.
iv. delete: Requires three Strings (named lastName, firstName, and department), two ints (named id and jobCode), and an Employee array (e) as parameters. Returns void.
v. read: Requires three Strings (named lastName, firstName, and department), two ints (named id and jobCode), and an Employee array (e) as parameters. Returns void.


The program should be written as a single .java file (the Employee class should be included in the Database.java file, after the Database class declaration).
 
Junilu Lacar
Sheriff
Posts: 11146
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A few things that are not right:

1. If you have a file called Foo.java, it should contain a public class Foo { ... } declaration. Your instructions are to put all your classes in Database.java. So, given what I just said, what should you declare as public class in that file?

2. The public class is what normally has the public static void main() method.

3. Carefully review your requirements for the Database methods. A few of the methods you wrote don't match the specifications given.
 
Junilu Lacar
Sheriff
Posts: 11146
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, what part of those requirements made you declare the variables for Database on lines 7 to 10?
 
Junilu Lacar
Sheriff
Posts: 11146
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The required functionality & components are:
...
ii. modify: Requires two Strings as parameters, named field and newValue. Returns nothing (void).

Your implementation:


All the other methods after this one don't have any types declared for the parameters. That code won't even compile.
 
Junilu Lacar
Sheriff
Posts: 11146
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lastly,
 
Junilu Lacar
Sheriff
Posts: 11146
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Welcome to the Ranch!
 
Ganesh Patekar
Bartender
Posts: 696
23
Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fields of Employee better to be accessed through methods only so declare them with private access modifier rather than public.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!