Study/Java
[java] 객체지향 실습
힝쏘
2019. 5. 14. 10:30
과제1>책값을 계산하는 프로그램을 만들어 보자.
교재 java, jsp, oracle 각각 가격이 30000, 25000, 15000 이다
교재 dc는 30000원 이상 25%할인, 20000원 이상 20%할인, 15000원 이상 15%할인
결과>java교재는 정가는 30000원 할인된 가격은 22500원입니다.
객체지향
책값 dc하는 메소드를 구현
책값을 출력하는 메소드도 따로 구현
test.java
class test
{
String bookname;
double bookprice;
double bookdc;
public test(String a, int b){
this.bookname = a;
this.bookprice = b;
}
double dc(double n)
{
if(n >= 30000)
{
bookdc = n-(n*0.25);
} else if (n >= 25000)
{
bookdc = n-(n*0.2);
}else if (n >= 15000)
{
bookdc = n-(n*0.15);
}
return bookdc;
}
public static void main(String[] args)
{
test t1 = new test("JAVA", 30000);
test t2 = new test("JSP", 25000);
test t3 = new test("ORACLE", 15000);
System.out.println(t1.bookname+ "교재의 정가는 " +(int)t1.bookprice+"원, ");
System.out.print("할인된 가격은 " +(int)t1.dc(t1.bookprice)+"원입니다.");
}
}