Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I have a java pkg with this different classes to answer the following assignment: Write a program that models an employee. An employee has

Hi, I have a java pkg with this different classes to answer the following assignment:

Write a program that models an employee. An employee has an employee number, a name, an address, and a hire date. A name consists of a first name and a last name. An address consists of a street, a city, a state (2 characters), and a 5-digit zip code. A date consists of an integer month, day and year. All fields are required to be non-blank. The Date fields should be reasonably valid values (ex. month 1-12, day 1-31, year > 1900 and < 2020). Issue appropriate error messages when incorrect data is entered. Create public Employee, Name, Address, and Date classes in your solution. Also create an application class named EmployeeDB which will use the previously listed classes, contain the applications main() method, contain an array of Employee objects, and perform all the user interaction. Each class should be in its own Java source file. You may use the Date class from the lectures or define your own. The Java-supplied Date class cannot be used. Provide appropriate class constructors, getter methods, setter methods, toString() and any other methods you think are necessary. The classes should not do any direct user input/output. All user input/output will be done in the main method. Your program should prompt the user for the number of employees to enter then prompt to enter data for the number of employees specified, storing the data in an array of type Employee. Upon program exit, the detailed data of each employee should be displayed to the terminal.

They worked fine all in one file, having trouble separating them.

I get the following errors:

error: cannot find symbol

Employee[] EmpArr;

^

symbol: class Employee

location: class EmployeesSystem

pkg/EmployeesSystem.java:22: error: cannot find symbol

EmpArr = new Employee[n];

^

symbol: class Employee

location: class EmployeesSystem

pkg/EmployeesSystem.java:25: error: cannot find symbol

EmpArr[i] = new Employee();

^

symbol: class Employee

location: class EmployeesSystem

pkg/EmployeesSystem.java:63: error: cannot find symbol

Name xName;

^

symbol: class Name

location: class EmployeesSystem

pkg/EmployeesSystem.java:64: error: cannot find symbol

Address xAddr;

^

symbol: class Address

location: class EmployeesSystem

pkg/EmployeesSystem.java:65: error: cannot find symbol

Date xHireDate;

^

symbol: class Date

location: class EmployeesSystem

And here are all the class files.

import java.util.Scanner;

import java.util.Scanner;

public class EmployeesSystem

{

public static void main(String[] args)

{

//Set the number of employees

System.out.println("Enter the Number of Employees: ");

Scanner scnr = new Scanner(System.in);

int n = scnr.nextInt();

// enter the values

//System.out.println("Enter the Data in Employee Array ");

int Id;

String first, last;

int month, day, year;

String streetNum, street, streetType, city, state;

int zip;

// Now creating Employee array of Size n

Employee[] EmpArr;

EmpArr = new Employee[n];

for (int i = 0; i < n; i++)

{

EmpArr[i] = new Employee();

System.out.println(" Enter the details for theEmployee "+(i+1));

System.out.println("Enter the Employee ID ");

Id = scnr.nextInt();

System.out.println("Enter the Employee First Name and Last Name ");

first = scnr.next();

last = scnr.next();

while (true)

{

System.out.println("Enter the Employee Hire Date "

+ ",i.e 3 11 2018, separated by a space");

month = scnr.nextInt();

day = scnr.nextInt();

year = scnr.nextInt();

if (month < 1 || month > 12 || day < 1 || day > 31

|| year < 1900 || year > 2020)

System.out.println("Invalid date. Please input again ");

else

break;

}

System.out.println("Enter the Address "

+ ",i.e street number, stree name, stree type, city, state and zip "

+ "separated by a space");

streetNum = scnr.next();

street = scnr.next();

streetType = scnr.next();

city = scnr.next();

state = scnr.next();

zip = scnr.nextInt();

EmpArr[i].setEmpId(Id);

EmpArr[i].setEmpName(first, last);

EmpArr[i].setHireDate(month, day, year);

EmpArr[i].setEmpAddress(streetNum, street, streetType, city, state,

zip);

scnr.nextLine();

}

// Now Print the Employee Data

Name xName;

Address xAddr;

Date xHireDate;

for (int i = 0; i < n; i++)

{

Id = EmpArr[i].getEmpNumb();

xName = EmpArr[i].getEmpName();

xAddr = EmpArr[i].getEmpAddress();

xHireDate = EmpArr[i].getHireDate();

System.out.println("Id " + Id + " Name " + xName.first + " "

+ xName.last);

System.out.println("Address : " + xAddr.streetNum + " "

+ xAddr.street + " " + xAddr.streetType + ", " + xAddr.city

+ " , " + xAddr.state + "," + xAddr.zip);

System.out.println("Hire Date: " + xHireDate.month + "-"

+ xHireDate.day + "-" + xHireDate.year);

System.out.println();

System.out.println();

}

}

}

