1.
public class Customer {
int height;
int weight;
int age;
String name;
public Customer(int height, int weight, int age, String name) {
this.height = height;
this.weight = weight;
this.age = age;
this.name = name;
}
public String showCustomerInfo() {
return "키가 " + height
+ " 이고 몸무게가 " + weight
+ " 킬로인 남성이 있습니다. 이름은 "
+ name + " 이고 나이는 "
+ age + " 세 입니다.";
}
}
public class CustomerTest {
public static void main(String[] args) {
Customer Tomas = new Customer(180,78,37,"Tomas");
System.out.println(Tomas.showCustomerInfo());
}
}
2.
public class Delivery {
String orderNum;
String price;
String orderDate;
String phoneNum;
String address;
String orderTime;
String menuNum;
public Delivery(String orderDate, String price, String phoneNum, String address, String orderTime, String menuNum) {
this.orderNum = orderDate + menuNum;
this.orderDate = orderDate;
this.orderTime = orderTime;
this.price = price;
this.phoneNum = phoneNum;
this.address = address;
this.menuNum = menuNum;
}
public String showDeliveryInfo() {
return "주문 접수 번호 : " + orderDate + menuNum
+ "\n 주문 핸드폰 번호 : " + phoneNum
+ "\n 주문 집 주소 : " + address
+ "\n 주문 날짜 : " + orderDate
+ "\n 주문 시간 : " + orderTime
+ "\n 주문 가격 : " + price
+ "\n 메뉴 번호 : " + menuNum;
}
}
public class DeliveryTest {
public static void main(String[] args) {
Delivery d202011020003 = new Delivery("20201102","35000","01023450001","서울시 강남구 역삼동 111-333","130258","0003");
System.out.println( d202011020003.showDeliveryInfo());
}
}
'객체 지향' 카테고리의 다른 글
캡슐화 (encapsulation) (0) | 2022.09.22 |
---|---|
접근 제어 지시자(access modifier)와 정보 은닉(information hiding) (0) | 2022.09.22 |
생성자 (constructor) (0) | 2022.09.21 |
인스턴스 생성과 힙 메모리 (heap memory) (0) | 2022.09.21 |
객체 지향 입문 (0) | 2022.09.20 |