๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ์ธ๊ณต๋ถ€/JAVA

[์ƒํ™œ์ฝ”๋”ฉ] JAVA1 - 14. ๋‚˜์˜ ์•ฑ ๋งŒ๋“ค๊ธฐ 3

by ๐Ÿ‡๋ฐ•๋ด‰๋ด‰๐Ÿ‡ 2022. 9. 18.

 

 

์ƒํ™œ์ฝ”๋”ฉ JAVA1

-  9. ๋‚˜์˜ ์•ฑ ๋งŒ๋“ค๊ธฐ - ๋ฉ”์†Œ๋“œ -

-  10. ๋‚˜์˜ ์•ฑ ๋งŒ๋“ค๊ธฐ - ํด๋ž˜์Šค -

-  11. ๋‚˜์˜ ์•ฑ ๋งŒ๋“ค๊ธฐ - ์ธ์Šคํ„ด์Šค -

 


 

9. ๋‚˜์˜ ์•ฑ ๋งŒ๋“ค๊ธฐ - ๋ฉ”์†Œ๋“œ

๋ฉ”์†Œ๋“œ๋Š” ์„œ๋กœ ์—ฐ๊ด€๋œ ์ฝ”๋“œ๋ฅผ ๊ทธ๋ฃนํ•‘ํ•ด์„œ ์ด๋ฆ„์„ ๋ถ™์ธ ์ •๋ฆฌ์ •๋ˆ์˜ ์ƒ์ž์ด๋‹ค.

 

ํ˜„์žฌ ์šฐ๋ฆฌ์˜ ์ฝ”๋“œ์—์„œ๋Š” ๋“œ๋ผ๋งˆํ‹ฑํ•œ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ค์ง€๋Š” ์•Š๊ฒ ์ง€๋งŒ ์ƒ์ƒ์„ ํ•ด๋ณด๋ฉด ๋งŒ์•ฝ ๋ณ€์ˆ˜ vat ๋ผ๊ณ ํ•˜๋Š” ๋ถ€๊ฐ€์„ธ๋ฅผ ๊ตฌํ•˜๋Š” ๊ณต์‹์ด ํ•œ์ค„์งœ๋ฆฌ๊ฐ€ ์•„๋‹ˆ๋ผ ์ผ์–ต์ค„ ์ด์ƒ์ด๋ผ๋ฉด vat์— ๋ฐ”๋กœ ์ผ์–ต์ค„์งœ๋ฆฌ ๊ณต์‹์„ ๋„ฃ๋Š” ๊ฒƒ๋ณด๋‹จ ๋‹ค๋ฅธ ๊ณณ์— ๋ถ€๊ฐ€์„ธ๋ฅผ ๊ตฌํ•˜๋Š” ๊ณต์‹์„ ์ž‘์„ฑํ•˜๊ณ  vat์•ˆ์— ํ•ด๋‹น๊ณต์‹์„ ๋‹ด์€ ์ƒ์ž๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๊ฒƒ์ด ์ข€ ๋” ํŽธ๋ฆฌํ•œ ์•ฑ์ด ๋  ์ˆ˜ ์žˆ์„ ๊ฒƒ์ด๋‹ค.

 

ํŠน์ •๊ณต์‹์„ ๋ฉ”์†Œ๋“œ๋กœ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์€ ์†์œผ๋กœ ์ง์ ‘ ์ž…๋ ฅํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ์ง€๋งŒ ๊ณต์‹์„ ๋“œ๋ž˜๊ทธํ•ด์ค€๋‹ค์Œ์— Extract Method... (option + command + M)์„ ๋ˆŒ๋Ÿฌ์„œ ๋ฉ”์†Œ๋“œ๋ช…์„ ์ง€์ •ํ•˜๊ณ  ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.

 

 ๋ถ€๊ฐ€์„ธ๋ฅผ ๊ตฌํ•˜๋Š” ๊ณต์‹์„ getVAT๋ผ๋Š” ๋ฉ”์†Œ๋“œ ์•ˆ์— ๋„ฃ๊ณ  ๋ณ€์ˆ˜ vat์—๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ์ž‘์„ฑ๋œ ์ฝ”๋“œ์ด๋‹ค.

์ด๋ ‡๊ฒŒ ๋˜๋ฉด ๊ณต์‹์˜ ๊ธธ์ด๊ฐ€ ๊ธธ์–ด์ ธ๋„ ๋ฉ”์†Œ๋“œ์•ˆ์— ๋‹ด๊ฒจ์ ธ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์šฐ๋ฆฌ๋Š” getVAT๋งŒ ํ˜ธ์ถœํ•˜๋ฉด ๋˜๋Š” ๊ฒƒ์ด๋‹ค.

 

๊ทธ๋Ÿฐ๋ฐ ์ง€๊ธˆ ๋ฉ”์†Œ๋“œ๋Š”  valueOfSupply๋ผ๋Š” ๊ณต๊ธ‰๊ฐ€์™€ vatRate๋ผ๋Š” ์„ธ๊ธˆ๋น„์œจ์„ ๊ฐ€์ ธ๊ฐ€์•ผ๋งŒ ์•ฑ์ด ์ •์ƒ์ ์œผ๋กœ ์‹คํ–‰๋˜์–ด ์ง„๋‹ค.

๊ทธ๋Ÿฌ๋ฉด getVAT์—์„œ ์–ด๋– ํ•œ ๊ฐ’๋„ ๊ฐ€์ ธ๊ฐ€์ง€ ์•Š๊ณ  ๋ฐ”๋กœ ์‹คํ–‰๋˜์–ด์ง€๊ฒŒ ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ์„๊นŒ?

 

๋งŒ์•ฝ ๋ฉ”์†Œ๋“œ์•ˆ์— ์ธ์ž๋ฅผ ๋„ฃ์–ด์ฃผ์ง€ ์•Š๋Š”๋‹ค๋ฉด ๊ณต๊ธ‰๊ฐ€์™€ ์„ธ๊ธˆ๋น„์œจ์„ ๋ฐ›์•„์˜ค์ง€ ์•Š์•„ valueOfSupply*vatRate๋ฅผ ๋ฆฌํ„ดํ•  ์ˆ˜ ์—†๋‹ค.

ํ•ด๋‹น ๊ฐ’์„ ๋ฆฌํ„ดํ•  ์ˆ˜ ์—†๋Š” ๊ฐ€์žฅ ํฐ ์ด์œ ๋Š” ๊ณต๊ธ‰๊ฐ€์™€ ์„ธ๊ธˆ๋น„์œจ์ด ๋ฉ”์ธ๋ฉ”์†Œ๋“œ์•ˆ์— ์„ ์–ธ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ฉ”์ธ๋ฉ”์†Œ๋“œ ๋ฐ–์— ์žˆ๋Š” getVAT๋Š” ํ•ด๋‹น ๋ณ€์ˆ˜์˜ ์ •๋ณด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋Š” ๊ฒƒ์ด๋‹ค.

 

์šฐ๋ฆฌ๋Š” ์ด๋Ÿฌํ•œ ๋‘๋ณ€์ˆ˜  valueOfSupply, vatRate๋ฅผ ์ง€์—ญ๋ณ€์ˆ˜๋ผ๊ณ  ํ•œ๋‹ค.

๊ทธ๋Ÿฌ๋ฉด ์šฐ๋ฆฌ๋Š” ์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•ด์•ผํ•˜๋Š”๋ฐ ๋ฐฉ๋ฒ•์€ ๋‘ ๋ณ€์ˆ˜๋ฅผ AccountingMethodApp ํด๋ž˜์Šค ์•ˆ์— ์ „์—ญ๋ณ€์ˆ˜๋กœ ์ง€์ •ํ•ด์„œ ๋ชจ๋“  ๋ฉ”์†Œ๋“œ์—์„œ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์•ผํ•œ๋‹ค.

 

์ด๋Ÿฐ์‹์œผ๋กœ ๋ชจ๋“  ๋ฉ”์†Œ๋“œ๊ฐ€ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํด๋ž˜์Šค ๋ฐ”๋กœ์•ˆ์— ์„ ์–ธํ•ด์ฃผ๋ฉด getVAT๋„ ํ•ด๋‹น ๋ณ€์ˆ˜๋ฅผ ์ด์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด๋‹ค.

์ด์ œ ์ด ์ฝ”๋“œ๋“ค์„ ๋ชจ๋‘ ๋ฉ”์†Œ๋“œ๋ฅผ ์ ์šฉ์‹œ์ผœ์„œ ์—…๊ทธ๋ ˆ์ด๋“œ๋ฅผ ์‹œ์ผœ๋ณด๋„๋ก ํ•˜์ž.

 

public class AccountingMethodApp {
	public static double valueOfSupply;
	public static double vatRate;
	public static double expenseRate;
	
	public static void main(String[] args) {
		
		valueOfSupply = 10000.0;
		vatRate = 0.1;
		expenseRate = 0.3;
		
		print();
	}

	public static 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() ); // ๋ฐฐ๋‹น1
		System.out.println("Dividend 2 : " + getDividend2() ); // ๋ฐฐ๋‹น2
		System.out.println("Dividend 3 : " + getDividend3() ); // ๋ฐฐ๋‹น3
	}

	public static double getDividend1() {
		return getIncome() * 0.5;
	}
	
	public static double getDividend2() {
		return getIncome() * 0.3;
	}
	
	public static double getDividend3() {
		return getIncome() * 0.2;
	}

	public static double getIncome() {
		return valueOfSupply - getExpense();
	}

	public static double getExpense() {
		return valueOfSupply*expenseRate;
	}

	public static double getTotal() {
		return valueOfSupply + getVAT();
	}

	public static double getVAT() {
		return valueOfSupply * vatRate;
	}

}

 

 

์ด๋Ÿฐ์‹์œผ๋กœ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด ์ฃผ๋ฉด ์ฝ”๋“œ์˜ ๊ธธ์ด๋Š” ๊ธธ์–ด์กŒ์ง€๋งŒ ๊ฐœ๋ฐœํ•˜๋Š”๋ฐ์— ์žˆ์–ด์„œ๋Š” ํ›จ์”ฌ ๋‹จ์ •ํ•œ ์ฝ”๋“œ๊ฐ€ ๋œ ๊ฒƒ์ด๋‹ค.

 

 


10. ๋‚˜์˜ ์•ฑ ๋งŒ๋“ค๊ธฐ - ํด๋ž˜์Šค

ํด๋ž˜์Šค๋Š” ์„œ๋กœ ์—ฐ๊ด€๋œ ๋ณ€์ˆ˜์™€ ๋ฉ”์†Œ๋“œ๋“ค์„ ๊ทธ๋ฃนํ•‘ํ•œ ๊ฒƒ์— ์ด๋ฆ„์„ ๋ถ™์ธ ๊ฒƒ์œผ๋กœ ๋ฉ”์†Œ๋“œ์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ •๋ฆฌ์ •๋ˆ์˜ ์ƒ์ž์ด๋‹ค.

 

์šฐ๋ฆฌ๋Š” ์ง€๊ธˆ๊นŒ์ง€ ๋ˆ๊ณ„์‚ฐ๊ณผ ๊ด€๋ จ๋œ ํšŒ๊ณ„์— ๋Œ€ํ•œ ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค๊ณ  ์žˆ๋‹ค.