package pkg;

import java.util.Scanner;

public class Address

{

public String streetNum = " ";

public String street = " ";

public String streetType = " ";

public String city = " ";

public String state = " ";

public int zip = 0;

public Address()

{

streetNum = " ";

street = " ";

streetType = " ";

city = " ";

state = " ";

zip = 0;

}

public String getStreetNum()

{

return streetNum;

}

public String getStreet()

{

return street;

}

public String getStreetType() {

return streetType;

}

public String getCity() {

return city;

}

public String getState() {

return state;

}

public int getZip()

{

return zip;

}

public void setAddress(String streetNum, String street,

String streetType, String city, String state, int zip)

{

this.streetNum = streetNum;

this.street = street;

this.streetType = streetType;

this.city = city;

this.state = state;

this.zip = zip;

}

}

package pkg;

import java.util.Scanner;

public class Date

{

public int month = 0;

public int day = 0;

public int year = 0;

public Date()

{

month = 0;

day = 0;

year = 0;

}

public int getMonth()

{

return month;

}

public void setMonth(int month)

{ // if clause to check the month

if (month < 1 || month > 12)

System.out.println("Invalid Month");

else

this.month = month;

}

public int getDay()

{

return day;

}

public void setDay(int day)

{ // if clause to check the date

if (day < 1 || day > 31)

System.out.println("Invalid Day");

else

this.day = day;

}

public int getYear()

{

return year;

}

public void setYear(int year)

{// if clause to check the year

if (year < 1900 || year > 2020)

System.out.println("Invalid year");

else

this.year = year;

}

public void setDate(int month, int day, int year)

{

setMonth(month);

setDay(day);

setYear(year);

}

}

package pkg;

import java.util.Scanner;

public class Employee

{

private int EmpNumb = 0;

private Name EmpName;

private Address EmpAddress;

private Date HireDate;

public Employee()

{

EmpNumb = 0;

EmpName = new Name();

EmpAddress = new Address();

HireDate = new Date();

}

public int getEmpNumb()

{

return EmpNumb;

}

public Name getEmpName()

{

EmpName.first = EmpName.getFirst();

EmpName.last = EmpName.getLast();

return EmpName;

}

public Address getEmpAddress()

{

EmpAddress.streetNum = EmpAddress.getStreetNum();

EmpAddress.street = EmpAddress.getStreet();

EmpAddress.streetType = EmpAddress.getStreetType();

EmpAddress.city = EmpAddress.getCity();

EmpAddress.state = EmpAddress.getState();

EmpAddress.zip = EmpAddress.getZip();

return EmpAddress;

}

public Date getHireDate()

{

HireDate.month = HireDate.getMonth();

HireDate.day = HireDate.getDay();

HireDate.year = HireDate.getYear();

return HireDate;

}

public void setEmpId(int Id)

{

EmpNumb = Id;

}

public void setEmpName(String first, String last)

{

EmpName.setName(first, last);

}

public void setHireDate(int month, int day, int year)

{

HireDate.setDate(month, day, year);

}

public void setEmpAddress(String streetNum, String street,

String streetType, String city, String state, int zip)

{

EmpAddress.setAddress(streetNum, street, streetType, city, state,

zip);

}

}

package pkg;

import java.util.Scanner;

public class Name

{

public String first = " ";

public String last = " ";

public Name()

{

first = " ";

last = " ";

}

public String getFirst()

{

return first;

}

public String getLast() {

return last;

}

public void setName(String first, String last)

{

this.first = first;

this.last = last;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 25th European Conference Adbis 2021 Tartu Estonia August 24 26 2021 Proceedings Lncs 12843

Authors: Ladjel Bellatreche ,Marlon Dumas ,Panagiotis Karras ,Raimundas Matulevicius

1st Edition

3030824713, 978-3030824716

More Books

Students also viewed these Databases questions

Question

Prepare and properly label figures and tables for written reports.

Answered: 1 week ago