728x90
import java.util.Scanner;
class Product
{
String code, name;
int price, discount;
Product(String code, String name, int price, int discount)
{
this.code=code;
this.name=name;
this.price=price;
this.discount=discount;
}
Product(String code, String name, int price)
{
this.code=code;
this.name=name;
this.price=price;
this.discount=0;
}
void setDiscount(int discount){this.discount=discount;}
int calcPrice(){return price-(price*discount/100);}
}
class Q1
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
Product []p=new Product[5];
p[0]=new Product("A001", "초코송이", 1000, 10);
p[1]=new Product("A002", "참크래커", 1500, 20);
p[2]=new Product("A003", "수미칩", 2000, 15);
p[3]=new Product("B001", "밀키스", 1000);
p[4]=new Product("B002", "레쓰비", 700);
while(true)
{
System.out.print("메뉴 선택(1:상품조회, 2:할인율변경, 3:종료) : ");
int menu=sc.nextInt();
switch(menu)
{
case 1:
System.out.println("상품코드\t상품명\t표준단가\t판매가");
for(int i=0;i<5;i++)
{
System.out.println(p[i].code+"\t"+p[i].name+"\t"+p[i].price+"\t"+p[i].calcPrice());
}
break;
case 2:
System.out.print("할인율 변경할 상품코드 : ");
String c=sc.next();
System.out.print("변경 할인율 : ");
int dis=sc.nextInt();
for(int i=0; i<p.length; i++)
{
if(c.equals(p[i].code))
{
p[i].setDiscount(dis);
}
}
System.out.println("변경되었습니다.");
break;
case 3:
System.out.println("종료합니다.");
break;
}
if(menu==3){break;}
}
}
}는 과제
'it > programming' 카테고리의 다른 글
| [JAVA] 메소드 생성자 사용 League of Legends 상점구현 (0) | 2013.04.20 |
|---|---|
| [JAVA] 메소드 함수 사용하기 (0) | 2013.04.10 |
| [JAVA] 객체 프로그래밍 (0) | 2013.04.03 |