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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
import java.util.Date;
import java.util.Calendar;
import java.text.SimpleDateFormat;;
public abstract class Account {
private String name; //고객명
private int amount; //금 액
private int term; //기 간(개월수로입력)
public Account(String name, int amount, int term) {
this.name = name;
this.amount = amount;
this.term = term;
}
public abstract void creatAccount();
public static String creationDate() {
SimpleDateFormat dtFormat = new SimpleDateFormat("yyyy-MM-dd");
Date day = new Date();
String today = dtFormat.format(day);
return today;
}
public String dueDate(int term) {
this.term = term;
SimpleDateFormat dtFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, term);
return dtFormat.format(cal.getTime());
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
public int getTerm() {
return term;
}
public void setTerm(int term) {
this.term = term;
}
}
|
cs |
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
32
33
34
35
36
37
38
|
import java.text.DecimalFormat;
public class LoanAccount extends Account {
private static final double rate = 4.5;
public static int ano = 10000001;
public LoanAccount(String name, int amount, int term) {
super(name, amount, term);
}
@Override
public void creatAccount() {
StringBuffer sb = new StringBuffer();
DecimalFormat df = new DecimalFormat("###,###");
sb.append(String.valueOf(ano++));
sb.insert(4, "-");
System.out.println("-------");
System.out.println("계좌 생성");
System.out.println("-------");
System.out.println("계좌번호 : " + sb.toString());
System.out.println("고 객 명 : " + getName());
System.out.println("대츨금액 : " + df.format(getAmount()) + "원");
System.out.println("이 율 : " + rate + "%");
System.out.println("이 자 액 : " + getAmount()*rate/100 + "원");
System.out.println("대 출 일 : " + creationDate());
System.out.println("기 간 : " + getTerm() + "개월");
System.out.println("만 기 일 : " + dueDate(getTerm()));
System.out.println("월상환액 : " + repayment() + "원");
}
public double repayment() {
double result = ((getAmount() * rate/100) + getAmount())/getTerm();
return Math.floor(result); //버림
}
}
|
cs |
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
32
33
34
35
36
37
38
|
import java.text.DecimalFormat;
public class DepositAccount extends Account {
private static final double rate = 2.5;
public static int ano = 20000001;
public DepositAccount(String name, int amount, int term) {
super(name, amount, term);
}
@Override
public void creatAccount() {
StringBuffer sb = new StringBuffer();
DecimalFormat df = new DecimalFormat("###,###");
sb.append(String.valueOf(ano++));
sb.insert(4, "-");
System.out.println("-------");
System.out.println("계좌 생성");
System.out.println("-------");
System.out.println("계좌번호 : " + sb.toString());
System.out.println("고 객 명 : " + getName());
System.out.println("예 금 액 : " + df.format(getAmount()) + "원");
System.out.println("이 율 : " + rate + "%");
System.out.println("이 자 액 : " + getAmount()*rate/100 + "원");
System.out.println("예 금 일 : " + creationDate());
System.out.println("기 간 : " + getTerm() + "개월");
System.out.println("만 기 일 : " + dueDate(getTerm()));
System.out.println("만기금액 : " + maturity() + "원");
}
public double maturity() {
double result = getAmount() +(getAmount()*rate/100);
return Math.floor(result);
}
}
|
cs |
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
32
33
34
35
36
37
38
39
40
41
42
43
44
|
import java.text.DecimalFormat;
public class SavingsAccount extends Account {
private static final double rate = 1.5;
public static int ano = 30000001;
public SavingsAccount(String name, int amount, int term) {
super(name, amount, term);
}
@Override
public void creatAccount() {
StringBuffer sb = new StringBuffer();
DecimalFormat df = new DecimalFormat("###,###");
sb.append(String.valueOf(ano++));
sb.insert(4, "-");
System.out.println("-------");
System.out.println("계좌 생성");
System.out.println("-------");
System.out.println("계좌번호 : " + sb.toString());
System.out.println("고 객 명 : " + getName());
System.out.println("만기금액 : " + df.format(getAmount()) + "원");
System.out.println("이 율 : " + rate + "%");
System.out.println("이 자 액 : " + getAmount()*rate/100 + "원");
System.out.println("예 금 일 : " + creationDate());
System.out.println("기 간 : " + getTerm() + "개월");
System.out.println("만 기 일 : " + dueDate(getTerm()));
System.out.println("월적금액 : " + monthlyAmount() + "원");
System.out.println("만기금액 : " + maturity() + "원");
}
public double maturity() {
double result = getAmount() +(getAmount()*rate/100);
return Math.floor(result);
}
public int monthlyAmount() {
int result = getAmount()/getTerm();
return result;
}
}
|
cs |
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
32
33
34
35
36
37
38
39
40
41
|
import java.text.DecimalFormat;
import java.util.Scanner;
public class AccountTest {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while(true) {
System.out.println("---------------------------------------------");
System.out.println(" 1.대출계좌생성 | 2.예금계좌생성 | 3.적금계좌 생성 | 4.종료");
System.out.println("---------------------------------------------");
System.out.print("선택> ");
int n = scanner.nextInt();
if(n == 4) break;
System.out.print("이름> ");
String name = scanner.next();
System.out.print("금액> ");
int amount = scanner.nextInt();
System.out.print("기간(개월단위)> ");
int term = scanner.nextInt();
if(n == 1) {
LoanAccount holder = new LoanAccount(name, amount, term);
holder.creatAccount();
}else if(n == 2) {
DepositAccount holder = new DepositAccount(name, amount, term);
holder.creatAccount();
}else if(n == 3) {
SavingsAccount holder = new SavingsAccount(name, amount, term);
holder.creatAccount();
}else {
System.out.println("지원하지 않는 기능입니다.");
}
}
}
}
|
cs |
[JAVA] 자바 예제 - 12지신 최단 거리 구하기(Pathfinding) (0) | 2021.06.09 |
---|---|
[JAVA] 자바 예제 - 배열의 요소 합 구하기(enhanced for문 사용) (0) | 2021.06.09 |
[JAVA] 자바 예제 - 랜덤 숫자 생성하기 (Math.random( )함수 이용) (0) | 2021.06.08 |
[JAVA] 자바 예제 - 자판기 거스름돈 산출하기 (0) | 2021.06.07 |
[JAVA] 자바 예제 - 소수(Prime Number) 구하기 (0) | 2021.06.05 |