기록

*14일차 실습 본문

학원/실습

*14일차 실습

pringspring 2022. 2. 10. 17:52

[문제]

캡슐화를 적용하여 value object class를 작성하고 생성자를 통해 객체를 생성하여 초기화하여 출력

 

 

package com.oop.employee.model.vo;

public class Employee {
	public Employee() {};

	private int empNo;
	private String name;
	private char gender;
	private String phone;
	private String dept;
	private int salary;
	private double bonusPct;
	
	public Employee(int empNo, String name,char gender,String phone) {
		this.empNo = empNo;
		this.name=name;
		this.gender=gender;
		this.phone=phone;
	}
	
	public Employee(int empNo, String name,char gender,String phone,String dept,int salary,double bonusPct)
	{
		this(empNo,name,gender,phone);
		this.dept=dept;
		this.salary=salary;
		this.bonusPct=bonusPct;
	}
	
	public void printEmployee() {
		System.out.printf("%d , %s , %c , %s , %s , %d, %.2f",
				empNo,name,gender,phone,dept,salary,bonusPct);
	}
	
	public void setempNo(int empNo) {
		this.empNo=empNo;
	}
	public int getempNo() {
		return empNo;
	}
	
	public void setName(String name) {
		this.name=name;
	}
	public String getName() {
		return name;
	}
	public void setGender(char gender) {
		this.gender=gender;
	}
	public char getGender() {
		return gender;
	}
	public void setPhone(String phone) {
		this.phone=phone;
	}
	
	public String getPhone() {
		return phone;
	}
	public void setDept(String dept) {
		this.dept=dept;
	}
	public String getDept() {
		return dept;
	}
	public void setSalary(int salary) {
		this.salary=salary;
	}
	public int getSalary() {
		return salary;
	}
	public void setBonusPct(double bonusPct) {
		this.bonusPct=bonusPct;
	}
	public double getBonusPct() {
		return bonusPct;
	}

}
package com.oop.employee.controller;

import com.oop.employee.model.vo.Employee;

public class Run {

	public static void main(String[] args) {
		Employee emp = new Employee();
		Employee emp2 = new Employee(1,"홍길동",'남',"010-7777-7777");
		Employee emp3 = new Employee(2,"유관순",'여',"010-3131-3131","영업부"
				,3000000,0.15);
		
		emp.printEmployee();
		System.out.println();
		emp2.printEmployee();
		System.out.println();
		emp3.printEmployee();
		
	}

}

'학원 > 실습' 카테고리의 다른 글

*16일차 실습  (0) 2022.02.14
*15일차 실습 (객체배열 실습문제)  (0) 2022.02.11
*13일차 실습  (0) 2022.02.09
*12일차 실습  (0) 2022.02.08
*11일차 실습  (0) 2022.02.07