Thursday, October 28, 2010

Lab 17 -- Solution -- Class: Employee


import java.util.Scanner;

public class Employee extends Person
{
 String SSN;
 int salary;
 
 Scanner k1 = new Scanner(System.in);
 Scanner k2 = new Scanner(System.in);
 Scanner k3 = new Scanner(System.in);
 
 public Employee()
 {
  SSN = "";
  salary = 0;
 }
 
 public Employee(String s, int sal)
 {
  this.SSN = s;
  this.salary = sal;
 }

 public String getSSN() {
  return SSN;
 }

 public void setSSN(String sSN) {
  SSN = sSN;
 }

 public int getSalary() {
  return salary;
 }

 public void setSalary(int salary) {
  this.salary = salary;
 }
 
 public void EnterEmployeeDetails(int empNumber)
 {
  // Enter Name
  System.out.println("Employee " + empNumber + ":" + " Enter Name:");
  super.setName(k1.nextLine());
  
  this.EnterEmployeeSSN(empNumber);
  
  // Enter Salary
  System.out.println("Employee " + empNumber + ":" + " Enter Salary:");
  this.setSalary(k3.nextInt());
  
 }
 
 public void EnterEmployeeSSN(int empNumber)
 {
  System.out.println("Employee " + empNumber + ":" + this.getName() + " :Enter SSN:");
  this.setSSN(k2.nextLine());
 }
 
 public String toString()
 {
  String str;
  str = String.format("Emp Name:%s EmpSSN:%s EmpSalary:%d", this.getName(), this.getSSN(), this.getSalary());
  return str;
 }
}

No comments: