본문 바로가기
java&eclipse 코딩 알고리즘/20231215

Customer

by 몽상크리에이터 2023. 12. 15.

package com.tjoeun.customer;

 

import java.text.DecimalFormat;

import java.text.NumberFormat;

import java.util.Objects;

 

// 부모 클래스

// 일반 고객 정보를 기억하는 클래스

public class Customer {

 

private int customerID; // 고객 ID

private String customerName; // 고객 이름

private String customerGrade; // 고객 등급

private int bonusPoint; // 보너스 포인트

private double bonusRatio; // 보너스 포인트 적립 비율

 

public Customer() {

// 신규 고객 카드 발급

customerGrade = "SILVER";

bonusRatio = 0.01;

}

 

 

public int getCustomerID() {

return customerID;

}

 

public void setCustomerID(int customerID) {

this.customerID = customerID;

}

 

public String getCustomerName() {

return customerName;

}

 

public void setCustomerName(String customerName) {

this.customerName = customerName;

}

 

public String getCustomerGrade() {

return customerGrade;

}

 

public void setCustomerGrade(String customerGrade) {

this.customerGrade = customerGrade;

}

 

public int getBonusPoint() {

return bonusPoint;

}

 

public void setBonusPoint(int bonusPoint) {

this.bonusPoint = bonusPoint;

}

 

public double getBonusRatio() {

return bonusRatio;

}

 

public void setBonusRatio(double bonusRatio) {

this.bonusRatio = bonusRatio;

}

 

@Override

public String toString() {

return "고객번호=" + customerID + ", 고객명=" + customerName + ", 고객등급="

+ customerGrade + ", 포인트=" + bonusPoint + ", 적립비율=" + bonusRatio;

}

 

// 회원 정보를 리턴하는 메소드

// 이몽룡님의 등급은 SILVER이며, 보너스 포인트는 1,000점 입니다. <<< 출력 형태

 

public String showCustomerInfo() {

// DecimalFormat df = new DecimalFormat("#,##0");

NumberFormat nf = NumberFormat.getNumberInstance();

return customerName + "님의 등급은 " + customerGrade + "이며, 보너스 포인트는 "

+ nf.format(bonusPoint) + "점 입니다.";

}

 

// 구매 금액을 인수로 넘겨받아 포너스 포인트를 계산해서 리턴하는 메소드

public int calcBonus(int price) {

return (int) (price * bonusRatio);

}

 

// 구매 금액을 인수로 넘겨받아 누적 포너스 포인트를 계산해서 리턴하는 메소드

public int calcPrice(int price) {

// bonusPoint += price * bonusRatio;

// 대입연산자 자동으로 캐스팅 해줌

// bonusPoint += (bonusPoint의 자료형)(price * bonusRatio)

// bonusPoint = (int)(bonusPoint + price * bonusRatio); // 정수 + 실수 => 정수형 자료에 실수 수동변환 필요

// https://docs.oracle.com/javase/specs/jls/se14/html/jls-15.html#jls-15.26.2 << 오라클 공식 문서의 대입연산자 설명

bonusPoint += calcBonus(price);

return bonusPoint;

}

 

 

 

 

}

'java&eclipse 코딩 알고리즘 > 20231215' 카테고리의 다른 글

CustomerTest  (0) 2023.12.15
VIPCustomer  (0) 2023.12.15
ClassIncludeTest  (0) 2023.12.15
Parent  (0) 2023.12.15
Child  (0) 2023.12.15