μΌ | μ | ν | μ | λͺ© | κΈ | ν |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- SQL
- μ°μ μ°μ°μ
- μΉμ ν SQL
- μ€λ²λ‘λ©
- κ°μ²΄
- μ΄ν΄λ¦½μ€ μ€μΉ
- μμ
- join
- SpringSecurity λ‘κ·Έμμ
- μλ°μμ μ
- StringBuffer
- μΉμ ν SQL νλ
- @PreAuthorize("isAuthenticated()")
- SQL νλ
- SQLνλ
- μ€λ²λΌμ΄λ©
- μλ³μ
- λ Όλ¦¬ μ°μ°μ
- λ°λ³΅λ¬Έ
- λ°°μ΄
- ν¨μ
- μ°μ°μ
- SpringSecurity λ‘κ·ΈμΈ
- spring κ²μν μμ
- μ€νλ§μνλ¦¬ν° λ‘κ·Έμμ
- κ°μ²΄μ§ν₯
- java
- λΉκ΅ μ°μ°μ
- μμ½μ΄
- μΈν 리μ μ΄ Web μ ν리μΌμ΄μ
Archives
- Today
- Total
gi_dor
Java enum λ³Έλ¬Έ
728x90
πΈ enum (μ΄κ±°ν)
- 미리 κ°μ΄ μ ν΄μ Έ μλ νμ λ λ°μ΄ν°μ λ¬Άμ
- μ΄κ±°νμΌλ‘ μμλ₯Ό λ체 ν μ μλ€
β» κ³ κ°μ λ±κΈ : Gold , Shilver , Bronze
β» νμ : A , B , C , D
β» κ³μ : λ΄ , μ¬λ¦ , κ°μ , 겨μΈ
π μ΄κ±°ν μ μνκΈ°
public enum Grade {
GOLD , SILVER , BRONZE;
}
public enum Grade {
A(4.0) , B(3.0) , C(2.0) , D (1.0) ,F (0.0);
}
πΈ μμ
- μμλ νλ‘κ·Έλ¨μ΄ μ€νλλ λμ λ³νμ§ μλ κ° ( 미리 κ°μ΄ μ ν΄μ§ λ°μ΄ν° )
- public static final νμ μμμ΄λ¦ = κ°;
public class Constants{
public static final int GOLD =1;
public static final int SILVER = 2;
public static final int BRONZE = 3;
public static final double GOLD_POINT_DEPOSIT_RATE = 0.05;
public static final double SHILVER_POINT_DEPOSIT_RATE = 0.02;
public static final double BRONZE_POINT_DEPOSIT_RATE = 0.01;
public static final long MAX_UPLOAD_SIZE = 1024 * 1024 * 10 ;
}
πΉ μμλ₯Ό μ μνλ λͺ©μ
- κ°λ μ ν₯μ μν¨λ€.
- μ μ§λ³΄μμ±μ λμΈλ€.
- μμ μμμΈ Constants μμμ κ°μ λ³κ²½νκΈ°λ§ νλ©΄ ν΄λΉ μμ κ°μ μ¬μ©νλ λͺ¨λ ν΄λμ€μ λ³κ²½λ κ°μ΄ μ μ©λλ€
- μμ κ°λ€κ°μ μκ΄κ΄κ³κ° μλκ²½μ° 2λ°° 3λ°° 1/2λ°°...λ± μμκ°μ κ·Έ μκ΄ κ΄κ³λ₯Ό νννλ μμΌλ‘ μμ±νλ€
final double GOLD_DEPOSIT_RATE = 0.1;
final double SHILVER_DEPOSIT_RATE = GOLD_DEPOSIT_RATE/2;
final double BRONZE_DEPOSIT_RATE = GOLD_DEPOSIT_RATE/4;
final double GUEST_DEPOSIT_RATE = GOLD_DEPOSIT_RATE/8;
// μμ μ¬μ©μν¨
public int getDeposiPoint(int customerGrade , int amount) {
if(customerGrade == 1 ) {
return (int) (amount * 0.05);
} else if ( customerGrade == 2) {
return (int) (amount * 0.02 ) ;
} else if (customerGrade == 3 {
return (int) (amount * 0.01);
}
return 0;
}
// μμμ¬μ©
public int getDeposiPoint(int customerGrade , int amount) {
if(customerGrade == constants.GOLD ) {
return (int) (amount * 0.05);
} else if ( customerGrade == constants.SHILVER) {
return (int) (amount * 0.02 ) ;
} else if (customerGrade == constants.BRONZE {
return (int) (amount * 0.01);
}
return 0;
}
πΉ enum (μ΄κ±°ν)
μμ κ° (μμλ°μ΄ν°)μ μ§ν©μ΄ μ΄κ±°νμ΄λ€
πΉ νμ
enum (μ΄κ±°νμ΄λ¦) {
μμ , μμ , μμ;
}
- μ΄κ±°ν μ΄λ¦ : ν΄λμ€ μ΄λ¦μ²λΌ 첫λ²μ§Έ κΈμλ₯Ό λλ¬Έμλ‘ νκ³ λλ¨Έμ§λ μλ¬Έμλ‘ μμ±
- μμ : μ λΆ λλ¬Έμλ‘ μμ± , λλ¨μ΄ μ΄μ μ‘°ν©μΌ λ ' _ ' λ‘ μ°κ²°
πΉ enumμ μ₯μ
- νμ© κ°λ₯ν κ°λ€μ μ ν νλ€
• μ΄κ±°ν μμκ° νΉμ μ΄κ±°νμ μ ν¬ν¨λμ΄ μκΈ° λλ¬Έμ μ΄κ±°ν λ³μμ λμ κ°λ₯ν κ°μ
ν΄λΉ μ΄κ±°νμ μ΄κ±°μμλ€ λΏμ΄λ€
static final int GOLD = 1;
static final int SILVER = 2;
int customerGrade = GOLD;
int customerGrade = 100; // κ³ κ°λ±κΈκ³Ό μκ΄μλ κ°μ΄ λμ
λμ΄λ μλ¬κ° λ°μ μν¨
public enum Grade{
GOLD , SILVER , BRONZE;
}
Grade grade = Grade.GOLD;
Grade grade = 100; // μ»΄νμΌ μ€λ₯ λ°μ
- κ°λ°λꡬμ μλμμ± , λ¬Έλ²μ€λ₯ 체ν¬λ±μ μ§μλ°μμ μλ€
- 쑰건μμμ == μΌλ‘ λΉκ΅ κ°λ₯νκ³ , switchλ¬Έμμλ λ°λ‘ μ¬μ©μ΄ κ°λ₯νλ€
πΉ enum μ£Όμ λ΄μ₯ λ©μλ
String name()
μ΄κ±°κ°μ²΄κ° κ°μ§κ³ μλ λ¬Έμμ΄μ λ°ν , λ¬Έμμ΄μ μ΄κ±°μμμ μ΄λ¦κ³Ό λμΌνλ€
int ordinal()
μ΄κ±°κ°μ²΄μ μλ²μ(0λ²λΆν° μμνλ) λ°ννλ€
int compareTo(enum other)
μ§μ λ μ΄κ±°κ°μ²΄μ μλ²μ λΉκ΅ν΄μ μ μκ°μ λ°ννλ€
μ λ¬λ°μ λ€λ₯Έ μ΄κ±°κ°μ²΄μ μλ²λ³΄λ€ λΉ λ₯΄λ©΄ μμ
μ λ¬λ°μ λ€λ₯Έ μ΄κ±°κ°μ²΄μ μλ²λ³΄λ€ λ¦μΌλ©΄ μμ
enum valueOf(String name)
맀κ°λ³μλ‘ μ λ¬λ°μ λ¬Έμμ΄κ³Ό λμΌν μ΄λ¦μ κ°μ§λ μ΄κ±°κ°μ²΄λ₯Ό μμ±ν΄μ λ°ν
enum[] values()
ν΄λΉ μ΄κ±°νμ λͺ¨λ μ΄κ±°μμλ€μ λν μ΄κ±°κ°μ²΄λ₯Ό λ°°μ΄λ‘ λ°ν
μ΄κ±°κ°μ²΄ ----> λ¬Έμμ΄
Grade.GOLD name() "GOLD"
λ¬Έμμ΄ ----> μ΄κ±°κ°μ²΄
"GOLD" Grade.valueOf("GOLD") Grade.GOLD
π λ°λ‘ new μ°μ°μλ‘ κ°μ²΄λ₯Ό μμ±νμ§ μκ³ ν΄λΉ μ½λ μ²λΌ νλ©΄ Grade.GOLDκ° μ΄κ±° κ°μ²΄κ° λλ€
Grade grade = Grade.GOLD;
πΉ enumκ³Ό μμ κ° λ§€ννκΈ°
enum ScoreGrade{
public static final ScoreGrade μ = new ScroreGrade(90);
public static final ScoreGrade μ° = new ScroreGrade(80);
public static final ScoreGrade λ―Έ = new ScroreGrade(70);
public int score;
private ScoreGrade (int score) {
this.score = score;
}
public int getScore() {
return score;
}
728x90
'Language > Java' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
Java νλ‘μΈμ€μ μ€λ λ (1) | 2023.11.29 |
---|---|
Java I / O (0) | 2023.11.23 |
Java Exception (4) | 2023.11.22 |
Java μ λ€λ¦, 컬λ μ , Set , List , Map , Stack (1) | 2023.11.20 |
Java Iterator , Score CRUD (1) | 2023.11.17 |