看书不到一周,但是需要完成任务,关于对象的,其中的任意一个解决了都可以,谢谢大佬了

Level 0 : 搞个类(人,动物,车,书。。。),再搞个对象。(同学,朋友,室友,女盆友,~友。。。),并按以下格式打印出该对象的信息。

  {
    //属性:内容,(英文逗号隔开)
    "name":"kuang",
     "gender":"女",
     "faceValue":6,
     "height":160,
     "mind":"merry"
  }

要求:

  • 搞的类/对象必须5个属性及以上。
  • 严格遵守JAVA的基本类型语法。(字符串用“”双引号...等等等)
  • 严格遵循命名规范。(类名,方法名,属性名)


    • Level 1:将**以下字符串**以英文逗号拆分,并写一个至少含有以下方法中前三个方法的字符串工具类,对分割后的字符串一一判断,并打印判断结果。

    字符串: acbdw,1269547,AASIDX,AIUydjs,12sjaA,3819247,ausSHSzio,IUFISsi

  • 方法一:判断字符串是否全是数字

  • 方法二:判断字符串是否是大写字母

  • 方法三:判断字符串是否全是小写字母

  • 方法四:如果字符串全是字母,将其中所有小写字母转换为大写字母。

  • 方法五:如果字符串全是数字组成,则按照数字大小升序排序并装入整型数组中。最后按升序打印出该数组

  • 方法六:如果字符串全是字母组成,则按照字母排序装入字符数组中,并按字母顺序打印出该该数组。

转成json就可以了

package text;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class A {

public String name;
public String gender;
public int faceValue;
public int height;
public String mind;


public A(String name,String gender,int faceValue,int height,String mind){
     this.name=name;
     this.gender=gender;
     this.faceValue=faceValue;
     this.height=height;
     this.mind=mind;
}
public String toString(){

    String str = "{\n \"name\":\""+name+"\",\n\"gender\":\""+gender+"\",\n\"faceValue\":"+faceValue+",\n\"height\":"+height+",\n\"mind\":\""+mind+"\" \n}";
    return str;
}

public static void main(String[] args){
    A a = new A("kuang","女",6,160,"merry");
    System.out.println(a.toString());
    String str = "acbdw,1269547,AASIDX,AIUydjs,12sjaA,3819247,ausSHSzio,IUFISsi";
    String[] s = str.split(",");//字符串切割为数组
    for(int i=0;i<s.length;i++){
        B.isNumber(s[i]);
        B.isUpper(s[i]);
        B.isLower(s[i]);
        B.lowerToUpper(s[i]);
        B.numToArray(s[i]);
        B.letterToArray(s[i]);
    }
}

}
class B{
static String[] str;

//判断是否是数字
public static boolean isNumber(String str){
    boolean result=false;
        String regx = "[0-9]{0,"+str.length()+"}";
        result = str.matches(regx);
        System.out.println("字符串:"+str+"是纯数字吗?"+result);
    return result;
}
//判断是否全是大写字母
public static boolean isUpper(String str){
    boolean result =false;
        String regx = "[A-Z]{0,"+str.length()+"}";
        result = str.matches(regx);
        System.out.println("字符串:"+str+"是全大写字母吗?"+result);
    return result;
}
//判断是否全是小写字母
    public static boolean isLower(String str){
        boolean result =false;
            String regx = "[a-z]{0,"+str.length()+"}";
            result = str.matches(regx);
            System.out.println("字符串:"+str+"是全小写字母吗?"+result);
        return result;
    }
//小写转大写
    public static void lowerToUpper(String str){
        String newStr="";
            String regx = "[a-zA-Z]{0,"+str.length()+"}";
            if(str.matches(regx)){
                newStr = str.toUpperCase();
                System.out.println("字符串:"+str+"转大写后为:"+newStr);
            }

    }
    //纯数字转数组升序
    public static void numToArray(String str){
        String[] arr=null;
        int[] intArr = null;
        int e;
        if(isNumber(str)){
            intArr = new int[str.length()];
            arr = str.split("");
            for(int i=0;i<arr.length;i++){
                e=Integer.parseInt(arr[i]);
                intArr[i] = e;
            }
        }
        if(intArr!=null){
            Arrays.sort(intArr);
            System.out.println("纯数字字符串:"+str+"排序:"+Arrays.toString(intArr));
        }
    }
    //字母排序
    public static void letterToArray(String str){
        String[] s=null;
        if(str.matches("[a-zA-Z]{"+str.length()+"}")){
            s=str.split("");
            Arrays.sort(s);
            System.out.println("字符串"+str+"排序:"+Arrays.toString(s));
        }
    }

}

