Question

The code I have so far:    public static boolean validPass(String sPass)    {    boolean...

The code I have so far:

   public static boolean validPass(String sPass)
   {
   boolean y=false;
   if(sPass.length()>10)
   {
   int i,j=0,k=0;
   char c;
   for(i=0;i<sPass.length();i++)
   {
         
   c=sPass.charAt(i);
   if(c>='A' && c<='Z')
   {
   j++;
   }
   else if(c>='a' && c<='z');
   else if (!(sPass.contains("&") || sPass.contains("-")
   || sPass.contains("%") || sPass.contains("_")
   ||sPass.contains("^")||sPass.contains("@")));
   else if(c>='0' && c<='9')
   {
   k++;
   }
   else
   {
   break;
   }
   }
   if(i==sPass.length())
   {
   if(k>2 && j>1)
   {
   y=true;
   }
   }
   }
   return y;
   }

   }

The test I'm failing:

String sValid1 = "Bryce^RON&123";
       assertTrue(Q4.validPass(sValid1));

Homework Answers

Answer #1
class Main
{
static boolean validPass(String sPass)
{
    if(sPass.length()>10)
    {
        int i,j=0,k=0,l=0;
        char c;
        for(i=0;i<sPass.length();i++)
        {
            c=sPass.charAt(i);
            if(c>='A' && c<='Z')
                j++;
            else if(c>='0' && c<='9')
                k++;
            else if(c>='a' && c<='z');
            else if (c=='&' || c=='-' || c=='%' || c=='_' || c=='^' || c=='@')
                l++;
            else
                return false;
        }
        if(k>2 && j>1 && l>0)
            return true;
   }
   return false;
}


public static void main(String[] args)
{
    String sValid1 = "Bryce^RON&123";
    System.out.println(validPass(sValid1));
}
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Here is my java code, I keep getting this error and I do not know how...
Here is my java code, I keep getting this error and I do not know how to fix it: PigLatin.java:3: error: class Main is public, should be declared in a file named Main.java public class Main { ^ import java.io.*; public class Main { private static BufferedReader buf = new BufferedReader( new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { String english = getString(); String translated = translate(english); System.out.println(translated); } private static String translate(String s) { String latin =...
[Java] I'm not sure how to implement the code. Please check my code at the bottom....
[Java] I'm not sure how to implement the code. Please check my code at the bottom. In this problem you will write several static methods to work with arrays and ArrayLists. Remember that a static method does not work on the instance variables of the class. All the data needed is provided in the parameters. Call the class Util. Notice how the methods are invoked in UtilTester. public static int min(int[] array) gets the minimum value in the array public...
in java need uml diagram import java.util.ArrayList; import java.util.*; public class TodoList { String date=""; String...
in java need uml diagram import java.util.ArrayList; import java.util.*; public class TodoList { String date=""; String work=""; boolean completed=false; boolean important=false; public TodoList(String a,String b,boolean c,boolean d){ this.date=a; this.work=b; this.completed=c; this.important=d; } public boolean isCompleted(){ return this.completed; } public boolean isImportant(){ return this.important; } public String getDate(){ return this.date; } public String getTask(){ return this.work; } } class Main{ public static void main(String[] args) { ArrayList<TodoList> t1=new ArrayList<TodoList>(); TodoList t2=null; Scanner s=new Scanner(System.in); int a; String b="",c=""; boolean d,e; char...
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String...
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String courseName;     private String[] students = new String[1];     private int numberOfStudents;     public COurseCom666(String courseName) {         this.courseName = courseName;     }     public String[] getStudents() {         return students;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public void addStudent(String student) {         if (numberOfStudents == students.length) {             String[] a = new String[students.length + 1];            ...
Consider the following two methods: public static boolean isTrue(int n){        if(n%2 == 0)          ...
Consider the following two methods: public static boolean isTrue(int n){        if(n%2 == 0)           return true;        else           return false; } public static int Method(int[] numbers, int startIndex) { if(startIndex >= numbers.length)        return 0; if (isTrue(numbers[startIndex]))      return 1 + Method(numbers, startIndex + 1); else      return Method(numbers, startIndex + 1); } What is the final return value of Method() if it is called with the following parameters: numbers = {1, 2, 2, 3, 3,...
How can I alter this Java method so that I convert and then return every sentence...
How can I alter this Java method so that I convert and then return every sentence in the array of strings instead of just the first sentence? public static char[] charConvert ( String [] sentences ) { int totLength = sentences[0].length() + sentences[1].length() + sentences[2].length() + sentences[3].length() + sentences[4].length(); char [] letter = new char[totLength]; int x = 0; int y = 0;    while ( y < sentences[x].length() ) { switch ( sentences[x].charAt(y) ) { case 'a': case 'A':...
This is the java code that I have, but i cannot get the output that I...
This is the java code that I have, but i cannot get the output that I want out of it. i want my output to print the full String Form i stead of just the first letter, and and also print what character is at the specific index instead of leaving it empty. and at the end for Replaced String i want to print both string form one and two with the replaced letters instead if just printing the first...
Takes two ints as parameters. Determines the remainder when the first int is divided by the...
Takes two ints as parameters. Determines the remainder when the first int is divided by the second. If the remainder is 0 or 1 return true otherwise false. ----------------------------------------------- public class Class1 { public static boolean closeEnough (int i, int j) {     //Enter code here } }
Consider the following Java program : public static void main (string args [ ]) { int...
Consider the following Java program : public static void main (string args [ ]) { int result, x ; x = 1 ; result = 0; while (x < = 10) { if (x%2 == 0) result + = x ; + + x ; } System.out.println(result) ; } } Which of the following will be the output of the above program? A. 35 B. 30 C. 45 D. 35 2. public static void main(String args[]) { int i =...
Provide A UML for the Following CODE public class Employee{ public String strName, strSalary; public Employee(){...
Provide A UML for the Following CODE public class Employee{ public String strName, strSalary; public Employee(){    strName = " ";    strSalary = "$0";    } public Employee(String Name, String Salary){    strName = Name;    strSalary = Salary;    } public void setName(String Name){    strName = Name;    } public void setSalary(String Salary){    strSalary = Salary;    } public String getName(){    return strName;    } public String getSalary(){    return strSalary;    } public String...