Question

In: Computer Science

Hello, I need to come up with the java code for a program that looks at...

Hello, I need to come up with the java code for a program that looks at bank Account ID's and checks if it is in the frame work of Letter followed by 4 numbers, so for example "A001". I need it to be its own method, named checkAccountID() that passes the accountID as an argument to check if it is in that framework of one letter followed by 4 numbers. Any ideas?

Solutions

Expert Solution

Java Code:

class AccountCheck {
   //Main method
   public static void main(String args[]) {
      
       //Creating object
       AccountCheck accChk = new AccountCheck();
      
       System.out.println("\n checkAccountID(\"A0123\"): " + accChk.checkAccountID("A0123"));
       System.out.println("\n checkAccountID(\"80123\"): " + accChk.checkAccountID("80123"));
       System.out.println("\n checkAccountID(\"A03\"): " + accChk.checkAccountID("A03"));
       System.out.println("\n checkAccountID(\"C2235\"): " + accChk.checkAccountID("C2235"));
      
   }
  
   //Method that validates Account ID
   public boolean checkAccountID(String ID) {
       //Checking length
       if(ID.length() != 5) {
           return false;
       }
      
       //Converting to char array
       char[] c = ID.toCharArray();
      
       //Checking first character
       int val = (int)c[0];
       if( (val >=65 && val <= 90) || (val >=97 && val <= 122) ) {
          
           //Checking for numbers
           for(int i=1; i<=4; i++) {
               val = (int)c[i];
              
               //Checking ascii value
               if(val < 48 || val > 57) {
                   return false;
               }
           }
          
           return true;
       }
       else {
           return false;
       }
   }
}

_____________________________________________________________________________________________________

Sample Run:


Related Solutions

I need to make this into a Java Code: Write a program that prompts the user...
I need to make this into a Java Code: Write a program that prompts the user for a double value representing a radius. You will use the radius to calculate: circleCircumference = 2πr circleArea = πr2 sphereArea = 4πr2 sphereVolume = 43πr3 You must use π as defined in the java.lang.Math class. Your prompt to the user to enter the number of days must be: Enter radius: Your output must be of the format: Circle Circumference = circleCircumference Circle Area...
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
I need the Java Code and Flowchart for the following program: Suppose you are given a...
I need the Java Code and Flowchart for the following program: Suppose you are given a 6-by-6 matrix filled with 0s and 1s. All rows and all columns have an even number of 1s. Let the user flip one cell (i.e., flip from 1 to 0 or from 0 to 1) and write a program to find which cell was flipped. Your program should prompt the user to enter a 6-by-6 array with 0s and 1s and find the first...
I need this in PSEUDO CODE: This looks long, but only because I have to give...
I need this in PSEUDO CODE: This looks long, but only because I have to give you my answer to the first part. First part of the questions (already answered) GDOT has contacted you to help write code to control the cross walk signals in Georgia. You must create a Crosswalk Signal class with three hidden attributes (Walk, Hurry and Wait), two constructors (a default that sets all lights to on and an overloaded that sets Hurry to on for...
I need this Java code transform to Python Code PROGRAM: import java.util.Scanner; public class Main {...
I need this Java code transform to Python Code PROGRAM: import java.util.Scanner; public class Main { static int count=0; int calculate(int row, int column) { count++; if(row==1&&column==1) { return 0; } else if(column==1) { return ((200+calculate(row-1,column))/2); } else if(column==row) { return (200+calculate(row-1,column-1))/2; } else { return ((200+calculate(row-1,column-1))/2)+((200+calculate(row-1,column))/2); }    } public static void main(String[] args) { int row,column,weight; Main m=new Main(); System.out.println("Welcome to the Human pyramid. Select a row column combination and i will tell you how much weight the...
I need original java code that completes this program and gets it to print out results...
I need original java code that completes this program and gets it to print out results just like in the example. Also please upload answer in a word document format only. Implement both linear search and binary search, and see which one performs better given an array 1,000 randomly generated whole numbers (between 0-999), a number picked to search that array at random, and conducting these tests 20 times. Each time the search is conducted the number of checks (IE...
I need a full java code. And I need it in GUI With the mathematics you...
I need a full java code. And I need it in GUI With the mathematics you have studied so far in your education you have worked with polynomials. Polynomials are used to describe curves of various types; people use them in the real world to graph curves. For example, roller coaster designers may use polynomials to describe the curves in their rides. Polynomials appear in many areas of mathematics and science. Write a program which finds an approximate solution to...
Hello I need a small fix in my program. I need to display the youngest student...
Hello I need a small fix in my program. I need to display the youngest student and the average age of all of the students. It is not working Thanks. #include <iostream> #include <iomanip> #include <fstream> #include <vector> #include <algorithm> using namespace std; struct Student { string firstName; char middleName; string lastName; char collegeCode; int locCode; int seqCode; int age; }; struct sort_by_age { inline bool operator() (const Student& s1, const Student& s2) { return (s1.age < s2.age); // sort...
Hello I am trying to come up with some answer for a Data mining project. And...
Hello I am trying to come up with some answer for a Data mining project. And need some better detailed answers for the following. 1. What is the issue with the usual linear regression? 2. What does lasso regression do? 3. What's the general theory about lasso? such as the formulas and the general properties of lambda? please kindly give a little explanation for each. Thankyou. (:
C++ Hello .I need to convert this code into template and then test the template with...
C++ Hello .I need to convert this code into template and then test the template with dynamic array of strings also if you can help me move the function out of the class that would be great.also There is a bug where the memory was being freed without using new operator. I cant seem to find it thanks in advance #include using namespace std; class DynamicStringArray {    private:        string *dynamicArray;        int size;    public:   ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT