https://www.youtube.com/watch?v=TOptBzGgJOw&t=550s
클래스를 복제하는 기능
class Accounting {
//static을 모두 지워버림
public double valueOfSupply;
public double vatRate;
public double expenseRate;
//메소드 생성
public void print() {
System.out.println("Value of supply : " + valueOfSupply);
System.out.println("VAT : " + getVAT() );
System.out.println("Total : " + getTotal() );
System.out.println("Expense : " + getExpense() );
System.out.println("Income : " + getIncome() );
System.out.println("Dividend1 : " + getDividend1() );
System.out.println("Dividend2 : " + getDividend2() );
System.out.println("Dividend3 : " + getDividend3() );
}
private double getDividend1() {
return getIncome() * 0.5;
}
private double getDividend2() {
return getIncome() * 0.3;
}
private double getDividend3() {
return getIncome() * 0.2;
}
private double getIncome() {
return valueOfSupply - getExpense();
}
private double getExpense() {
return valueOfSupply*expenseRate;
}
private double getTotal() {
return valueOfSupply + getVAT(); // vat를 전역변수로 설정하지 않고 메소드 호출
}
private double getVAT() {
return valueOfSupply*vatRate;
}
}
public class AccountingClassApp {
public static void main(String[] args) { // 실행되는 메소드
//instance
Accounting a1 = new Accounting();//
a1.valueOfSupply = 10000.0;
a1.vatRate = 0.1;
a1.expenseRate = 0.3;
Accounting a2 = new Accounting();
a2.valueOfSupply = 20000.0;
a2.vatRate = 0.05;
a2.expenseRate = 0.2;
a1.print();
}
}
'생활코딩 > 생활코딩 Java' 카테고리의 다른 글
Java_제어문 - 조건문 형식 (0) | 2021.10.12 |
---|---|
Java_제어문 - Boolean Datatype (0) | 2021.10.12 |
Java1_나의 앱 만들기_클래스 (0) | 2021.10.11 |
Java1_나의 앱 만들기_Method (0) | 2021.10.11 |
Java1_나의 앱 만들기_반복문 (0) | 2021.10.11 |