loading...

CS506 Web Design and Development Assignment 1 Solution 2013

You have to develop a simple console base application, which reads an input from the user and based on user input, insert different information in different text files and also display on console.

Solution Guidelines:

  1. Create Emplyee.java which will contain employee information (id, name, Joining Date, Designation, Address, Phone number and email address). Constructor and setter/ getter functions implementation should be defined in the Employee class.
  2.  Create LabourCard.java which will contain labourcard information (Id, EmpId, IssueDate, ExpiryDate). Constructor and setter/ getter functions implementation should be defined in the LabourCard class.
  3. Create HealthCard.java which will contain healthcard information (Id, EmpId, IssueDate, ExpiryDate). Constructor and setter/ getter functions implementation should be defined in HealthCard class.
  4. Create Driver.java which will contain your main program. In the main program you are required to initialize overloaded constructor (Parameterized constructor) to set the values of data members of each class. Through Employee class overloaded constructor (Parameterized constructor) all the data members of Employee class should be initialized. Then insert the values of data members of Employee class in a text file “Employee.txt”.  Similarly you should initialize other class data members through their respective overloaded constructor i.e. constructor of LabourCard and HealthCard and insert the data members value in prospective text files and also display on console.
  5. You have to create text file for each class through code. For example, for employee class you have to make text file named as “Employee.txt” and for LabourCard class you have to make text file named as “LabourCard.txt” and similarly for HealthCard class you have to make text file named as “HealthCard.txt”.

Note:

  • Attached with this assignment statement is a file “CS506 Assignment No.1 Demo.gif” which shows sample working output of the assignment.
  • Snapshots of the desired solution along with its working are also given in the following pages.

Solution:

/*
* @public class Employee
*/
public class Emplyee {

/*
* @data fields
*/
private int id;
private String name;
private String joiningDate;
private String designation;
private String address;
private String phoneNumber;
private String emailAddress;

/*
* @methods
*/

/*
* @overloaded constructer
*/
public Emplyee(int i,String n,String j,String d, String addr,String ph, String email){
this.setId(i);
this.setName(n);
this.setJoiningDate(j);
this.setDesignation(d);
this.setAddress(addr);
this.setPhoneNumber(ph);
this.setEmailAddress(email);
}
/*
* @get id method
*/
public int getId(){
return this.id;
}
/*
* @set id method
*/
public void setId(int a){
this.id=a;
}
/*
* @get name method
*/
public String getName(){
return this.name;
}
/*
* @set name method
*/
public void setName(String s){
this.name=s;
}
/*
* @get joiningDate method
*/
public String getJoiningDate(){
return this.joiningDate;
}
/*
* @set joiningDate method
*/
public void setJoiningDate(String s){
this.joiningDate=s;
}
/*
* @ get designation method
*/
public String getDesignation(){
return this.designation;
}
/*
* @set designation method
*/
public void setDesignation(String s){
this.designation=s;
}
/*
* @get address method
*/
public String getAddress(){
return this.address;
}
/*
* @set address method
*/
public void setAddress(String s){
this.address=s;
}
/*
* @get phoneNumber method
*/
public String getPhoneNumber(){
return this.phoneNumber;
}
/*
* @set phoneNumber method
*/
public void setPhoneNumber(String s){
this.phoneNumber=s;
}
/*
* @get emailAddress method
*/
public String getEmailAddress(){
return this.emailAddress;
}
/*
* @set emailAddress method
*/
public void setEmailAddress(String s){
this.emailAddress=s;
}
}

/*
* @public class HealthCard
*/
public class HealthCard {

/*
* @data fields
*/
private int id;
private String name;
private String issueDate;
private String expiryDate;

/*
* @methods
*/

/*
* @overloaded constructer
*/
public HealthCard(int id,String name,String issueDate,String expieryDate){
this.setId(id);
this.setName(name);
this.setIssueDate(issueDate);
this.setExpiryDate(expieryDate);

}
/*
* @get id method
*/
public int getId(){
return this.id;
}
/*
* @set id method
*/
public void setId(int a){
this.id=a;
}
/*
* @get name method
*/
public String getName(){
return this.name;
}
/*
* @set name method
*/
public void setName(String i){
this.name=i;
}
/*
* @get issueDate method
*/
public String getIssueDate(){
return this.issueDate;
}
/*
* @set issueDate method
*/
public void setIssueDate(String s){
this.issueDate=s;
}
/*
* @ get expiryDate method
*/
public String getExpiryDate(){
return this.expiryDate;
}
/*
* @set expiryDate method
*/
public void setExpiryDate(String s){
this.expiryDate=s;
}
}

/*
* @public class LabourCard
*/
public class LabourCard {

/*
* @data fields
*/
private int id;
private String name;
private String issueDate;
private String expiryDate;

/*
* @methods
*/

/*
* @overloaded constructer
*/
public LabourCard(int id,String name,String issueDate,String expieryDate){
this.setId(id);
this.setName(name);
this.setIssueDate(issueDate);
this.setExpiryDate(expieryDate);

}
/*
* @get id method
*/
public int getId(){
return this.id;
}
/*
* @set id method
*/
public void setId(int a){
this.id=a;
}
/*
* @get name method
*/
public String getName(){
return this.name;
}
/*
* @set name method
*/
public void setName(String i){
this.name=i;
}
/*
* @get issueDate method
*/
public String getIssueDate(){
return this.issueDate;
}
/*
* @set issueDate method
*/
public void setIssueDate(String s){
this.issueDate=s;
}
/*
* @ get expiryDate method
*/
public String getExpiryDate(){
return this.expiryDate;
}
/*
* @set expiryDate method
*/
public void setExpiryDate(String s){
this.expiryDate=s;
}
}

/*
* @public class Driver
*/
import java.io.*;

public class Driver {

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {

InputStreamReader input = new InputStreamReader(System.in);
BufferedReader br= new BufferedReader(input);

while(true){
System.out.println("Enter 1 for Employee Personal Information");
System.out.println("Enter 2 for Employee Labour Card Information");
System.out.println("Enter 3 for Employee Health Card Information");
System.out.println("Enter 4 To Exit");

String s =br.readLine();
switch (s) {
case ("1"):
System.out.print("ID: ");
String i =br.readLine();
int id= Integer.parseInt(i);
System.out.print("Name: ");
String name =br.readLine();
System.out.print("Joining Date: ");
String jDate =br.readLine();
System.out.print("Designation: ");
String desi =br.readLine();
System.out.print("Address: ");
String address =br.readLine();
System.out.print("Phone Number: ");
String ph =br.readLine();
System.out.print("Email: ");
String email =br.readLine();
Emplyee emp = new Emplyee(id, name, jDate, desi, address, ph, email);
try{
FileWriter fr= new FileWriter("Employee.txt");
PrintWriter pw= new PrintWriter(fr);
pw.println("ID t Name t Joining Date t Designation t Address t Phone No t Email");
pw.println(id +"t"+ name +"t"+ jDate +"t"+ desi +"t"+ address +"t"+ ph +"t"+ email);

pw.flush();
pw.close();
fr.close();
}
catch (IOException e) {
// TODO: handle exception
System.out.println("Error in writting file Employee.txt");
}
break;
case("2"):
System.out.print("ID: ");
String lId =br.readLine();
int laborID= Integer.parseInt(lId);
System.out.print("Name: ");
String laborName =br.readLine();
System.out.print("IssueDate: ");
String issueDate =br.readLine();
System.out.print("ExpiryDate: ");
String expiryDate =br.readLine();
LabourCard lc= new LabourCard(laborID, laborName, issueDate, expiryDate);
try{
FileWriter fr= new FileWriter("LabourCard.txt");
PrintWriter pw= new PrintWriter(fr);
pw.println("LabourCard ID t Empoyee Name t Issue Date t Expiery Date ");
pw.println(laborID +"tt"+ laborName +"tt"+ issueDate +"t"+ expiryDate);

pw.flush();
pw.close();
fr.close();
}
catch (IOException e) {
// TODO: handle exception
System.out.println("Error in writting file LabourCard.txt");
}
break;
case("3"):
System.out.print("ID: ");
String hId =br.readLine();
int healthID= Integer.parseInt(hId);
System.out.print("Name: ");
String emplyName =br.readLine();
System.out.print("IssueDate: ");
String iDate =br.readLine();
System.out.print("ExpiryDate: ");
String expDate =br.readLine();
HealthCard hc= new HealthCard(healthID,emplyName , iDate, expDate);
try{
FileWriter fr= new FileWriter("HealthCard.txt");
PrintWriter pw= new PrintWriter(fr);
pw.println("HealthCard ID t Empoyee Name t Issue Date t Expiery Date ");
pw.println(healthID +"tt"+ emplyName +"tt"+ iDate +"t"+ expDate);

pw.flush();
pw.close();
fr.close();
}
catch (IOException e) {
// TODO: handle exception
System.out.println("Error in writting file HealthCard.txt");
}
break;
case("4"):
System.exit(0);
break;
default:
break;

}

}
}

Download the complete Solution Here CS506_Assignment_1_Solution

DOWNLOAD SOLUTION HERE
loading...