Question

Write an interface and two classes which will implements the interface. 1. Interface - StringVerification -...

Write an interface and two classes which will implements the interface.

1. Interface - StringVerification

- will have the abstract method defined - boolean verifyInput( String input );

2. class EmailVerification implements StringVerification

- implement the verifyInput() method in EmailVerification class. The method should validate a user input String, character by character and see the input string has a dot (.) and an at the rate (@) character in it. If any of the condition wrong the verifyInput method will return a false boolean value.

Example of a valid Email id – [email protected]

3. class PhoneVerification implements StringVerification

- implement the verifyInput() method in PhoneVerification class. The method should validate user input String, character by character and see, the input string is all digits and the phone number has exactly 10 digits. If any of the condition wrong, the verifyInput() method will return a false boolean value.

Example of a valid phone number – 5161112222

4. The client (Main) class

The client class should prompt for 2 entry from the console when running, as below.

System.out.print( "Enter the string to verify: " );

String input = scan.nextLine( );

System.out.println( "\nOur options are: "

+ "\n\t1 Email ID Verification"

+ "\n\t2 Phone number Verification");

System.out.print( "Select your verification option 1 or 2: " );

int option = scan.nextInt( );

Based on the screen input option (1 or 2), the appropriate class (EmailVerification or PhoneVerification) is instantiated and assign it to the object reference of – StringVerification.

For option 1, Email id string entered is verified using the EmailVerification classes verifyInput() method and an appropriate message is displayed, if it is a valid Email ID.

For option 2, Phone number string entered is verified using the PhoneVerification classes verifyInput() method and an appropriate message is displayed, if it is a valid Phone number.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//note if you hav e any quires comment it i will explian

import java.util.Scanner;

interface stringvrification{
   boolean vreifyinput(String input);
}
class emailverification implements stringvrification{

   @Override
   public boolean vreifyinput(String input) {
       boolean correct=false,correct1=false;
       for(int i=0;i<input.length();i++) {
           if(input.charAt(i)=='@') {
               correct=true;
           }
           if(input.charAt(i)=='.') {
               correct1=true;
           }
       }
       if(correct&&correct1){
           return true;
       }
       else {
           return false;
       }
   }
  
}

class phonenumberverification implements stringvrification{

   @Override
   public boolean vreifyinput(String input) {
       char[] chars= input.toCharArray();
       if(input.length()!=10)
       {
       return false;
       }
       else {
           for(char c : chars){
       if(Character.isDigit(c)){
         
       }
       else {
           return false;
       }
       }
       }
       return true;
   }
  
}
public class main{
   public static void main(String[]args) {
       System.out.println("select your verification option ");
       System.out.println("for email verification press 1 ");
       System.out.println("for phonenumber verification press 2");
       System.out.println("enter your choice");
       Scanner sc =new Scanner (System.in);
       int choice=sc.nextInt();
       System.out.println("enter the string");
       String input=sc.nextLine();
       if(choice==1) {
       emailverification email =new emailverification();
       if(email.vreifyinput(input)) {
           System.out.println("valid email");
       }
       else {
           System.out.println("not valid email");
       }
       }
       if(choice==2) {
       phonenumberverification phonenumber= new phonenumberverification();
   if(   phonenumber.vreifyinput(input)) {
       System.out.println("valid phone number");
   }
   else {
       System.out.println("invalid phone number");
   }
       }
      
   }

}

