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...
8.15 *zyLab: Method Library (Required & Human Graded) This code works but there are some problems...
8.15 *zyLab: Method Library (Required & Human Graded) This code works but there are some problems that need to be corrected. Your task is to complete it to course style and documentation standards CS 200 Style Guide. This project will be human graded. This class contains a set of methods. The main method contains some examples of using the methods. Figure out what each method does and style and document it appropriately. The display method is done for you and...
I'm trying to find a code to check the occurrences of the word or string I...
I'm trying to find a code to check the occurrences of the word or string I wrote my own code but it's not working can you please help and fix my code #include <stdio.h> #include <string.h> #define MAX_SIZE 100 // Maximum string size int main() { char str[MAX_SIZE]; char tosearch[MAX_SIZE]; printf("Enter any string: "); gets(str); printf("Enter word to search occurrences: "); gets(tosearch); int cursor = 0; int i = 0; int stringLen = 0; int searchLen = 0; int count1;...
public class PalindromeChecker { /** * Method that checks if a phrase or word is *...
public class PalindromeChecker { /** * Method that checks if a phrase or word is * a Palindrome * * @param str * Represents a string input * * @return true * True if the string is a Palindrome, * false otherwise */ public static boolean isPalindrome(String str) { if (str == null) { return false; } str = str.toLowerCase(); String temp = ""; for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if ((ch...
import java.util.Scanner; import java.io.*; public class P1 { static final int ROW = 1000; static final...
import java.util.Scanner; import java.io.*; public class P1 { static final int ROW = 1000; static final int COL = 667; public static void readImage(int[][][] startImage, String fileName) { Scanner inputF = new Scanner(fileName); int row = 0, col = 0; int line = 1; while (inputF.hasNext()) { if (line <= 4) { inputF.nextLine(); line++; } else { line += 3; if (col < COL) { startImage[row][col][0] = inputF.nextInt(); startImage[row][col][1] = inputF.nextInt(); startImage[row][col][2] = inputF.nextInt(); col++; } else { row++; col...
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,...
What is the output of the following code segment? public class Exception { ... static int...
What is the output of the following code segment? public class Exception { ... static int divider(int x, int y) { try { return x/y; } catch (ArrayIndexOutOfBoundsException a) { System.out.print("A"); return 1; } } static int computer(int x, int y) { try { return divider(x,y); } catch (NullPointerException b) { System.out.print("B"); } return 2; } public static void main(String args[]){ try { int i = computer (100, 0); } catch (ArithmeticException c) { System.out.print("C"); } } } ABC A...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT