7일차 코드(https://baseballgrammer.tistory.com/102)에서 OOP답게 만든 코드이다.
class Accounting{
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("Dividend 1 : " + getDividend1());
System.out.println("Dividend 2 : " + getDividend2());
System.out.println("Dividend 3 : " + getDividend3());
}
public double getDividend3(){
return getIncome() * 0.2;
}
public double getDividend2(){
return getIncome() * 0.3;
}
public double getDividend1(){
return getIncome() * 0.5;
}
public double getIncome(){
return valueOfSupply - getExpense();
}
public double getExpense(){
return valueOfSupply * expenseRate;
}
public double getTotal(){
return valueOfSupply + getVAT();
}
public double getVAT(){
return valueOfSupply * vatRate;
}
}
public class AccountingClassApp{
public static void main(String[] args){
Accounting a1 = new Accounting();
a1.valueOfSupply = 10000.0;
a1.vatRate = 0.1;
a1.expenseRate = 0.3;
a1.print();
Accounting a2 = new Accounting();
a2.valueOfSupply = 20000.0;
a2.vatRate = 0.05;
a2.expenseRate = 0.2;
a2.print();
a1.print();
}
}
10일차 - == vs equals (0) | 2024.01.10 |
---|---|
9일차 - 제어문 1 (1) | 2024.01.10 |
7일차 - 나의 앱 만들기 1 (기본 기능 구현) (1) | 2024.01.06 |
6일차 - API, UI, 자바 문서 보는법 (1) | 2024.01.04 |
5일차 - 직접 컴파일하고 실행하기 (1) | 2024.01.03 |
댓글 영역