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

Help please Depts file https://www.dropbox.com/s/ojl315sjc6bvc7e/Depts.txt?dl=0

ID: 3812858 • Letter: H

Question

Help please

Depts file

https://www.dropbox.com/s/ojl315sjc6bvc7e/Depts.txt?dl=0

Emps file

https://www.dropbox.com/s/x81dtemv403fblk/Emps.dat?dl=0

Object oriented and GUI Programming The objectives of this assignment are to: 1) Gain experience using the Eclipse IDE; including its environment for managing 2) Gain an understanding of processing both text and binary files. 3) Gain experience in using data structures to hold data in memory. 4) Develop a small Java program that applies the concepts of objectives 2 and 3 5) Practice good programming techniques.

Explanation / Answer


import java.io.*;
import java.lang.*;
import java.util.ArrayList;
import java.math.BigInteger;

public class Test{

static String emp_file_name = "Emps.dat";
static String dept_file_name = "Depts.txt";

public static void main(String []args){
  
ArrayList<Department> depts = readDepartmentData();
       ArrayList<Employee> emps = readEmployeeData();
      
       System.out.println("depts : " + depts.size());
       System.out.println("emps : " + emps.size());
}
  
// read department data from file
static ArrayList<Department> readDepartmentData() {
  
       ArrayList<Department> depts = new ArrayList<Department>();
try{
           FileInputStream fstream = new FileInputStream(dept_file_name);
           DataInputStream in = new DataInputStream(fstream);
           BufferedReader br = new BufferedReader(new InputStreamReader(in));
           String strLine;
           while ((strLine = br.readLine()) != null) {
               String[] tokens = strLine.split(",");
               depts.add( new Department(tokens[0], tokens[1], Integer.parseInt(tokens[2])));
           }
           in.close();
       }catch (Exception e){
           System.err.println("Error: " + e.getMessage());
       }
      
       return depts;
}
  
   // read employee data from file
static ArrayList<Employee> readEmployeeData() {
  
       ArrayList<Employee> emps = new ArrayList<Employee>();
try{
           FileInputStream fstream = new FileInputStream(emp_file_name);
           DataInputStream in = new DataInputStream(fstream);
           while (in.available() > 0) {
               byte[] emp_id = new byte[4];
               in.read(emp_id);
              
               byte[] emp_fname = new byte[10];
               in.read(emp_fname);
              
               byte[] emp_lname = new byte[10];
               in.read(emp_lname);
              
               byte[] dpt_code = new byte[2];
               in.read(dpt_code);
              
               byte[] h_mon = new byte[1];
               in.read(h_mon);
              
               byte[] h_day = new byte[1];
               in.read(h_day);
              
               byte[] h_yr = new byte[2];
               in.read(h_yr);
              
               String emp_type = "" + (char)in.readByte();
              
               double salary = in.readDouble();
               double hourly_rate = in.readDouble();
              
               byte[] v_days = new byte[2];
               in.read(v_days);
              
               byte training = in.readByte();
              
               emps.add(new Employee(new BigInteger(emp_id).intValue(), new String(emp_fname).trim(), new String(emp_lname).trim(), new String(dpt_code).trim(),
                                   new BigInteger(h_mon).intValue() + "/" + new BigInteger(h_day).intValue() + "/" + new BigInteger(h_yr).intValue(), new String(emp_type).trim(),
                                   salary, hourly_rate, new BigInteger(v_days).intValue(), training));
               System.out.println(new BigInteger(emp_id).intValue() + " | " + new String(emp_fname).trim() + " | " + new String(emp_lname).trim() + " | " + new String(dpt_code).trim() +
                                   " | " + new BigInteger(h_mon).intValue() + "/" + new BigInteger(h_day).intValue() + "/" + new BigInteger(h_yr).intValue() + " | " + emp_type +
                                   " | " + salary + " | " + hourly_rate + " | " + new BigInteger(v_days).intValue() + " | " + training);
              
           }

           in.close();
       }catch (Exception e){
           System.err.println("Error: " + e.getMessage());
       }
      
       return emps;
}

}


// Employee model to store information of employee
class Employee {

int emp_id, vacation_days;
String first_name, last_name, dpt_code, hire_date, emp_type;
double salary, hourly_rate;
byte training;
  
public Employee() {
}

public Employee(int emp_id, String first_name, String last_name, String dpt_code, String hire_date, String emp_type, double salary, double hourly_rate, int vacation_days, byte training) {
this.emp_id = emp_id;
this.first_name = first_name;
this.last_name = last_name;
this.dpt_code = dpt_code;
this.hire_date = hire_date;
this.emp_type = emp_type;
this.salary = salary;
this.hourly_rate = hourly_rate;
this.vacation_days = vacation_days;
this.training = training;
}

   public int getEmp_id() {
       return emp_id;
   }
  
   public int getVacation_days() {
       return vacation_days;
   }
  
   public String getFirst_name() {
       return first_name;
   }
  
   public String getLast_name() {
       return last_name;
   }
  
   public String getDpt_code() {
       return dpt_code;
   }
  
   public String getHire_date() {
       return hire_date;
   }
  
   public String getEmp_type() {
       return emp_type;
   }
  
   public double getSalary() {
       return salary;
   }
  
   public double getHourly_rate() {
       return hourly_rate;
   }
  
   public byte getTraining() {
       return training;
   }
  
}

// Department model to store information of department
class Department {

private int emp_id;
private String dpt_code, dpt_name;
  
public Department() {
}

public Department(String dpt_code, String dpt_name, int emp_id) {
this.dpt_code = dpt_code;
this.dpt_name = dpt_name;
this.emp_id = emp_id;
}

   public int getEmp_id() {
       return emp_id;
   }
  
   public String getDpt_code() {
       return dpt_code;
   }
  
   public String getDpt_name() {
       return dpt_name;
   }
}