apache中的方法

方法一:判断字符串是否全是数字

/**
     * <p>Checks if the String contains only unicode digits.
     * A decimal point is not a unicode digit and returns false.</p>
     *
     * <p><code>null</code> will return <code>false</code>.
     * An empty String (length()=0) will return <code>true</code>.</p>
     *
     * <pre>
     * StringUtils.isNumeric(null)   = false
     * StringUtils.isNumeric("")     = true
     * StringUtils.isNumeric("  ")   = false
     * StringUtils.isNumeric("123")  = true
     * StringUtils.isNumeric("12 3") = false
     * StringUtils.isNumeric("ab2c") = false
     * StringUtils.isNumeric("12-3") = false
     * StringUtils.isNumeric("12.3") = false
     * </pre>
     *
     * @param str  the String to check, may be null
     * @return <code>true</code> if only contains digits, and is non-null
     */
    public static boolean isNumeric(String str) {
        if (str == null) {
            return false;
        }
        int sz = str.length();
        for (int i = 0; i < sz; i++) {
            if (Character.isDigit(str.charAt(i)) == false) {
                return false;
            }
        }
        return true;
    }

方法二:判断字符串是否是大写字母

/**
     * <p>Checks if the String contains only uppercase characters.</p>
     *
     * <p><code>null</code> will return <code>false</code>.
     * An empty String (length()=0) will return <code>false</code>.</p>
     *
     * <pre>
     * StringUtils.isAllUpperCase(null)   = false
     * StringUtils.isAllUpperCase("")     = false
     * StringUtils.isAllUpperCase("  ")   = false
     * StringUtils.isAllUpperCase("ABC")  = true
     * StringUtils.isAllUpperCase("aBC") = false
     * </pre>
     *
     * @param str  the String to check, may be null
     * @return <code>true</code> if only contains uppercase characters, and is non-null
     * @since 2.5
     */
    public static boolean isAllUpperCase(String str) {
        if (str == null || isEmpty(str)) {
            return false;
        }
        int sz = str.length();
        for (int i = 0; i < sz; i++) {
            if (Character.isUpperCase(str.charAt(i)) == false) {
                return false;
            }
        }
        return true;
    }

方法三:判断字符串是否全是小写字母

 /**
     * <p>Checks if the String contains only lowercase characters.</p>
     *
     * <p><code>null</code> will return <code>false</code>.
     * An empty String (length()=0) will return <code>false</code>.</p>
     *
     * <pre>
     * StringUtils.isAllLowerCase(null)   = false
     * StringUtils.isAllLowerCase("")     = false
     * StringUtils.isAllLowerCase("  ")   = false
     * StringUtils.isAllLowerCase("abc")  = true
     * StringUtils.isAllLowerCase("abC") = false
     * </pre>
     *
     * @param str  the String to check, may be null
     * @return <code>true</code> if only contains lowercase characters, and is non-null
     * @since 2.5
     */
    public static boolean isAllLowerCase(String str) {
        if (str == null || isEmpty(str)) {
            return false;
        }
        int sz = str.length();
        for (int i = 0; i < sz; i++) {
            if (Character.isLowerCase(str.charAt(i)) == false) {
                return false;
            }
        }
        return true;
    }

方法四:如果字符串全是字母,将其中所有小写字母转换为大写字母。

 /**
     * <p>Converts a String to upper case as per {@link String#toUpperCase()}.</p>
     *
     * <p>A <code>null</code> input String returns <code>null</code>.</p>
     *
     * <pre>
     * StringUtils.upperCase(null)  = null
     * StringUtils.upperCase("")    = ""
     * StringUtils.upperCase("aBc") = "ABC"
     * </pre>
     *
     * <p><strong>Note:</strong> As described in the documentation for {@link String#toUpperCase()},
     * the result of this method is affected by the current locale.
     * For platform-independent case transformations, the method {@link #lowerCase(String, Locale)}
     * should be used with a specific locale (e.g. {@link Locale#ENGLISH}).</p>
     *
     * @param str  the String to upper case, may be null
     * @return the upper cased String, <code>null</code> if null String input
     */
    public static String upperCase(String str) {
        if (str == null) {
            return null;
        }
        return str.toUpperCase();
    }

剩下两个可以自己写,呵呵!~~~