ProductOrder product1 = new ProductOrder();
product1.productName = "tofu";
product1.price = 2000;
product1.quantity = 29;
ProductOrder product2 = new ProductOrder();
product2.productName = "kimchi";
product2.price = 3000;
product2.quantity = 43;
ProductOrder[] products = {product1, product2};
while(true) {
System.out.println("1. 목록 | 2. 계산");
int menu = scanner.nextInt();
if(menu == 1) {
for (int i=0; i<products.length; i++) {
list(products[i].productName, products[i].price, products[i].quantity);
}
} else if (menu == 2) {
for (int i=0; i<products.length; i++) {
balance(products[i].productName, products[i].price, products[i].quantity);
}
} else {
break;
}
}
}
public static void list(String name, int price, int quantity) {
System.out.println("상품명: "+name+", 가격: "+price+", 수량: "+quantity);
}
public static void balance(String name, int price, int quantity) {
System.out.println("상품명: "+name+", 가격: "+price*quantity);
}
}
자바 기본편을 수강하고 있다! 아직 수강을 끝내지는 못했다.
Section 1의 클래스와 객체부터, 다형성까지 앞으로 갈 길이 멀어보인다..
이번에는 충분히 많은 강의를 수강하지는 못해서, 대신 풀었던 문제 하나를 기록해보기로 했다.
package class1;
public class ProductOrder {
String productName;
int price;
int quantity;
}
클래스와 객체를 이용한 간단한 프로그램이었다. 아직 다른 강의를 수강중이어서 기록할 내용이 별로 없다..
기본편 수강 후에 더 채워넣겠습니다 ㅠ_ㅠ
'개발 > JAVA' 카테고리의 다른 글
2024 겨울 방캅스 (2) - 자바 입문 끝내기 (1) | 2024.02.11 |
---|