2024-10-29



메뉴는 몇 개로 할까요? : 3
1 번째 메뉴의 메뉴명과 단가, 수량을 입력하세요.
짜장면
5000
2
2 번째 메뉴의 메뉴명과 단가, 수량을 입력하세요.
짬뽕
6000
1
3 번째 메뉴의 메뉴명과 단가, 수량을 입력하세요.
우동
5500
2
-----------------------------------------
품명 단가 수량 금액
-----------------------------------------
짜장면 5,000 2 10,000원
짬뽕 6,000 1 6,000원
우동 5,500 2 11,000원
-----------------------------------------
공급가액 24,545원
부가세액 2,455원
-----------------------------------------
청구금액 27,000원
package exam;
public class Receipt {
// 멤버변수
String name; // 품명
int unitPrice; // 단가
int amount; // 수량
public Receipt() {} // 기본 생성자
public Receipt(String name, int unitPrice, int amount) {
this.name = name;
this.unitPrice = unitPrice;
this.amount = amount;
} // 인자 생성자
}
package exam;
import java.util.Scanner;
public class Receipt_06 {
// 클래스(정적 - static) 멤버 선언
public static final double TAX_RATE = 1.1;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("메뉴는 몇 개로 할까요? : ");
Receipt[] receipts = new Receipt[sc.nextInt()];
// 메뉴명, 단가, 수량을 키보드로 입력을 받아서 객체에 저장
for(int i=0; i<receipts.length; i++) {
System.out.println((i+1) + " 번째 메뉴의 메뉴명과 단가, 수량을 입력하세요.");
receipts[i] = new Receipt(
sc.next(), sc.nextInt(), sc.nextInt());
}
System.out.println();
int totalPrice = 0; // 총금액 변수
System.out.println("-----------------------------------------");
System.out.println("품명\t단가\t수량\t금액");
System.out.println("-----------------------------------------");
for(int i=0; i<receipts.length; i++) {
System.out.printf("%s\t%,d\t%,d\t%,d원\n",
receipts[i].name, receipts[i].unitPrice, receipts[i].amount,
(receipts[i].unitPrice * receipts[i].amount));
totalPrice += (receipts[i].unitPrice * receipts[i].amount);
}
// 공급가액 = 총금액(totalPrice) / 부가세율
int supplyPrice = (int)(totalPrice / Receipt_06.TAX_RATE);
// 부가세액 = 총금액(totalPrice) - 공급가액(supplyPrice)
int vat = totalPrice - supplyPrice;
System.out.println("-----------------------------------------");
System.out.printf("공급가액\t\t\t%,d원\n", supplyPrice);
System.out.printf("부가세액\t\t\t%,d원\n", vat);
System.out.println("-----------------------------------------");
System.out.printf("청구금액\t\t\t%,d원\n", totalPrice);
sc.close();
}
}'Java > 기초 내용 정리' 카테고리의 다른 글
| Java(Class2)_Inheritance_02 (0) | 2024.10.30 |
|---|---|
| Java(Class2)_Inheritance_01 (0) | 2024.10.30 |
| Java(Class&Method)_Exam_05 (0) | 2024.10.29 |
| Java(Class&Method)_Exam_04 (0) | 2024.10.29 |
| Java(Class&Method)_Exam_03 (0) | 2024.10.29 |