Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Java Employee Class and HR Class Programs

$
0
0
Hi everyone! I need some help with these two programs /: I have attempted both but I know that they are both incomplete. If somebody could help me with both programs it would be much appreciated!!

Part I: (50 pts) Create a Employee class with the following:

A private String variable named “fName” to store the Employee's first name
A private String variable named “mName” to store the Employee’s middle name
A private String variable named “lName” to store the Employee’s last name
A private String variable named “ID” that contains the unique ID number for this Employee
A private String variable named “title” to store the Employee's title in a company
A private String variable named “startDate” to store the Employee's starting date in the company
A public constructor Employee() which will set default names, ID, title, and startDate. You may set them as NULL if needed.
Several public set methods:
SetNames(String name) will store the first word in name to fName, last word to lName, and if the name contains a middle name, store in mName. (Note: it is possible that the input String has just two words, but never 4 or more words.)
SetID(String id) will check whether id is a valid ID in the format of xxx-xx-xxxx where x is a single digit. If so, it will set the ID accordingly. Otherwise, give a message and do not change the ID.
SetTitle(String t) will check whether t is a valid title. You may pre-set at least three different titles. If t is one of these titles, it will set the title accordingly. Otherwise, give a message and do not change the title.
SetStartDate(String date) will set the startDate if the input String is in the format of MM/DD/YYYY and also with valid date. E.g., 02/30/1999 is not a valid date since February does not have 30 days, while Feb 12, 1999 is not a valid format. You should allow user to input date without unnecessary 0 in it, e.g., 2/3/1999 is valid.
A set of Get methods to retrieve the name/ID/role/StartDate info.
A public method toString() returns a String in the following format:
Name: Last name, first name
Title: title
ID: xxx-xx-xxxx
Starting Date: MM/DD/YYYY

Attempt:
public class Employee {
	private String fName;
	private String mName;
	private String lName;
	private String ID;
	private String title;
	private String startDate;
	
	public Employee (String fName1, String mName1, String lName1, String ID1, String title1, String startDate1) {
		fName = fName1;
		mName = mName1;
		lName = lName1;
		ID = ID1;
		title = title1;
		startDate = startDate1;
}
	
	private String getfName() {
		return fName;
	}
	
	private String getmName() {
		return mName;
	}
	
	private String getlName() {
		return lName;
	}
	
	public void setName (String Name1, String Name2, String Name3) {
		fName = Name1;
		mName = Name2;
		lName = Name3;
	}
	
	private String getID() {
		return ID;
	}
	
	public void setID (String employeeID) {
		ID = employeeID;
	}
	
	private String gettitle() {
		return title;
	}
	
	public void settitle (String employeeTitle) {
		title = employeeTitle;
	}
	
	private String getstartDate() {
		return startDate;
	}
	
	public void setstartDate (String employeeStartDate) {
		startDate = employeeStartDate;
	}
	
	public void print () {
		System.out.println(fName + mName + lName);
		System.out.println(ID);
		System.out.println(title);
		System.out.println(startDate);
	}

}




Part II: (50 pts) In a separate file, named HR.java, create a class named HR. It will read in all personnel info from a file. The first line of the file contains a number indicating how many employees information are specified in the file. And the rest in the file contains information of each individual Employee. The HR class will receive the name of this file through command line argument, create an array to store Employees info, read in the information from the file, and save these Employees' info to another file in a better format via calling the toString method. In addition, it will count how many Employees are with the same title and print out these numbers on the screen.

Attempt:
package textfiles;

import java.io.IOException;
import java.io.FileReader;
import java.io.BufferedReader;

public class HR {
	
	private String path;
	
	public HR (String file_path) {
		path = file_path;
	}
	
	public String[] OpenFile() throws IOException {
		
		FileReader fr = new FileReader(path);
		BufferedReader textReader = new BufferedReader (fr);
		
		int numberOfLines = readLines();
		String[] textData = new String[numberOfLines];
		
		int i;
		
		for (i = 0; i < numberOfLines; i++) {
			textData[i] = textReader.readLine();
		}
		
		textReader.close();
		return textData;
	}
	
	int readLines() throws IOException {
		
		FileReader file_to_read = new FileReader(path);
		BufferedReader bf = new BufferedReader(file_to_read);
		
		String aLine;
		int numberOfLines = 0;
		
		while ((aLine = bf.readLine()) != null) {
			
		}
		bf.close();
		
		return numberOfLines;
	}

}




And I don't know how to relate the HR file to the Employee Class /:

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>