package org.lcq.util;
import java.util.Properties;
public class IntegralGrade {
private Properties pro = null;
private static final IntegralGrade ig = new IntegralGrade(); / /首先这里要声明静态的常量
// key-->value
private IntegralGrade() {//单态设计 //把构造方法声明为private私有的
this.pro = new Properties();
this.pro.setProperty("1", "开发爱好者");
this.pro.setProperty("2", "初级程序员");
this.pro.setProperty("3", "软件工程师");
this.pro.setProperty("4", "高级软件工程师");
this.pro.setProperty("5", "项目主管");
this.pro.setProperty("6", "项目经理");
this.pro.setProperty("7", "项目总监");
this.pro.setProperty("8", "首席技术执行官");
}
public static IntegralGrade getInstance(){ //声明一个静态的方法进行调用
return ig;
}
// 确认等级
public int getGrade(int ita) {
int grade = 0;
if (ita >= 0 && ita <= 300) {
grade = 1;
}
if (ita >= 301 && ita <= 1000) {
grade = 2;
}
if (ita >= 1001 && ita <= 5000) {
grade = 3;
}
if (ita >= 5001 && ita <= 10000) {
grade = 4;
}
if (ita >= 10001 && ita <= 20000) {
grade = 5;
}
if (ita >= 200001 && ita <= 50000) {
grade = 6;
}
if (ita >= 50001 && ita <= 100000) {
grade = 7;
}
if (ita >= 100001 && ita <= 500000) {
grade = 8;
}
return grade;
}
// 取得等级信息
public String getGradeInfo(int grade) {
String str = "";
str = this.pro.getProperty(grade + "");
return str == null ? "" : str;
}
public static void main(String[] args) {
IntegralGrade ita = new IntegralGrade();
System.out.println(ita.getGradeInfo(ita.getGrade(50002)));
}
}
---------------------------------------------------------
调用的方法如下:
IntegralGrade.getInstance().getGradeInfo(3);