频道栏目
首页 > 程序开发 > 软件开发 > Java > 正文
java自动生成随机中文类
2011-06-19 15:34:58      个评论      
收藏   我要投稿


import java.io.UnsupportedEncodingException;

import java.util.Date;

import java.util.Random;

 

public class ChineseUtils {

 private static Random random = null;

 

 private static Random getRandomInstance() {

  if (random == null) {

   random = new Random(new Date().getTime());

  }

  return random;

 }

 

 public static String getChinese() {

  String str = null;

  int highPos, lowPos;

  Random random = getRandomInstance();

  highPos = (176 + Math.abs(random.nextInt(39)));

  lowPos = 161 + Math.abs(random.nextInt(93));

  byte[] b = new byte[2];

  b[0] = (new Integer(highPos)).byteValue();

  b[1] = (new Integer(lowPos)).byteValue();

  try {

   str = new String(b, "GB2312");

  } catch (UnsupportedEncodingException e) {

   e.printStackTrace();

  }

  return str;

 }

 

 public static String getFixedLengthChinese(int length) {

  String str = "";

  for (int i = length; i > 0; i--) {

   str = str + ChineseUtils.getChinese();

  }

  return str;

 }

 

 public static String getRandomLengthChiness(int start, int end) {

  String str = "";

  int length = new Random().nextInt(end + 1);

  if (length < start) {

   str = getRandomLengthChiness(start, end);

  } else {

   for (int i = 0; i < length; i++) {

    str = str + getChinese();

   }

  }

  return str;

 }

 

 public static String getUserName(int betweenZeroAndSix) {

  switch (betweenZeroAndSix) {

  case 0:

   return "Baul";

  case 1:

   return "Ebony";

  case 2:

   return "Tony";

  case 3:

   return "Charles";

  case 4:

   return "Pebbles";

  case 5:

   return "Queen";

  default:

   return "Kismet";

  }

 }

 

 public static String getSupplierName(int betweenZeroAndSix) {

  switch (betweenZeroAndSix) {

  case 0:

   return "Ulrika";

  case 1:

   return "Unity";

  case 2:

   return "Zelene";

  case 3:

   return "Shelby";

  case 4:

   return "Coleman";

  case 5:

   return "Fielding";

  default:

   return "Sabrina";

  }

 }

 

 public static String getHotelName(int betweenZeroAndThirty) {

  switch (betweenZeroAndThirty) {

  case 0:

   return "新中央酒店";

  case 1:

   return "格兰";

  case 2:

   return "东亚酒店";

  case 3:

   return "帝濠酒店";

  case 4:

   return "财神酒店";

  case 5:

   return "澳门富华粤海酒店";

  case 6:

   return "金皇冠中国大酒店";

  case 7:

   return "金龙酒店";

  case 8:

   return "英皇娱乐酒店";

  case 9:

   return "金都酒店";

  case 10:

   return "君怡酒店";

  case 11:

   return "东望洋酒店";

  case 12:

   return "假期酒店";

  case 13:

   return "澳门假日酒店";

  case 14:

   return "澳门假日酒店";

  case 15:

   return "康泰酒店";

  case 16:

   return "澳门富豪酒店";

  case 17:

   return "皇家金堡酒店";

  case 18:

   return "环球酒店";

  case 19:

   return "莱斯酒店";

  case 20:

   return "回力酒店";

  case 21:

   return "金域酒店";

  case 22:

   return "置地广场酒店";

  case 23:

   return "葡京酒店";

  case 24:

   return "英京酒店";

  case 25:

   return "万事发酒店";

  case 26:

   return "文华";

  case 27:

   return "文华东方酒店";

  case 28:

   return "维景酒店";

  case 29:

   return "新世纪酒店";

  default:

   return "利澳酒店";

  }

 }

 

 public static String getNationality(int betweenZeroAndTen) {

  switch (betweenZeroAndTen) {

  case 0:

   return "Egypt";

  case 1:

   return "Azerbaijan";

  case 2:

   return "Ireland";

  case 3:

   return "Estonia";

  case 4:

   return "Austria";

  case 5:

   return "Anguilla";

  case 6:

   return "Macau";

  case 7:

   return "Barbados";

  case 8:

   return "Papua New Guinea";

  case 9:

   return "Poland";

  case 10:

   return "Iceland";

  default:

   return "China";

  }

 }

 

 public static String getCustomerName(int betweenZeroAndTen) {

  switch (betweenZeroAndTen) {

  case 0:

   return "Brishen";

  case 1:

   return "Andy";

  case 2:

   return "Tony";

  case 3:

   return "Wayne";

  case 4:

   return "Jhon";

  case 5:

   return "PaPa";

  case 6:

   return "Juyne";

  case 7:

   return "Marry";

  case 8:

   return "Harmony";

  case 9:

   return "Brandon";

  case 10:

   return "Carlyle";

  default:

   return "

点击复制链接 与好友分享!回本站首页
相关TAG标签 中文类 自动生成
上一篇:走在组件化的路上(六)——JSF的优势之自定义组件与模块化
下一篇:JAVA中数组排序小结
相关文章
图文推荐
点击排行

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站