์ง€๊ธˆ๊นŒ์ง€๋Š” ํšŒ๊ณ„์— ๊ด€๋ จ๋œ ๋ณ€์ˆ˜์™€ ๋ฉ”์†Œ๋“œ๋“ค์ด ์กด์žฌํ–ˆ์ง€๋งŒ ๋งŒ์•ฝ ํ”„๋กœ๊ทธ๋žจ์ด ํ™•์žฅ๋˜์–ด์„œ ํšŒ๊ณ„์™€ ๊ด€๋ จ์—†๋Š” ๋ฉ”์†Œ๋“œ์™€ ๋ณ€์ˆ˜๊ฐ€ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์ƒ๊ธธ์ˆ˜๋„ ์žˆ๋‹ค.

๋งŒ์•ฝ ์ฝ”๋“œ์˜ ์–‘์ด ๋ฐฉ๋Œ€ํ•ด์ง€๋ฉด ์šฐ๋ฆฌ๊ฐ€ ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“œ๋Š” ์ƒ์‚ฐ์„ฑ์ด ๋‚ฎ์•„ ์งˆ ์ˆ˜ ์žˆ๋Š”๋ฐ ์ด๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด ๋ฐ”๋กœ ํด๋ž˜์Šค ์ด๋‹ค.

 

class Accounting { // ํšŒ๊ณ„ ๊ด€๋ จ ์ƒ์ž
	public static double valueOfSupply;
	public static double vatRate;
	public static double expenseRate;
	
	public static 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() ); // ๋ฐฐ๋‹น1
		System.out.println("Dividend 2 : " + getDividend2() ); // ๋ฐฐ๋‹น2
		System.out.println("Dividend 3 : " + getDividend3() ); // ๋ฐฐ๋‹น3
	}

	public static double getDividend1() {
		return getIncome() * 0.5;
	}
	
	public static double getDividend2() {
		return getIncome() * 0.3;
	}
	
	public static double getDividend3() {
		return getIncome() * 0.2;
	}

	public static double getIncome() {
		return valueOfSupply - getExpense();
	}

	public static double getExpense() {
		return valueOfSupply*expenseRate;
	}

	public static double getTotal() {
		return valueOfSupply + getVAT();
	}

	public static double getVAT() {
		return valueOfSupply * vatRate;
	}
}

public class AccountingClassApp {
	
	
	public static void main(String[] args) {
		
		Accounting.valueOfSupply = 10000.0;
		Accounting.vatRate = 0.1;
		Accounting.expenseRate = 0.3;
		Accounting.print();
		
		// anotherVariable = ... ;
		// anotherMethod = ...;
	}

	

}

 

๊ธฐ์กด์— AccountingClassApp ํด๋ž˜์Šค์— ์žˆ๋˜ ํšŒ๊ณ„๊ด€๋ จ ๋ณ€์ˆ˜์™€ ๋ฉ”์†Œ๋“œ๋“ค์„ Accounting์ด๋ผ๊ณ  ํ•˜๋Š” ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์–ด์„œ ํ•œ ๊ณณ์— ๋„ฃ์–ด์ฃผ๊ฒŒ ๋˜๋ฉด ๊ธฐ์กด ํด๋ž˜์Šค์•ˆ์— ํšŒ๊ณ„์™€ ๊ด€๋ จ์—†๋Š” ๋ณ€์ˆ˜์™€ ๋ฉ”์†Œ๋“œ๋“ค์ด ์žˆ๋‹ค๊ณ  ํ•˜๋”๋ผ๋„ ์ŠคํŠธ๋ ˆ์Šค๋ฅผ ๋ฐ›์„ ํ•„์š”๊ฐ€ ์—†์–ด์ง„๋‹ค.

 

๋˜ํ•œ ์œ„์˜ ์ฝ”๋“œ์ฒ˜๋Ÿผ print()๋ผ๋Š” ๋น„๊ต์  ๊ฐ„๋‹จํ•œ ์ด๋ฆ„์ด๋”๋ผ๋„ Accounting์ด๋ผ๋Š” ํด๋ž˜์Šค์•ˆ์— ์†Œ์†๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋‹ค๋ฅธ ์†Œ์†์˜ ๊ฐ™์€ ์ด๋ฆ„์„ ๊ฐ€์ง„ ๋ฉ”์†Œ๋“œ๊ฐ€ ์กด์žฌํ•˜๋”๋ผ๋„ ๋ฌธ์ œ๋  ์ผ์ด ์—†๋‹ค.

 

 


11. ๋‚˜์˜ ์•ฑ ๋งŒ๋“ค๊ธฐ - ์ธ์Šคํ„ด์Šค

์ธ์Šคํ„ด์Šค๋Š” ํ•˜๋‚˜์˜ ํด๋ž˜์Šค๋ฅผ ๋ณต์ œํ•ด์„œ ์„œ๋กœ ๋‹ค๋ฅธ ๋ฐ์ดํ„ฐ์˜ ๊ฐ’๊ณผ ์„œ๋กœ ๊ฐ™์€ ๋ฉ”์†Œ๋“œ๋ฅผ ๊ฐ€์ง„ ๋ณต์ œ๋ณธ์„ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด๋‹ค.

 

ํ•ด๋‹น์ฝ”๋“œ๋Š” ๋ฌธ์ œ๋  ๊ฒŒ ์—†๋Š” ์ฝ”๋“œ์ด๋‹ค.

 

๊ทธ๋Ÿฐ๋ฐ ๋งŒ์•ฝ  Accounting์— ์†Œ์†๋˜์–ด ์žˆ๋Š” ๋ณ€์ˆ˜์™€ ๋ฉ”์†Œ๋“œ๋“ค์ด ๊ต‰์žฅํžˆ ๋งŽ์ด ์žˆ๋Š”๋ฐ ์–ด์ฉŒ๋‹ค ํ•œ๋ฒˆ ๋‹ค๋ฅธ ์กด์žฌ๊ฐ€ ๋ฉ”์†Œ๋“œ๋“ค์˜ ๊ฐ’์„ ๋ณ€๊ฒฝํ•ด ์ถœ๋ ฅํ•ด์„œ ์šฐ๋ฆฌ๊ฐ€ ๊ธฐ์กด์— ์ž…๋ ฅํ–ˆ๋˜ ๊ฐ’์œผ๋กœ ๋‹ค์‹œ ๋ฐ”๊ฟ”์„œ ํ”„๋ฆฐํŠธ๋ฅผ ํ•ด์•ผํ•˜๋Š” ์ƒํ™ฉ์ด ๊ฝค๋‚˜ ๋นˆ๋ฒˆํ•˜๊ฒŒ ์ผ์–ด๋‚˜๊ฒŒ ๋œ๋‹ค๋ฉด ํด๋ž˜์Šค์˜ ๋‚ด๋ถ€์ ์ธ ์ƒํƒœ๋ฅผ ๊ณ„์† ๋ฐ”๊พธ๋Š” ํ–‰์œ„๋กœ ์ธํ•ด ๋ฒ„๊ทธ๊ฐ€ ์ผ์–ด๋‚  ํ™•๋ฅ ์ด ๋†’์•„์ง€๊ฒŒ ๋œ๋‹ค.

 

๋งŒ์•ฝ ์ด๋Ÿฌํ•œ ์˜ค๋ฅ˜์˜ ๋ฒ”์œ„์— ๋ฒ—์–ด๋‚˜๊ธฐ ์œ„ํ•ด์„œ Accounting ํด๋ž˜์Šค์— ๋ฒˆํ˜ธ๋ฅผ ๋ถ™์—ฌ์„œ Accountingํด๋ž˜์Šค๋ฅผ ์—ฌ๋Ÿฌ ๊ฐœ ๋ณต์ œํ•œ ๋‹ค์Œ์— ๊ฐ ๊ฐ’์„ ๋„ฃ์–ด์ฃผ๋Š” ๋ฐฉ๋ฒ•์„ ์ƒ๊ฐํ•ด๋‚ผ ์ˆ˜๋„ ์žˆ๊ฒ ์ง€๋งŒ ๋งŒ์•ฝ ํด๋ž˜์Šค์•ˆ์— ๋ฉ”์†Œ๋“œ๋‚˜ ๋ณ€์ˆ˜์˜ ๊ฐ’์ด ๋ณ€๊ฒฝ๋˜์—ˆ์„ ๊ฒฝ์šฐ์—” ์ผ์ผํžˆ ๊ฐ’์„ ๋ณ€๊ฒฝํ•ด์ฃผ์–ด์•ผ ํ•˜๋Š” ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜๊ฒŒ ๋œ๋‹ค.

 

์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด์„œ ์šฐ๋ฆฌ๋Š” ์ธ์Šคํ„ด์Šค๋ฅผ ์‚ฌ์šฉํ•ด ๋ณผ ๊ฒƒ์ด๋‹ค.

 

๋ฐฉ๋ฒ•์€ ์ƒ๊ฐ๋ณด๋‹ค ๊ฐ„๋‹จํ•˜๋‹ค.

Accounting์ด ๋“ค์–ด๊ฐ€์•ผํ•  ๋ณ€์ˆ˜ a1์•ˆ์— new Accounting()์„ ์ž…๋ ฅํ•ด ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•ด ๊ธฐ์กด ํด๋ž˜์Šค๋ฅผ ๋ณต์ œํ•ด ์ฃผ๋Š” ๊ฒƒ์ด๋‹ค.

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์šฐ๋ฆฌ๋Š” ์—ฌ๋Ÿฌ๊ฐœ์˜ ํด๋ž˜์Šค๋ฅผ ๋”ฐ๋กœ ๋ณต์ œํ•ด์ค„ ํ•„์š”๊ฐ€ ์—†๋‹ค.

 

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() ); // ๋ฐฐ๋‹น1
		System.out.println("Dividend 2 : " + getDividend2() ); // ๋ฐฐ๋‹น2
		System.out.println("Dividend 3 : " + getDividend3() ); // ๋ฐฐ๋‹น3
	}

	public double getDividend1() {
		return getIncome() * 0.5;
	}
	
	public double getDividend2() {
		return getIncome() * 0.3;
	}
	
	public double getDividend3() {
		return getIncome() * 0.2;
	}

	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) {
		
		// instance
		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.5;
		a2.expenseRate = 0.2;
		a2.print();
		
		a1.print();
		
	}

}

 

๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•ด๋ณด๋ฉด ์šฐ๋ฆฌ๊ฐ€ ์›ํ•˜๋Š” ๊ฒฐ๊ณผ๊ฐ€ ์ถœ๋ ฅ๋˜์–ด ๋‚˜์˜ค๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

์ด ๊ณผ์ •๋“ค์„ ํ†ตํ•ด ์•Œ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์€ ์ž๋ฐ”์—์„œ๋Š” ๋ฉ”์†Œ๋“œ๋กœ ๊ตฌ์กฐ๋ฅผ ์žก๊ณ , ๋ฉ”์†Œ๋“œ์™€ ๋ณ€์ˆ˜๋ฅผ ๊ทธ๋ฃนํ•‘ํ•ด์„œ ํด๋ž˜์Šค๋กœ ๊ตฌ์กฐ๋ฅผ ์žก์€ ๋‹ค์Œ, ๊ทธ ํด๋ž˜์Šค๋ฅผ ๋ณต์ œํ•œ ์ธ์Šคํ„ด์Šค๋ฅผ ํ†ตํ•ด์„œ ๋˜ ๋‹ค๋ฅธ ๊ตฌ์กฐ๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐฉ์‹์œผ๋กœ ํ”„๋กœ๊ทธ๋žจ์˜ ์™„์„ฑ๋„๋ฅผ ๋†’์—ฌ๋‚˜๊ฐˆ ์ˆ˜ ์žˆ๋‹ค.

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€