• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Employee class  RSS feed

 
Greenhorn
Posts: 3
  • 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).
 
Sheriff
Posts: 13454
222
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: 13454
222
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: 13454
222
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: 13454
222
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: 13454
222
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!
 
Bartender
Posts: 1203
81
Angular Framework AngularJS Eclipse IDE Hibernate Java jQuery MySQL Database 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.
 
Hey cool! They got a blimp! But I have a tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!