public class EmployeeTest {
public static void main(String arg[]) {
// TODO Auto-generated method stub
Regular r = new Regular("이순신", 35, "서울", "인사부");
Temporary t = new Temporary("장보고", 25, "인천", "경리부");
r.setSalary(5000000);
r.printInfo();
t.setWorkHours(120);
t.printInfo();
}
}
class Employee {
private String name;
private int age;
private String address;
private String dept;
private int salary;
public Employee(String name, int age, String address, String dept) {
this.name = name;
this.age = age;
this.address = address;
this.dept = dept;
}
protected void setSalary(int salary) {
this.salary = salary;
}
protected int getSalary() {
return salary;
}
public void printInfo() {
System.out.printf("이름 : %s\n", name);
System.out.printf("이름 : %d\n", age);
System.out.printf("이름 : %s\n", address);
System.out.printf("이름 : %s\n", dept);
}
}
class Regular extends Employee {
public Regular(String name, int age, String address, String dept) {
super(name, age, address, dept);
}
@Override
public void setSalary(int salary) {
super.setSalary(salary);
}
@Override
public void printInfo() {
super.printInfo();
System.out.println("정규직");
System.out.println(super.getSalary());
}
}
class Temporary extends Employee {
private int workHours;
private int wage;
public Temporary(String name, int age, String address, String dept) {
super(name, age, address, dept);
this.wage = 10000;
}
public int getWorkHours() {
return workHours;
}
public void setWorkHours(int workHours) {
this.workHours = workHours;
setSalary();
}
private void setSalary() {
int salary = workHours * wage;
super.setSalary(salary);
}
@Override
public int getSalary() {
return super.getSalary();
}
@Override
public void printInfo() {
super.printInfo();
System.out.println("비정규직");
System.out.println("일한 시간 : " + getWorkHours());
System.out.println("급여 : " + super.getSalary());
}
}
public class EmployeeTest {
public static void main(String[] args) {
Regular r = new Regular("이순신", 35, "서울", "인사부");
Temporary t = new Temporary("장보고", 25, "인천", "경리부");
r.setSalary(5000000);
r.printInfo();
t.setWorkHours(120);
t.printInfo();
}
}
버블정렬
import java.util.Arrays;
class Bubble {
public static int[] bubbleSort(int n, int[] arr) {
int[] result = arr;
for (int i = 1; i < n; i++) {
for (int j = 0; j < (n-i); j++) {
int pre = result[j];
int post = result[j+1];
if (pre > post) {
result[j] = post;
result[j+1] = pre;
} else continue;
}
}
return result;
}
}
public class BubbleSortTest {
public static void main(String[] args) {
int[] arr = {5,3,6,4,8,9,1,2,7};
int[] sorted = Bubble.bubbleSort(9, arr);
System.out.println(Arrays.toString(sorted));
}
}