增加处理类

时间:2016-07-15 00:35:34

标签: java arrays static field private-methods

我正在研究这个类项目,我必须开发一个程序,测试用户输入的字符串是否符合条件。为了更加了解,源代码将发布在底部。虽然我制作了阵列" u []"静态,它不会被for循环增加。

主要类

package GroupX;

import java.util.Scanner;

public class GbeApp{

  public static void main(String[] args){

      Scanner kb= new Scanner(System.in);
      GbeClass gbebObject= new GbeClass();

      System.out.print("Please enter a password that meets the following criteria:\nat least six characters long\nat least one uppercase and lowercase letter\nand at least one digit\n");

         String temp= kb.nextLine();
         gbeObeject.setPass(temp);//@param String password
         System.out.println(gbebObject.getTest());
  }

}

Gbe Processsing Class

package Groupx;
import java.lang.*;
public class GbeClass{
   public String password;
   private static int u[]= {0,0,0,0};/*here is the issue, the for loop doesnt increment this array */

   public void test(){
      for(int x= 0; x <= password.length()- 1; x++){
          if(Character.isUpperCase(password.charAt(x)))
             u[0]++;
          else if(Character.isLowerCase(password.charAt(x)))
             u[1]++;
          else if(Character.isDigit(password.charAt(x)))
             u[2]++;
          else
             u[3]++;
       }
    }
    public String getTest(){
         if(password.length() <6)
            return "The password must be at least 6 characters or more in length. Please try again";
         if(u[0] <= 0)
            return "The password must contain an uppercase letter. Please try again";
         if(u[1] <= 0)
            return "The password must contain a lowercase letter. Please try again";
         if(u[2] <= 0)
            return "The password must contain a digit.  Please try again";
         else
            return "The password meets the criteria!";
    }
}

0 个答案:

没有答案