Java(Class&Method)_Exam_06

2024. 10. 29. 17:24·Java/기초 내용 정리

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
'Java/기초 내용 정리' 카테고리의 다른 글
  • Java(Class2)_Inheritance_02
  • Java(Class2)_Inheritance_01
  • Java(Class&Method)_Exam_05
  • Java(Class&Method)_Exam_04
mw41817
mw41817
일생의 개발 기록 저장소
  • mw41817
    IT 개발 일지
    mw41817
    • Index (487)
      • HTML (36)
        • 기초 내용 정리 (36)
      • CSS (29)
        • 기초 내용 정리 (29)
      • JavaScript (60)
        • 기초 내용 정리 (60)
      • JQuery (38)
        • 기초 내용 정리 (38)
      • Java (232)
        • 기초 내용 정리 (232)
      • JSP (46)
        • 기초 내용 정리 (46)
      • Spring, Boot (31)
        • 기초 내용 정리 (31)
      • DB (5)
        • Oracle SQL (5)
      • Code WorkBook (6)
        • programmers (6)
        • Baekjoon (0)
      • 기타 (1)
        • 유용한 사이트 (3)
  • 전체
    오늘
    어제
  • 글쓰기 관리
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 카테고리
    • 주인장 GitHub
  • 공지사항

  • 인기 글

  • 태그

    html #코딩 #프로그래밍 #기초
  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.0
mw41817
Java(Class&Method)_Exam_06
상단으로

티스토리툴바