CS506 Assignment 1 Solution Fall 2021 - Free Download

CS506 Assignment 1 Solution Fall 2021

VU Answer Provide Latest CS506 Assignment 1 Solution Fall 2021. Easy to See Complete Correct CS506 Assignment 1 Solution 2021 and Download PDF File.


CS506 ASSIGNMENT 1 SOLUTION FALL 2021 

Provide by VU Answer


Due Date: 9 Dec 2021

Total Marks: 20


GET COMPLETE .ZIP FILE DOWNLOAD FREE BELOW


Objective:

This assignment is to give you some practice exercises of file handling and understanding in java console programs.


Important Instruction:

1. You are not allowed to use any IDE tool like NetBeans in this assignment. 

2. Use text file (empData.txt) attached with assignment file. Your code should work with a given attached text file. 

3. Use text files and java files in the same directory.

4. Create Employee.java which will contain Employee information (empId, empName, empDoB, empQualf, empExp, and empPScale).

5. Create Main.java file which will read data from a text file and also enable user to add, search, exit (see output screenshot).  

6. Complete all requirements given below.



CODE Solution:


Employee.java


public class Employee {


    private String empId;

    private String empName;

    private String empDoB;

    private String empQualf;

    private String empExp;

    private String empPScale;


    // default constructo

    public Employee() {


    }

    // parametarized constructor

    public Employee(String empId, String empName, String empDoB, String empQualf, String empExp, String empPScale) {

        this.empId = empId;

        this.empName = empName;

        this.empDoB = empDoB;

        this.empQualf = empQualf;

        this.empExp = empExp;

        this.empPScale = empPScale;

    }


    

   


    // getter and setter

    public String getEmpId() {

        return empId;

    }


    public void setEmpId(String empId) {

        this.empId = empId;

    }


    public String getEmpName() {

        return empName;

    }


    public void setEmpName(String empName) {

        this.empName = empName;

    }


    public String getEmpDoB() {

        return empDoB;

    }


    public void setEmpDoB(String empDoB) {

        this.empDoB = empDoB;

    }


    public String getEmpQualf() {

        return empQualf;

    }


    public void setEmpQualf(String empQualf) {

        this.empQualf = empQualf;

    }


    public String getEmpExp() {

        return empExp;

    }


    public void setEmpExp(String empExp) {

        this.empExp = empExp;

    }


    public String getEmpPScale() {

        return empPScale;

    }


    public void setEmpPScale(String empPScale) {

        this.empPScale = empPScale;

    }


}



Main.java


import java.io.BufferedReader;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

import java.io.PrintWriter;

import java.util.ArrayList;

import javax.swing.JOptionPane;


public class Main {


 


    public static void main(String[] args) {

        while (true) {


            String number = JOptionPane.showInputDialog("Please Ener \n "

                    + "1 for ' add new Employee'"

                    + " \n 2 for ' search in employee' \n"

                    + "3 for ' Exit '   ");


            int convertnumber = Integer.parseInt(number);


            if (convertnumber == 1) {


                addEmployee();

            } else if (convertnumber == 2) {

                String eId = JOptionPane.showInputDialog("Enter Id to search");

                searchEmploye(eId);

            } else if (convertnumber == 3) {

                JOptionPane.showMessageDialog(null, "Developed By : Muhammad Sarim (VUAnswer.com) ");

                System.exit(0);

            } else {

                JOptionPane.showMessageDialog(null, "Invalid ");

            }


        }//end of while


    }


    // String id

    public static void searchEmploye(String eId) {


        try {

            String tokens[] = null;

            String id, name, dob, qual, expe, payS;

            FileReader fr = new FileReader("empData.txt");

            BufferedReader br = new BufferedReader(fr);

            

            String line = br.readLine();

            

            while (line != null) {

                tokens = line.split(",");

                id = tokens[0];

                name = tokens[1];

                dob = tokens[2];

                qual = tokens[3];

                expe = tokens[4];

                payS = tokens[5];

                

                Employee emp = new Employee(id, name, dob, qual, expe, payS);


                ArrayList list = new ArrayList();

                list.add(emp);

                line = br.readLine();

//


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

                    Employee p = (Employee) list.get(i);

                    if (eId.equals(p.getEmpId())) {

                        JOptionPane.showMessageDialog(null, "Employee : \n "

                                + "Empoyee Id : " + p.getEmpId()

                                + " \n Empoyee Name : " + p.getEmpName()

                                + " \n DOB : " + p.getEmpDoB()

                                + " \n Qualification : " + p.getEmpQualf()

                                + " \n Experience : " + p.getEmpExp()

                                + " \n DOB : " + p.getEmpPScale()

                        );

                    } else {

                        JOptionPane.showMessageDialog(null, "Employee Note found");

                    }

                } // end for


            }

            br.close();

            fr.close();


        } catch (Exception ex) {

            ex.printStackTrace();

        }


    }


    public static void addEmployee() {

        try {

            ArrayList list = new ArrayList();


            String id = JOptionPane.showInputDialog("Enter Id ");


            String name = JOptionPane.showInputDialog("Enter Name ");

            String dob = JOptionPane.showInputDialog("Enter DOB  ");

            String qualification = JOptionPane.showInputDialog("Enter Qualification ");

            String experience = JOptionPane.showInputDialog("Enter Employee Experince in month ");

            String paScale = JOptionPane.showInputDialog("Enter Emlpoyee pay scale ");

            Employee emp = new Employee(id, name, dob, qualification, experience, paScale);

            list.add(emp);


            String line;

            FileWriter fw = new FileWriter("empData.txt");

            PrintWriter pw = new PrintWriter(fw);


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

                emp = (Employee) list.get(i);

                line = emp.getEmpId() + "," + emp.getEmpName() + "," + emp.getEmpDoB() + "," + emp.getEmpQualf() + "," + emp.getEmpExp() + "," + emp.getEmpPScale();

// writes line to file (empData.txt)

                pw.println(line);

            }

            pw.flush();

            pw.close();

            fw.close();

        } catch (IOException ioEx) {

            System.out.println(ioEx);

        }

    }


}



Only Use Own VU ID and Name



DOWNLOAD CS506 Assignment 1 Solution Fall 2021 ZIP File


DOWNLOAD CS506 Assignment 1 Solution Fall 2021 Word File


DOWNLOAD CS506 Assignment 1 Solution Fall 2021 PDF File



PLEASE NOTE:

Don't copy the same answer.

Make sure you can make some changes to your solution


Post a Comment

0 Comments