wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Noob really needs help please with beginner Assignment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Noob really needs help please with beginner Assignment" Watch "Noob really needs help please with beginner Assignment" New topic
Author

Noob really needs help please with beginner Assignment

Paul Di
Greenhorn

Joined: Feb 09, 2013
Posts: 3
Hello everyone,

Sorry if it seems like I need to be spoon fed because that how I feel. I am usually a quick learner but that does not seem to be the case with java. I am learning C# and feel like I am catching on quickly but I feel very frustrated that I can not even complete my java first assignment.

I have been reading as much as possible and watching the tutorials, I plan to continue to do both.

I am hopeful someone would be kind enough to point me in the right direction so I can complete my assignment. Any help at all would be very much appreciated.

Here is the assignment I need to complete

Assignment 1 is to practice creating classes, attributes, methods, and basic syntax and flow control. There are two parts in this assignment.

Part 1

You will create two classes, Employee and EmployeeTable. Employee represents an employee record in a table of employee records. It will have three attributes: employee number, employee name and salary. Employee class also has methods that allow other objects to change its attributes or print out all its attributes.

EmployeeTable represents a table of employee records with a company. This class has two attributes: the name of company and the actual table that contains all the employee records. The latter can be implemented using a Java library class Hashtable.

The class EmployeeTable will have behavior/methods that allow other objects to call to do the following:

Get the total number of employees in the table
Insert an employee in the table, the employee object being passed to the method
Delete an employee from the table, the employee number being passed to the method
Update an employee in the table, the employee number being passed to the method

Part 2

You will create a test class that instantiates a new EmployeeTable and then loops infinitely to take some user input from console and then allows user to invoke one of the methods of the EmployeeTable to insert, delete or update an employee record in the table. The test program will exit if user enters Q on the console.

Some example output is as follows:

EmpClient.main(): client started...

[L]ist| [A]dd | [E]dit | [D]elete | [Q]uit: a
Adding a new employee...
Enter a string value for empNo: emp-01
Enter a string value for empName: George Bush
Enter a float value for salary: 80000
Employee added:
emp-01, George Bush, 80000.0

[L]ist| [A]dd | [E]dit | [D]elete | [Q]uit: a
Adding a new employee...
Enter a string value for empNo: emp-02
Enter a string value for empName: Greg Harper
Enter a float value for salary: 50000
Employee added:
emp-02, Greg Harper, 50000.0

[L]ist| [A]dd | [E]dit | [D]elete | [Q]uit: a
Adding a new employee...
Enter a string value for empNo: emp-03
Enter a string value for empName: Brad Linsley
Enter a float value for salary: 45000
Employee added:
emp-03, Brad Linsley, 45000.0

[L]ist| [A]dd | [E]dit | [D]elete | [Q]uit: l
Listing all employees...
3 employees found:
emp-03, Brad Linsley, 45000.0
emp-02, Greg Harper, 50000.0
emp-01, George Bush, 80000.0

[L]ist| [A]dd | [E]dit | [D]elete | [Q]uit: e
Editing an employee...
Enter a string value for empNo: emp02
No record exists for emp02

[L]ist| [A]dd | [E]dit | [D]elete | [Q]uit: e
Editing an employee...
Enter a string value for empNo: emp-02
Enter a new string value for empName: Brad Linsle
Enter a new float value for salary: 55000
Employee updated:
emp-02, Brad Linsley, 55000.0

[L]ist| [A]dd | [E]dit | [D]elete | [Q]uit: d
Deleting an employee...
Enter a string value for empNo: emp-01
Employee deleted:
emp-01, George Bush, 80000.0

[L]ist| [A]dd | [E]dit | [D]elete | [Q]uit: l
Listing all employees...
2 employees found:
emp-03, Brad Linsley, 45000.0
emp-02, Brad Linsley, 55000.0

[L]ist| [A]dd | [E]dit | [D]elete | [Q]uit: q
EmpClient.main(): client exiting...
Done.


Question about part 1,
It will have three attributes: employee number, employee name and salary. Employee class also has methods that allow other objects to change its attributes or print out all its attributes.

Is it as simple at this?
private String empName;
private int empNo;
private double empSalary;

I am having an issue getting the employee Class started.

template for EmployeeTable. I have started the update method. I don't really understand what is being passed in to the method to be honest.


Part 2: Test class started (some of this was provided in a template and I realize the is code that needs to be added in the switch statement. Case L needs System.out.println(table.toString()); etc.


If anyone could help me out, I would greatly appreciate it. In the mean time I will continue to read until my eyes bleed. Thank you for your time.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7536
    
  18

Paul Di wrote:Question about part 1,
It will have three attributes: employee number, employee name and salary. Employee class also has methods that allow other objects to change its attributes or print out all its attributes.

Is it as simple at this?
private String empName;
private int empNo;
private double empSalary;

Yup. And well done for avoiding the "beginners 101" mistake of making everything a String.

I am having an issue getting the employee Class started...

The above looks pretty good to me. Do that; get your constructors sorted out; add any getters and setters you think you might need (Tip: be especially careful about adding setters if you don't need them - my technique: don't add them until you need them); and then get started on the "beef" (ie, the methods that actually do something).

I hate to say, but that's too much code to go through. Get your class started and come back with a specific question when/if you have problems.

Another good tip from one of my colleagues here: Don't write more than 10 lines of code without compiling it.

HIH

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Paul Di
Greenhorn

Joined: Feb 09, 2013
Posts: 3
So I am slowly making some progress but I am having some issues. I am trying to pass an object as the value to the hash table, however when I hit "L" for list and try to print out the hash table I only see what ever value is entered for "please enter employee ID number". Just wondering if you could give me an idea what I am doing wrong. I know there is other methods still to fill out but for now I am just working on adding employees to the hash table and printing out a list of the employees that have been added to the hash table.

test class


EmployeeTable class


Employee Class


Sample of the output
Paul Di
Greenhorn

Joined: Feb 09, 2013
Posts: 3
Well I did get the issue solved. It was just a matter of needing to override the toString() method in the Employee class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Noob really needs help please with beginner Assignment
 
Similar Threads
Problem with ContainsKey(obj key) in HashMap
Bean setters not invoked when no data entered in form fields
Hibernate Criteria Ambiguos
Need Help:How to port HashMap<String-ColmnName, ArayList-ClumnData> to Datatable for multiple colmns
Return multiple fields aas 1 object