///////
Search

황시은

1번문제
package week1; class Employee { private String name; private int age; private String address; private String department; public Employee(String name, int age, String address, String department) { this.name = name; this.age = age; this.address = address; this.department = department; } public void printInfo() { System.out.println("이름: " + this.name ); System.out.println("나이: " + this.age ); System.out.println("주소: " + this.address); System.out.println("부서: " + this.department); } } class Regular extends Employee{ private int monthSalary; public Regular(String name, int age, String address, String department) { super(name, age, address, department); // TODO Auto-generated constructor stub } public void setSalary(int monthSalary) { this.monthSalary = monthSalary; } public void printInfo() { super.printInfo(); System.out.println("정규직"); System.out.println("월급: " + this.monthSalary); } } class Temporary extends Employee{ private int workTime; private int timeSalary; private int workSalary; public Temporary(String name, int age, String address, String department) { super(name, age, address, department); // TODO Auto-generated constructor stub this.timeSalary = 10000; } public void setWorkHours(int workTime) { this.workTime = workTime; this.workSalary = workTime * timeSalary; } public void printInfo() { super.printInfo(); System.out.println("비정규직"); System.out.println("일한 시간: " + this.workTime); System.out.println("급여: " + this.workSalary); } } public class EmployeeTest { public static void main(String[] args) { // 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(); } }
Java
복사
2번문제
package week1; import java.util.Arrays; public class BubbleSort { public static void main(String[] args) { // TODO Auto-generated method stub int[] arr = {7 , 4 , 3, 2, 5}; int [] result = new int[5]; result = bubbleSort(5,arr); System.out.println(Arrays.toString(arr)); } public static int[] bubbleSort(int n, int[] arr) { int temp = 0; for(int i = n - 1; i > 0; i--) { for(int j = 0; j< n-1;j++) { if(arr[j]>arr[j+1]) { temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; } } } return arr; } }
Java
복사
3번문제
package week1; class Shape{ public Shape() { System.out.println("도형입니다 "); } public void draw() { System.out.println("도형입니다 "); } public double getArea() { return 0.0; } } class Rectangle1 extends Shape { private int height; private int width; public Rectangle1(int height, int width){ this.height = height; this.width = width; } @Override public double getArea() { return height * width; } } class Triangle extends Shape{ private int height; private int width; public Triangle(int height, int width){ this.height = height; this.width = width; } @Override public double getArea() { return height * width / 2.0; } } public class Poly { public static void main(String[] args) { // TODO Auto-generated method stub Shape[] shapeArr = {new Triangle(10,10),new Rectangle1(10,10)}; double sumArea = 0; for (Shape s : shapeArr) { sumArea += s.getArea(); } System.out.println(sumArea); } }
Java
복사