[실습 10] 여행 상품 패키지 견적서를 제작하세요.
대인 기준
호주: 600,000 원
태국: 400,000 원
대만: 500,000 원
[실행 화면]
java If.IfExam10 호주 2 ← 대인 인원수
국가: 호주
대인: 2 명 1200000 원
-------------------------------
결재 금액: 1200000 원
-------------------------------------------------------------------------------------
public class IfExam10 {
public static void main(String[] args) {
String country = args[0];
int num = Integer.parseInt(args[1]);
int price=0;
if(country.equals("호주")==true){
price =600000;
}else if(country.equals("태국")){
price =400000;
}else if(country.equals("대만")){
price =500000;
}
int tot = num * price;
System.out.println("국가 :" + country);
System.out.println("대인 :" + num + "명" +" " + tot + "원");
System.out.println("--------------------");
System.out.println("결재 금액 :" + tot + "원");
}
}
-------------------------------------------------------------------------------------
[실습 10_1]
* 인원수 입력을 1명에서 30명까지 입력받은 경우만 정상처리하고,
그외의 인원 입력은 메시지를 출력하고 종료하도록 수정 할 것.
"신청가능한 인원은 1 ~ 30명까지입니다."
-------------------------------------------------------------------------------------
public class IfExam10_1{
public static void main(String[] args) {
String country = args[0];
int people = Integer.parseInt(args[1]);
int price = 0;
if (people < 1 || 30 < people) {
System.out.println("신청가능한 인원은 1~30명까지입니다.");
} else {
if (country.equals("호주")) {
price = 600000 * people;
} else if (country.equals("태국")) {
price = 400000 * people;
} else if (country.equals("대만")) {
price = 500000 * people;
}
System.out.println("국가: " + country);
System.out.println("대인: " + people + "명");
System.out.println("-------------------------");
System.out.println("결재금액: " + price + "원");
}
}
}
-------------------------------------------------------------------------------------
[실습 11] 여행 상품 패키지 견적서를 제작하세요.
- 가격 기준
대인 기준
호주: 600,000 원
태국: 400,000 원
대만: 500,000 원
소인 기준
호주: 500,000 원
태국: 300,000 원
대만: 400,000 원
[실행 화면]
java If.IfExam11 호주 2 1 ← 호주, 대인 2, 소인 1
국가: 호주
대인: 2 명 1200000 원
소인: 1 명 500000 원
-------------------------------
결재 금액: 1700000 원
java If.IfExam11 대만 2 2
국가: 대만
대인: 2 명 1000000 원
소인: 2 명 800000 원
-------------------------------
결재 금액: 1800000 원
-------------------------------------------------------------------------------------
public class IfExam11 {
public static void main(String[] args) {
String nation = args[0];
int cnt = Integer.parseInt(args[1]); // 대인의 인원수
int cntPrice =0;
int cntPriceTot =0;
int childCnt = Integer.parseInt(args[2]); // 소인의 인원수
int childPrice = 0;
int childPriceTot = 0;
int tot = 0;
if (cnt >=1 && cnt <= 30) {
if (nation.equals("호주")) {
cntPrice = 600000; // 대인의 가격
childPrice = 500000;
} else if (nation.equals("태국")) {
cntPrice = 400000;
childPrice = 300000;
} else if (nation.equals("대만")) {
cntPrice = 500000;
childPrice = 400000;
}
cntPriceTot = cntPrice * cnt;
childPriceTot = childPrice * childCnt;
tot = cntPriceTot + childPriceTot;
System.out.println("국가: " + nation);
System.out.println("대인: " + cnt + " 명 " + cntPriceTot + " 원");
System.out.println("소인: " + childCnt + " 명 " + childPriceTot + " 원");
System.out.println("-------------------------------");
System.out.println("결재 금액: " + tot + " 원");
} else {
System.out.println("신청가능한 인원은 1 ~ 30명까지입니다.");
}
}
}
-------------------------------------------------------------------------------------
[실습 12] 펜션 예약 견적서를 제작하세요.
- 바베큐 신청, 바닷가 전망 신청, 물놀이 튜브 신청: Y, N
펜션 1박2일 기준
펜션1: 80,000 원
펜션2: 120,000 원
펜션3: 150,000 원
옵션 상품
바베큐: 30000 원
바닷가 전망: 20000 원
물놀이 튜브: 10000 원
[실행 화면]
java If.IfExam12 펜션1 Y Y Y ← 펜션1, 바베큐 신청, 바닷가 전망 신청, 물놀이 튜브 신청
펜션: 펜션1
가격: 80000 원
바베큐: 30000 원
바닷가 전망: 20000 원
물놀이 튜브: 10000 원
-------------------------------
결재 금액: 140000 원
java If.IfExam12 펜션1 Y N N ← 펜션1, 바베큐 신청, 바닷가 전망 신청 안함, 물놀이 튜브 신청 안함
펜션: 펜션2
가격: 120000 원
바베큐: 30000 원
바닷가 전망: 0 원
물놀이 튜브: 0 원
-------------------------------
결재 금액: 150000 원
-------------------------------------------------------------------------------------
public class IfExam12 {
public static void main(String[] args) {
String pension = "";
int pensionPrice = 0;
String barbecue = "";
int barbecuePrice = 0;
String sea = "";
int seaPrice = 0;
String tube = "";
int tubePrice = 0;
int total = 0; // 결재 금액
pension = args[0];
barbecue = args[1];
sea = args[2];
tube = args[3];
if (pension.equals("펜션1")) {
pensionPrice = 80000;
} else if (pension.equals("펜션2")) {
pensionPrice = 120000;
} else if (pension.equals("펜션3")) {
pensionPrice = 150000;
}
if (barbecue.equals("Y")) {
barbecuePrice = 30000;
}
if (sea.equals("Y")) {
seaPrice = 20000;
}
if (tube.equals("Y")) {
tubePrice = 10000;
}
total = pensionPrice + barbecuePrice + seaPrice + tubePrice;
System.out.println("펜션: " + pension);
System.out.println("가격: " + pensionPrice + " 원");
System.out.println("바베큐: " + barbecuePrice + " 원");
System.out.println("바닷가 전망: " + seaPrice + " 원");
System.out.println("물놀이 튜브: " + tubePrice + " 원");
System.out.println("----------------------------");
System.out.println("결재 금액: " + total);
}
}
-------------------------------------------------------------------------------------
[실습 13] java, jsp, spring 성적중에 한 과목이라도 80점이 넘으면 합격처리하는 프로그램을 작성하세요.
정수형 변수 3개: 숫자 저장
문자열 변수 1개: 출력 문자열
Console에서 실행: java IfExam13 50 80 60 <-- java, jsp, spring
[실행 화면]
java If.IfExam13 50 80 60
결과: 합격
java If.IfExam13 50 70 60
결과: 재심사
-------------------------------------------------------------------------------------
public class IfExam13 {
public static void main(String[] args) {
int java = 0;
int jsp = 0;
int spring = 0;
String decision = "";
java = Integer.parseInt(args[0]);
jsp = Integer.parseInt(args[1]);
spring = Integer.parseInt(args[2]);
if (java >= 80 || jsp >= 80 || spring >= 80) {
decision = "합격";
} else {
decision = "재심사";
}
System.out.println("결과: " + decision);
}
}
-------------------------------------------------------------------------------------
[실습 14] 한 과목이 80점이 넘어도 전체 평균이 60점이 안넘으면 불합격 처리하세요.
[실행 화면]
java If.IfExam14 60 80 60
결과: 합격
java If.IfExam14 60 70 60
결과: 재심사
java If.IfExam14 30 90 50
결과: 평균 점수 미달입니다.
-------------------------------------------------------------------------------------
public class IfExam14 {
public static void main(String[] args) {
int java = 0;
int jsp = 0;
int spring = 0;
String decision = "";
int tot = 0;
int avg = 0;
java = Integer.parseInt(args[0]);
jsp = Integer.parseInt(args[1]);
spring = Integer.parseInt(args[2]);
tot = java + jsp + spring;
avg = tot / 3;
if (avg >= 60) {
if (java >= 80 || jsp >= 80 || spring >= 80) {
decision = "합격";
} else {
decision = "재심사";
}
} else {
decision = "평균 점수 미달입니다.";
}
System.out.println("결과: " + decision);
}
}
-------------------------------------------------------------------------------------
[실습 15] 도서를 쇼핑카트에 저장하는 기능을 구현하세요.
- 도서 가격이 20000 원을 넘으면 배송비 2500원을 청구하지 않습니다.
- 포인트는 도서 주문 가격에 대하여 5%를 계산합니다.
[실행 화면]
java If.IfExam15 여행 15000 1
도서명: 여행 | 가격: 15000 원 | 수량: 1 권
배송비: 2500 원
-------------------------------------------------------
도서 가격: 15000 (포인트: 750 원) ← 5 % 계산
결재 금액: 17500 원
java If.IfExam15 캠핑 15000 2
도서명: 캠핑 | 가격: 15000 원 | 수량: 2 권
배송비: 0 원 ← 도서 주문 가격이 20000 원을 넘음으로 배송비를 받지 않습니다.
-------------------------------------------------------
도서 가격: 30000 (포인트: 1500 원) ← 5 % 계산
결재 금액: 30000 원
-------------------------------------------------------------------------------------
public class IfExam15 {
public static void main(String[] args) {
String book = ""; // 도서명
int price = 0; // 도서 가격
int count = 0; // 도서 수량
int baesong = 2500; // 배송비
int subTotal = 0; // 도서 가격 합계
int total = 0; // 결재 금액
int point = 0; // 포인트
book = args[0]; // 도서명
price = Integer.parseInt(args[1]); // 금액
count = Integer.parseInt(args[2]); // 수량
subTotal = price * count; // 도서 가격 합계
if (subTotal >= 20000) {
baesong = 0; // 배송비 없음.
}
total = subTotal + baesong; // 결재 금액
point = (int)(subTotal * 0.05); // 5% 포인트 계산
System.out.println("도서명: " + book + " | 가격: " + price + " 원 | 수량: " + count + " 권");
System.out.println("배송비: " + baesong + " 원");
System.out.println("-------------------------------------------------------");
System.out.println("도서 가격: " + subTotal + "(포인트: " + point + " 원)");
System.out.println("결재 금액: " + total + " 원");
}
}
-------------------------------------------------------------------------------------
[실습 16] 오토 캠핑장 예약 시스템 제작
- 유형 1: 캠핑, 40,000 원
- 유형 2: 펜션식 방, 150,000 원
- 인원 기준 6명, 추가 인원 5,000 원
- 포인트: 7%
- 결재 방법
. 신용카드: 1, 계좌이체(현금): 2, 모바일 결재: 3, 포인트 결재: 4
[실행 화면]
java If.IfExam16 1 2 1 ← 유형 1, 추가인원 2명, 결재 방법 1
캠핑장 예약 내역
유형: 캠핑 | 가격: 40000 원
추가인원: 2명 | 금액: 10000 원
-------------------------------------------------------
결재 방법: 신용카드
결재 금액: 50000 (포인트: 3500 원) ← 7 % 계산
java If.IfExam16 2 0 3 ← 유형 2, 추가인원 0명, 결재 방법 3
캠핑장 예약 내역
유형: 펜션식방 | 가격: 150000 원
추가인원: 0명 | 금액: 0 원
-------------------------------------------------------
결재 방법: 모바일 결재
결재 금액: 150000 (포인트: 10500 원) ← 7 % 계산
-------------------------------------------------------------------------------------
public class IfExam16 {
public static void main(String[] args) {
int type = Integer.parseInt(args[0]); // 유형
int ext = Integer.parseInt(args[1]); // 추가인원
int pay_way = Integer.parseInt(args[2]); // 결재 방법
String type_name = ""; // 캠핑 유형 이름
int type_price = 0; // 유형별 금액
int ext_price = 0; // 추가 금액
String pay_method = ""; // 결재 방법 이름
int total = 0; // 총 결재 금액
int point = 0; // 포인트
if (type == 1) {
type_name = "캠핑";
type_price = 40000;
} else if (type == 2) {
type_name = "펜션";
type_price = 150000;
}
if (pay_way == 1) {
pay_method = "신용카드";
} else if (pay_way == 2) {
pay_method = "계좌이체(현금)";
} else if (pay_way == 3) {
pay_method = "모바일 결재";
} else if (pay_way == 4) {
pay_method = "포인트 결재";
}
ext_price = ext * 5000;
total = type_price + ext_price;
point = (int) (total * 0.07);
System.out.println("캠핑장 예약 내역");
System.out.println("유형: " + type_name + " | " + "가격: " + type_price + " 원");
System.out.println("추가인원: " + ext + "명" + " | " + "금액: " + ext_price + " 원");
System.out.println("----------------------------------------------------");
System.out.println("결재 방법: " + pay_method);
System.out.println("결재 금액: " + total + "(포인트: " + point + "원)");
}
}
-------------------------------------------------------------------------------------