Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that models an employee. An employee has an employee number, a n

ID: 3675466 • Letter: W

Question

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. Be sure to comment your code and use the course code formatting style.

Explanation / Answer

main.java

//import java. util.*;
import java.io.*;
import java.util.Scanner;
public class main
{
   public static void main(String[]args)
   {
       Employee employee = new Employee();
       int nID = 0;
       Name name = new Name();
       Address address = new Address();
       Date date = new Date();
      
      
      Scanner in = new Scanner(System.in);

      System.out.println("How many employees were hired");
     int x = in.nextInt();
       //int x = Input.getInt("How many employees were hired?");
       for(nID = 1; nID <= x; nID++)
       {
           //String f = Input.getString("Enter employee " + nID + "'s first name");
           System.out.println("Enter employee " + nID + "'s first name");
     String f = in.nextLine();
   
           //String l = Input.getString("Enter employee " + nID + "'s last name");
           System.out.println("Enter employee " + nID + "'s last name");
     String l = in.nextLine();
           //String c = Input.getString("Enter employee " + nID + "'s city's name");
           System.out.println("Enter employee " + nID + "'s city's name");
     String c = in.nextLine();
           //String s = Input.getString("Enter employee " + nID + "'s street's name");
           System.out.println("Enter employee " + nID + "'s street's name");
     String s = in.nextLine();
           //int n = Input.getInt("Enter employee " + nID + "'s street address number");
           System.out.println("Enter employee " + nID + "'s street address number");
     int n = in.nextInt();
           //String t = Input.getString("Enter employee " + nID + "'s state's initials");
           System.out.println("Enter employee " + nID + "'s state's initials");
     String t = in.nextLine();
           //String z = Input.getString("Enter employee " + nID + "'s five-digit zip code");
           System.out.println("Enter employee " + nID + "'s five-digit zip code");
     String z = in.nextLine();
       //   String d = Input.getString("Enter employee " + nID + "'s hire date in the form MM/DD/YYYY");
           System.out.println("Enter employee " + nID + "'s hire date in the form MM/DD/YYYY");
     String d = in.nextLine();
           name.setFirst(f);
           name.setLast(l);
          
          
          
           address.setCity(c);
           address.setStreet(s);
           address.setState(t);
           address.setNumber(n);
           address.setZip(z);
           date.setDate(d);
           employee.setName(name);
           employee.setAddress(address);
           employee.setDate(date);
           employee.setID(nID);
           System.out.println();
           display(employee);
       }
   }
   public static void display(Employee employee)
   {
       Name A = employee.getName();
       Address B = employee.getAddress();
       Date C = employee.getDate();
       System.out.println("Employee " + employee.getID() + ":");
       System.out.println("Name: " + A.getFirst() + " " + A.getLast());
       System.out.println("Address: " + B.getNumber() + " " + B.getStreet() + ", " + B.getCity() + " " + B.getState() + ", " + B.getZip());
       System.out.println("Hire date: " + C.getMonth() + " " + C.getDay() + ", " + C.getYear());
   }
}

Employee.java

import util.*;

public class Employee
{
   int nID;
   Name name = new Name();
   Address address = new Address();
   Date date = new Date();
   public void setName(Name name)
   {
       this.name = name;
   }
   public void setDate(Date date)
   {
       this.date = date;
   }
   public void setAddress(Address address)
   {
       this.address = address;
   }
   public void setID(int nID)
   {
       this.nID = nID;
   }
   public Name getName()
   {
       return name;
   }
   public Date getDate()
   {
       return date;
   }
   public Address getAddress()
   {
       return address;
   }
   public int getID()
   {
       return nID;
   }
}


Address.java

public class Address {
   String city;
   String street;
   String state;
   int streetnum;
   String zip;
   public void setCity(String c)
   {
       city = c;
   }
   public void setStreet(String s)
   {
       street = s;
   }
   public void setNumber(int a)
   {
       streetnum = a;
   }
   public void setZip(String z)
   {
       zip = z.substring(0,5);
   }
   public void setState(String t)
   {
       t = t.toUpperCase();
       state = t.substring(0,2);
   }
   public String getCity()
   {
       return city;
   }
   public String getStreet()
   {
       return street;
   }
   public int getNumber()
   {
       return streetnum;
   }
   public String getZip()
   {
       return zip;
   }
   public String getState()
   {
       return state;
   }
}

Date.java

public class Date {
   String month;
   int day;
   int year;
   public void setDate(String date)
   {
       String months[] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
       char Number[] = {'0','1','2','3','4','5','6','7','8','9'};
       if(date.charAt(0) == '0')
       {
           for(int j = 1; j < Number.length; j++)
           {
               if(date.charAt(1) == Number[j])
               {
                   month = months[j-1];
               }
           }
       }
       if(date.charAt(0) == '1')
       {
           for(int j = 1; j<=3; j++)
           {
               if(date.charAt(1) == Number[j])
               {
                   month = months[j+9];
               }
           }
       }
       if(date.charAt(3) == '0')
       {
           day = ((int)date.charAt(4) - 48);
       }
       if((date.charAt(3) == '0') == false);
       {
           day = ((int)(date.charAt(3)) - 48)*10 + ((int)date.charAt(4) - 48);
       }
       year = ((int)date.charAt(6)-48)*1000 + ((int)date.charAt(7)-48)*100 + ((int)date.charAt(8)-48)*10 + ((int)date.charAt(9)-48);
   }
   public String getMonth()
   {
       return month;
   }
   public int getDay()
   {
       return day;
   }
   public int getYear()
   {
       return year;
   }
}


Name.java
public class Name {
   String first;
   String last;
   public void setFirst(String f)
   {
       first = f;
   }
   public void setLast(String l)
   {
       last = l;
   }
   public String getFirst()
   {
       return first;
   }
   public String getLast()
   {
       return last;
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote