티스토리 뷰
package org;
public class Company {
String name;
Department[] departments;
String location;
int assets;
double growthRate;
public Company(String name, Department[] departments, String location, int assets, double growthRate) {
this.name = name;
this.departments = departments;
this.location = location;
this.assets = assets;
this.growthRate = growthRate;
}
public Company(){
System.out.println("새로운 회사 탄생");
}
public int calcSalary(){
int sum = 0;
for (Department department : departments) {
sum += department.getSalary() * department.getNumOfPeople();
}
return sum;
}
public String giveSalary(){
this.assets -= calcSalary();
return "지급 후 자산: " + assets;
}
public String introduceCompany(){
return "저희 회사는 " + name + "이고 " + location + "에 위치하고 있습니다.\n저희회사는 " + growthRate + "% 의 성장률을 보이고 있습니다.";
}
public int getAssets() {
return assets;
}
public void setAssets(int assets) {
this.assets = assets;
}
}
package org;
public class Department {
private String name;
private int numOfPeople;
private int salary;
public Department(String name, int numOfPeople, int salary) {
this.name = name;
this.numOfPeople = numOfPeople;
this.salary = salary;
}
public Department(){}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNumOfPeople() {
return numOfPeople;
}
public void setNumOfPeople(int numOfPeople) {
this.numOfPeople = numOfPeople;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
}
package org;
public class FinalAndStatic {
private static int sum;
public static final double PI = 3.14;
private final int cantModify;
FinalAndStatic(int cantModify){
this.cantModify = cantModify;
}
public static int sum(int[] array){
sum = 0;
for (int i : array) {
sum += i;
}
return sum;
}
public static double average(int[] array){
sum = 0;
for (int i : array) {
sum += i;
}
return (double)(sum / array.length);
}
public static double getWidth(int r){
return r * r * PI;
}
}
package org;
public class Kakao extends Company {
private String[] appName = {"카카오톡", "카카오뱅크", "카카오택시", "카카오지하철", "카카오버스"};
public Kakao(String name, Department[] departments, String location, int assets, double growthRate, String[] appName) {
super(name, departments, location, assets, growthRate);
this.appName = appName;
}
public Kakao(){
super();
}
@Override
public String introduceCompany(){
return "저희는 카카오입니다.";
}
public String introduceApps(){
String introduce = "";
for (String s : appName) {
introduce += s + " ";
}
return "저희가 개발한 앱으로는 " + introduce + "등이 있습니다.";
}
// public void setAssets(int assets){
// this.assets = assets;
// System.out.println("완료");
// }
}
package org;
public class Naver extends Company{
public Naver(String name, Department[] departments, String location, int assets, double growthRate) {
super(name, departments, location, assets, growthRate);
}
public Naver() {
}
}
package org;
public class Run {
public static void main(String[] args) {
System.out.println(FinalAndStatic.PI);
int[] numArray = {1, 2, 3};
System.out.println(FinalAndStatic.average(numArray));
System.out.println(FinalAndStatic.sum(numArray));
System.out.println(FinalAndStatic.getWidth(10));
System.out.println();
System.out.println();
Department software = new Department("개발", 10, 5000);
Department planning = new Department("기획", 4, 4500);
Department promotion = new Department("홍보", 5, 4000);
Department[] dArray = {software, planning, promotion};
Company tuk = new Company("한국공학회사", dArray, "시흥", 5000000, 50);
System.out.println(tuk.calcSalary());
System.out.println(tuk.getAssets() + "-" + tuk.calcSalary() + " = " + tuk.giveSalary());
System.out.println();
System.out.println();
String[] appName = {"카카오톡", "카카오뱅크", "카카오택시", "카카오지하철", "카카오버스"};
Kakao k = new Kakao("카카오Inc", dArray, "강남", 1000000, 300, appName);
System.out.println(k.getAssets());
System.out.println(k.introduceApps());
System.out.println();
Naver n = new Naver();
System.out.println();
Company kakao = new Kakao();
Company naver = new Naver();
System.out.println(kakao.introduceCompany());
kakao.setAssets(1000);
System.out.println(kakao.getAssets());
((Kakao) kakao).introduceApps();
if(kakao instanceof Company){
System.out.println("Company");
}
else{
System.out.println("Kakao");
}
}
}
'멘토링 준비 자료 > 자바 스터디 멘토링' 카테고리의 다른 글
자바 스터디 3주차 - 클래스와 객체 (0) | 2022.03.26 |
---|---|
자바 스터디 2주차 - 반복문과 배열, 예외처리 (0) | 2022.03.21 |
자바 스터디 1주차 - 자바 기본 프로그래밍_2 (0) | 2022.03.10 |
자바 스터디 1주차 - 자바 기본 프로그래밍_1 (0) | 2022.03.10 |
자바 스터디 1주차 - 자바 개요 (0) | 2022.03.09 |