물음표 살인마의 개발블로그

객체 지향

객체 구현하기

BEstyle 2022. 9. 21. 17:31

 

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());
    }
}