Employee
package Homework0927;
class Employee {
String name, adress, department;
int age, salary;
Employee(String name, int age, String adress, String department) { // 이름, 나이, 주소, 부서를 지정하는 생성자 정의
this.name = name;
this.age = age;
this.adress = adress;
this.department = department;
}
public void printinfo() { // 이름, 나이, 주소, 부서 출력
System.out.printf(
"%n이름 : " + name + "%n나이 : " + age + "%n주소 : " + adress + "%n부서 : " + department);
}
}
class Regular extends Employee {
Regular(String name, int age, String adress, String department) {
super(name, age, adress, department); // 상위 생성자 호출
}
public void setSalary(int salary) { // salary 생성자 (상속에서 받아옴)
this.salary = salary;
}
@Override
public void printinfo() {
super.printinfo(); //
System.out.printf("%n정규직" + "%n월급 : " + salary);
}
}
class Temporary extends Employee {
int workHour, hourlyPay=10000;
Temporary(String name, int age, String adress, String department) {
super(name, age, adress, department);
}
void setWorkHours(int workHour) {
this.workHour = workHour;
this.salary = workHour*hourlyPay;
}
@Override
public void printinfo() {
super.printinfo();
System.out.printf("%n비정규직" + "%n일한 시간 : " + workHour + "%n급여 : " + salary);
}
}
public class EmployeeTest {
public static void main(String arg[]) {
Regular r = new Regular("이순신", 35, "서울", "인사부");
Temporary t = new Temporary("장보고", 25, "인천", "경리부");
r.setSalary(5000000);
r.printinfo();
t.setWorkHours(120);
t.printinfo();
}
}
Java
복사
bubble
package Homework0927;
import java.util.Arrays;
public class bubbleSort {
public static void main(String[] args) {
int[] a = { 3, 5, 1, 2, 4 };
int tempValue;
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a.length - i - 1; j++) { // 0 ~ n, 0 ~ n-1 번 반복를 돌면서 바로 옆 숫자릴 비교
if (a[j] > a[j + 1]) { // 바로 오른쪽 숫자와 비교하여 크기가 클 경우, 서로 위치를 바꿈
tempValue = a[j];
a[j] = a[j + 1];
a[j + 1] = tempValue;
}
}
}
System.out.println(Arrays.toString(a));
}
}
Java
복사