Question

**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a...

**JAVA LANGUAGE**

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 an Employee, a Name, an Address, and a Date classes in your solution. 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. To keep things simple, your classes don’t need to do any editing of data. 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 to enter data for several employees, store the data in an array of type Employee, and then display the data.

Homework Answers

Answer #1

SOLUTION-
I have solve the problem in Java code with comments and screenshot for easy understanding :)

CODE-

//java code
import java.util.Scanner;
//class Mydata
class MyDate {
//Declaring instance variables
private int year;
private int month;
private int day;

//Parameterized constructor
public MyDate(int year, int month, int day) {
super();
this.year = year;
this.month = month;
this.day = day;
}

//getters and setters
public int getYear() {
return year;
}

public void setYear(int year) {
this.year = year;
}

public int getMonth() {
return month;
}

public void setMonth(int month) {
this.month = month;
}

public int getDay() {
return day;
}

public void setDay(int day) {
this.day = day;
}

@Override
public String toString() {
return month + "/" + year + "/" + day;
}


}
class Employee {

// Declaring variables
private int employeeNumber;
private String name;
private MyDate hireDate;
private String address;

//Parameterized constructor
public Employee(int employeeNumber, String name, MyDate hireDate,
String address) {
super();
this.employeeNumber = employeeNumber;
this.name = name;
this.hireDate = hireDate;
this.address = address;
}

//getters and setters
public int getEmployeeNumber() {
return employeeNumber;
}
public void setEmployeeNumber(int employeeNumber) {
this.employeeNumber = employeeNumber;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public MyDate getHireDate() {
return hireDate;
}
public void setHireDate(MyDate hireDate) {
this.hireDate = hireDate;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}

//toString method is used to display the contents of an object inside it
@Override
public String toString() {
return "Employee Number=" + employeeNumber + "\nName=" + name + "\nHire Date=" + hireDate + "\nAddress=" + address;
}

}

public class Main {

public static void main(String[] args) {

//Declaring variables

String name, address;

int employeeNO;

int mon, day, year, size;

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

System.out.print("How many Employees data you want to enter :");

size = sc.nextInt();

//Creating an Array of Employee class

Employee emp[] = new Employee[size];

//Getting the Employee info

for (int i = 0; i < size; i++) {

//Getting the input entered by the user

System.out.println("Employee#" + (i + 1) + ":");

sc.nextLine();

System.out.println("Enter Full name :");

name = sc.nextLine();

System.out.println("Enter Employee No :");

employeeNO = sc.nextInt();

sc.nextLine();

System.out.println("Enter Address :");

address = sc.nextLine();

while (true) {

System.out.print("Enter Month :");

mon = sc.nextInt();

if (mon < 1 || mon > 12) {

System.out.println("** Invalid.Must be between 1-12 **");

continue;

} else

break;

}

while (true) {

System.out.print("Enter Day :");

day = sc.nextInt();

if (day < 1 || day > 31) {

System.out.println("** Invalid.Must be between 1-31 **");

continue;

} else

break;

}

while (true) {

System.out.print("Enter Year :");

year = sc.nextInt();

if (year < 1900 || year > 2020) {

System.out.println("** Invalid.Must be between 1900-2020 **");

continue;

} else

break;

}

MyDate md = new MyDate(year, mon, day);

//Creating an Employee class object and populate them into an array

emp[i] = new Employee(employeeNO, name, md, address);

}

//Displaying each employee info

System.out.println("Dsipalying the Employees Info");

for (int i = 0; i < size; i++) {

System.out.println("Employee#" + (i + 1) + ":");

System.out.println(emp[i].toString());

}

}

}


SCREENSHOT-

IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
JAVA Learning Objectives: To be able to code a class structure with appropriate attributes and methods....
JAVA Learning Objectives: To be able to code a class structure with appropriate attributes and methods. To demonstrate the concept of inheritance. To be able to create different objects and use both default and overloaded constructors. Practice using encapsulation (setters and getters) and the toString method. Create a set of classes for various types of video content (TvShows, Movies, MiniSeries). Write a super or parent class that contains common attributes and subclasses with unique attributes for each class. Make sure...
Consider the following code snippet: Employee programmer = new Employee(10254, "exempt"); String str = programmer.toString(); Assume...
Consider the following code snippet: Employee programmer = new Employee(10254, "exempt"); String str = programmer.toString(); Assume that the Employee class has not implemented its own toString() method. What value will the variable str contain when this code is executed? Group of answer choices the variable will become a null reference the code will not compile because Employee has not implemented toString() the default from Object, which is the class name of the object and its hash code the string representations...
Java Programming COMP-228 LAB ASSIGNMENT #1 >> Apply the naming conventions for variables, methods, classes, and...
Java Programming COMP-228 LAB ASSIGNMENT #1 >> Apply the naming conventions for variables, methods, classes, and packages: - variable names start with a lowercase character for the first word and uppercase for every other word - classes start with an uppercase character of every word - packages use only lowercase characters - methods start with a lowercase character for the first word and uppercase for every other word Java Programming COMP-228 Exercise #1: [5 marks] Write a Java application using...
Java Program Implement a class called AnimalTrainer. Include the following data types in your class with...
Java Program Implement a class called AnimalTrainer. Include the following data types in your class with the default values denoted by dataType name : defaultValue - String animal : empty string - int lapsRan : 0 - boolean resting : false - boolean eating : false - double energy : 100.00 For the animal property implement both getter/setter methods. For all other properties implement ONLY a getter method Now implement the following constructors: 1. Constructor 1 – accepts a String...
Write a Java program that reads employee information from the file “employee.txt” then the program will...
Write a Java program that reads employee information from the file “employee.txt” then the program will display his/her information on the screen. The file contains the Employee’s Name, age,join date, quit date, and salary. • For each year the employee is in the company,10 days of sick leave are allowed. So, if an employee is in the company for two years, 20 days of sick leave are allowed. • For each year the employee is in the company, one-month salary...
Has to be written in C#! Write a program that includes an Employee class that can...
Has to be written in C#! Write a program that includes an Employee class that can be used to calculate and print the take-home pay for a commissioned sales employee. Items to include as data members are employee number, first name, last name, and total sales. All employees receive 9% of the total sales of the month. Federal tax rate is 18%. Retirement contribution is 10%. Social Security tax rate is 6%. Use appropriate constants, design an object-oriented solution, and...
Write a program in Java that: 1. will prompt user with a menu that contains options...
Write a program in Java that: 1. will prompt user with a menu that contains options to: a. Add a To-Do Item to a todo list. A To-Do Item contains: i. An arbitrary reference number (4; 44,004; etc.) ii. A text description of the item ("Pick up dry cleaning", etc.) iii. A priority level (1, 2, 3, 4, or 5) b. View an item in the list (based on its reference number) c. Delete an item from the list (based...
IN JAVA Inheritance Using super in the constructor Using super in the method Method overriding Write...
IN JAVA Inheritance Using super in the constructor Using super in the method Method overriding Write an application with five classes Vehicle, Car, Bus, Truck, and Tester class with main method in it. The following characteristics should be used: make, weight, height, length, maxSpeed, numberDoors, maxPassenges, isConvertable, numberSeats, maxWeightLoad, and numberAxels. Characteristics that are applicable to all vehicles should be instance variables in the Vehicle class. The others should be in the class(s) where they belong. Class vehicle should have...
Write a complete Java program which prompts the user of the program to input his/her first...
Write a complete Java program which prompts the user of the program to input his/her first name, then prompts the user for the middle initial and finally prompts the user for the last name. As indicated, there are three prompts to the user. The program should output the user’s name with the first name first, followed by the middle initial, and the last name last, all on one line (with appropriate spacing). If you could also pinpoint exactly where to...
The following is for a Java Program Create UML Class Diagram for these 4 java classes....
The following is for a Java Program Create UML Class Diagram for these 4 java classes. The diagram should include: 1) All instance variables, including type and access specifier (+, -); 2) All methods, including parameter list, return type and access specifier (+, -); 3) Include Generalization and Aggregation where appropriate. Java Classes description: 1. User Class 1.1 Subclass of Account class. 1.2 Instance variables __ 1.2.1 username – String __ 1.2.2 fullName – String __ 1.2.3 deptCode – int...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT