21.06.07 - 생활코딩 JAVA 공부

·2021년 6월 28일
0

생활코딩JAVA

목록 보기
5/12

1. 나의 앱 만들기 - 기본 기능 구현

public class AccountingApp {

	public static void main(String[] args) {
		
		System.out.println("Value of supply : "+10000.0); //공급가
		System.out.println("VAT : "+ (10000.0*0.1)); //부가세
		System.out.println("Total : "+ (10000.0 + 10000.0*0.1) ); //공급가+부가세
		System.out.println("Expense : "+ (10000.0*0.3)); //비용
		System.out.println("Income : "+ (10000.0 - 10000.0*0.3)); //이익
		System.out.println("Dividend 1 : "+ (10000.0 - 10000.0*0.3) * 0.5); //배당1
		System.out.println("Dividend 2 : "+ (10000.0 - 10000.0*0.3) * 0.3); //배당2
		System.out.println("Dividend 3 : "+ (10000.0 - 10000.0*0.3) * 0.2); //배당3

	}

}

<결과>

Value of supply : 10000.0
VAT : 1000.0
Total : 11000.0
Expense : 3000.0
Income : 7000.0
Dividend 1 : 3500.0
Dividend 2 : 2100.0
Dividend 3 : 1400.0



여러 번 입력된 숫자 한번에 변경하기 Edit > Find/Replac > Find 10000, Replace with 12345 > Replace All

public class AccountingApp {

	public static void main(String[] args) {
		
		System.out.println("Value of supply : "+12345.0); //공급가
		System.out.println("VAT : "+ (12345.0*0.1)); //부가세
		System.out.println("Total : "+ (12345.0 + 12345.0*0.1) ); //공급가+부가세
		System.out.println("Expense : "+ (12345.0*0.3)); //비용
		System.out.println("Income : "+ (12345.0 - 12345.0*0.3)); //이익
		System.out.println("Dividend 1 : "+ (12345.0 - 12345.0*0.3) * 0.5); //배당1
		System.out.println("Dividend 2 : "+ (12345.0 - 12345.0*0.3) * 0.3); //배당2
		System.out.println("Dividend 3 : "+ (12345.0 - 12345.0*0.3) * 0.2); //배당3

	}

}

<결과>

Value of supply : 12345.0
VAT : 1234.5
Total : 13579.5
Expense : 3703.5
Income : 8641.5
Dividend 1 : 4320.75
Dividend 2 : 2592.45
Dividend 3 : 1728.3000000000002

2. 나의 앱 만들기 - 변수 도입

  • 변수 한 번에 입력하고 전체 변경하기

변수로 입력될 값 선택 후 우측 마우스 클릭 > Refactor > Extract Local Variable > Variable name (변수명) 입력 > OK

public class AccountingApp {

	public static void main(String[] args) {
		
		double valueOfSupply = 10000.0;
		double vatRate = 0.1;
		double expenseRate = 0.3;
		double vat = valueOfSupply*vatRate;
		double total = valueOfSupply + vat;		
		double expense = valueOfSupply*expenseRate;
		double income = valueOfSupply - expense;
		double dividend1 = income * 0.5;
		double dividend2 = income * 0.3;
		double dividend3 = income * 0.2;
		
		
		System.out.println("Value of supply : "+valueOfSupply);   //공급가
		System.out.println("VAT : "+ vat);   //부가세
		System.out.println("Total : "+ total );   //공급가+부가세	
		System.out.println("Expense : "+ expense);   //비용
		System.out.println("Income : "+ income);   //이익
		System.out.println("Dividend 1 : "+ dividend1);   //배당1
		System.out.println("Dividend 2 : "+ dividend2);   //배당2
		System.out.println("Dividend 3 : "+ dividend3);   //배당3

		
	}

}

변수 사용의 효율성!
필요 시 변수값만 수정해주면 변수가 입력된 모든 코드들이 수정되는 폭발적인 효과~!

3. 나의 앱 만들기 - 입력값 도입

  • args 값 넣어주고, cmd로 경로들어가서 확인하는 것까지 해봤다. 

public class AccountingApp {

	public static void main(String[] args) {
		
		double valueOfSupply = Double.parseDouble(args[0]); // string to double
		double vatRate = 0.1;
		double expenseRate = 0.3;
		double vat = valueOfSupply*vatRate;
		double total = valueOfSupply + vat;		
		double expense = valueOfSupply*expenseRate;
		double income = valueOfSupply - expense;
		double dividend1 = income * 0.5;
		double dividend2 = income * 0.3;
		double dividend3 = income * 0.2;
		
		
		System.out.println("Value of supply : "+valueOfSupply);   //공급가
		System.out.println("VAT : "+ vat);   //부가세
		System.out.println("Total : "+ total );   //공급가+부가세	
		System.out.println("Expense : "+ expense);   //비용
		System.out.println("Income : "+ income);   //이익
		System.out.println("Dividend 1 : "+ dividend1);   //배당1
		System.out.println("Dividend 2 : "+ dividend2);   //배당2
		System.out.println("Dividend 3 : "+ dividend3);   //배당3

		
	}

}

오늘 공부한 '나의 앱 만들기 1'은 지금까지 배웠던 생활코딩 자바 복습차원으로 정리해보는 느낌이었고, 오늘의 수확은 아무래도 단축키인듯😆 이클립스 사용하면서 불편하거나 더 빠르게 할 수 있을 것 같은 부분은 구글링으로 단축키 검색하면서 익혀가야겠다.

월요일이니까 오늘은 이정도로 마무리하고,,(월요병은 아무도 못말려~),, 내일부터 또 열심히 달려본다👩‍💻



🗝️ 오늘 익힌 이클립스 단축키 Tip

Ctrl+Alt+방향키 : 현재 위치한 줄을 위or아래로 똑같이 복제할 경우 사용 (복사+붙여넣기)

Alt+방향키 : 현재 위치한 코드 줄이 위or아래로 옮겨짐 (잘라내기+붙여넣기)

Ctrl+D : 줄 전체 코드 삭제

Ctrl+Shift+L : 단축키 모음 확인 가능

Alt+Shift+L : Extract Local Variable

0개의 댓글