Add a comment
Know the answer?
Add Answer to:
Write an interface and two classes which will implements the interface. 1. Interface - StringVerification -...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This Exercise contains two classes: ValidateTest and Validate. The Validate class uses try-catch and Regex expressions...

    This Exercise contains two classes: ValidateTest and Validate. The Validate class uses try-catch and Regex expressions in methods to test data passed to it from the ValidateTest program. Please watch the related videos listed in Canvas and finish creating the 3 remaining methods in the class. The regular expression you will need for a Phone number is: "^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$" and for an SSN: "^\\d{3}[- ]?\\d{2}[- ]?\\d{4}$" This exercise is meant to be done with the video listed in the...

  • Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete...

    Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete programs using two classes: client and supplier 2   User Interface Specification This is a console-based I/O program. Display should go to System.out (print or println) and the program will get user input using the Scanner class. The flow of execution should be as follows: When the program starts, display a one-line introduction to the user Display a menu with 5 options 1. validate zip...

  • Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use impl...

    Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use implements Comparable<Book> in the class definition. Now, all book objects are instances of the java.lang.Comparable interface. Write a test program that creates an array of ten books. 1. Use Arrays.sort( Book[]l books) from the java.util package to sort the array. The order of objects in the array is determined using compareTo...) method. 2. Write a method that returns the most expensive book in the...

  • Requirements:  Your Java class names must follow the names specified above. Note that they are...

    Requirements:  Your Java class names must follow the names specified above. Note that they are case sensitive. See our template below.  BankAccount: an abstract class.  SavingAccount: a concrete class that extends BankAccount. o The constructor takes client's firstname, lastname and social security number. o The constructor should generate a random 6-digit number as the user account number. o The initial balance is 0 and the annual interest rate is fixed at 1.0% (0.01).o The withdraw method signature...

  • Using loops with the String and Character classes. You can also use the StringBuilder class to...

    Using loops with the String and Character classes. You can also use the StringBuilder class to concatenate all the error messages. Floating point literals can be expressed as digits with one decimal point or using scientific notation. 1 The only valid characters are digits (0 through 9) At most one decimal point. At most one occurrence of the letter 'E' At most two positive or negative signs. examples of valid expressions: 3.14159 -2.54 2.453E3 I 66.3E-5 Write a class definition...

  • In a file named LLBag.java, write a class called LLBag that implements the Bag interface using...

    In a file named LLBag.java, write a class called LLBag that implements the Bag interface using a linked list instead of an array. You may use a linked list with or without a dummy head node. Bag interface code: /* * Bag.java * * Computer Science 112, Boston University */ /* * An interface for a Bag ADT. */ public interface Bag { /*    * adds the specified item to the Bag. Returns true on success    * and...

  • Abstract classes and Interfaces problems 10. Explain one similarity and one difference between abstract classes and...

    Abstract classes and Interfaces problems 10. Explain one similarity and one difference between abstract classes and interfaces. 11. Consider the following declarations. public interface Shape{ int someFunction(Shape other); //other functions not shown } public class Square implements Shape {/*implementation not shown*/} Which of the following function headings of someFunction must be added to the declaration of the Square class such that it will satisfy the Shape interface? public int someFunction (Shape other) public int someFunction (Square other) public boolean someFunction(Object...

  • Open the Validate Number Solution.sln file contained in the VB2017\Chap07\Validate Number Solution folder. The interface provides...

    Open the Validate Number Solution.sln file contained in the VB2017\Chap07\Validate Number Solution folder. The interface provides a text box for entering a 9-digit number. The btnValidate_Click procedure should use the algorithm and example shown in Figure 7-56 to validate the user’s entry. The procedure should display a message indicating whether the entry is or is not valid. Code the procedure. Include any other code that will professionalize the interface. Save the solution and then start and test the application. Create...

  • Abstract classes and Interfaces problems 10. Explain one similarity and one difference between ab...

    Abstract classes and Interfaces problems 10. Explain one similarity and one difference between abstract classes and interfaces. 11. Consider the following declarations. public interface Shape{ int someFunction(Shape other); //other functions not shown } public class Square implements Shape {/*implementation not shown*/} Which of the following function headings of someFunction must be added to the declaration of the Square class such that it will satisfy the Shape interface? public int someFunction (Shape other) public int someFunction (Square other) public boolean someFunction(Object...

  • Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB....

    Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB. This interface should specify this abstract method: public abstract Product get(String productCode); Modify the ProductDB class so it implements the IProductDB interface. Write the code for the new ‘get’ method. Then remove the getProductByCode method. In the Main class, modify the code so it works with the new ProductDB class. This code should create an instance of the IProductDB interface like this: IProductDB db...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT