수업소개
클래스와 인스턴스를 프로젝트에 도입함으로서 코드를 단정하게 정리 정돈하는 모습을 보여드리는 수업입니다.
강의1
소스코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | class Accounting{ public static double valueOfSupply; public static double vatRate = 0.1 ; public static double getVAT() { return valueOfSupply * vatRate; } public static double getTotal() { return valueOfSupply + getVAT(); } } public class AccountingApp { public static void main(String[] args) { Accounting.valueOfSupply = 10000.0 ; System.out.println( "Value of supply : " + Accounting.valueOfSupply); System.out.println( "VAT : " + Accounting.getVAT()); System.out.println( "Total : " + Accounting.getTotal()); } } |
강의2
소스코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | class Accounting{ public double valueOfSupply; public static double vatRate = 0.1 ; public Accounting( double valueOfSupply) { this .valueOfSupply = valueOfSupply; } public double getVAT() { return valueOfSupply * vatRate; } public double getTotal() { return valueOfSupply + getVAT(); } } public class AccountingApp { public static void main(String[] args) { Accounting a1 = new Accounting( 10000.0 ); Accounting a2 = new Accounting( 20000.0 ); System.out.println( "Value of supply : " + a1.valueOfSupply); System.out.println( "Value of supply : " + a2.valueOfSupply); System.out.println( "VAT : " + a1.getVAT()); System.out.println( "VAT : " + a2.getVAT()); System.out.println( "Total : " + a1.getTotal()); System.out.println( "Total : " + a2.getTotal()); } } |