MovieReview
package class1;
public class MovieReview {
String title;
String review;
}
MovieReviewMain
package class1.ex;
public class MovieReviewMain {
public static void main(String[] args) {
MovieReview movieReview1 = new MovieReview();
movieReview1.title = "인셉션";
movieReview1.review = "인생은 무한루프";
MovieReview movieReview2 = new MovieReview();
movieReview2.title = "어바웃 타임";
movieReview2.review = "인생 시간 영화!";
System.out.println("영화 제목: " + movieReview1.title + " 영화 리뷰: " + movieReview1.review);
System.out.println("영화 제목: " + movieReview2.title + " 영화 리뷰: " + movieReview2.review);
}
}
package class1.ex;
public class MovieReviewMain2 {
public static void main(String[] args) {
MovieReview movieReview1 = new MovieReview();
movieReview1.title = "인셉션";
movieReview1.review = "인생은 무한루프";
MovieReview movieReview2 = new MovieReview();
movieReview2.title = "어바웃 타임";
movieReview2.review = "인생 시간 영화!";
//MovieReview[] movieReviews = new MovieReview[2];
//MovieReview[] movieReviews = new MovieReview[] {movieReview1 , movieReview2};
MovieReview[] movieReviews = {movieReview1 , movieReview2};
// 일반 for문
for(int i = 0; i<movieReviews.length; i++) {
System.out.println("영화 제목: " + movieReviews[i].title + " 영화 리뷰: " + movieReviews[i].review);
}
// 강화된 for문
for(MovieReview m : movieReviews){
System.out.println("영화 제목: " + m.title + " 영화 리뷰: " + m.review);
}
}
}
ProductOrder
package class1.ex;
public class ProductOrder {
String productName; // 제품 이름
int price; // 상품 가격
int quentity; // 상품 수량
}
ProductOrderMain
package class1.ex;
public class ProductOrderMain {
public static void main(String[] args) {
// 상품 주문 정보를 담는 배열을 생성
ProductOrder[] orderList = new ProductOrder[3];
// 최종 금액을 알려줄 변수
int totalPrice = 0;
// 상품 정보를 저장
ProductOrder product1 = new ProductOrder();
product1.productName = "두부";
product1.price = 2000;
product1.quantity = 2;
orderList[0] = product1;
ProductOrder product2 = new ProductOrder();
product2.productName = "김치";
product2.price = 5000;
product2.quantity = 1;
orderList[1] = product2;
ProductOrder product3 = new ProductOrder();
product3.productName = "콜라";
product3.price = 1500;
product3.quantity = 2;
orderList[2] = product3;
for (ProductOrder po : orderList){
System.out.println("상품명: " + po.productName + " 가격: " + po.price + " 수량: " + po.quantity);
totalPrice += (po.price * po.quantity);
}
System.out.println("총 결제 금액: " + totalPrice);
}
}