Spread the word.

Share the link on social media.

Share
  • Facebook
Have an account? Sign In Now

Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

SIKSHAPATH

SIKSHAPATH Navigation

    • Home
    • Questions
    • Blog
      • Computer Science(CSE)
      • NPTEL
      • Startup
    • Shop
      • Internshala Answers
Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • Questions
  • Blog
    • Computer Science(CSE)
    • NPTEL
    • Startup
  • Shop
    • Internshala Answers
Home/ Questions/Q 5863
Next
In Process

SIKSHAPATH Latest Questions

SUMIT
  • -1
  • -1
SUMIT
Asked: November 18, 20212021-11-18T22:04:21+05:30 2021-11-18T22:04:21+05:30In: Programming Language

Define class EmailId with members, username, domainId and password. Define default and parameterized constructors. Accept values from the command line and create a date object. Throw user defined exceptions – “InvalidUsernameException” or “InvalidPasswordException” if the uaername and password are invalid. If the date is valid, display message “Valid Email Id”.

  • -1
  • -1

Define class EmailId with members, username, domainId and password. Define default and

parameterized constructors. Accept values from the command line and create a date object. Throw user

defined exceptions – “InvalidUsernameException” or “InvalidPasswordException” if the uaername and

password are invalid. If the date is valid, display message “Valid Email Id”.

java
  • 1 1 Answer
  • 4k Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    1 Answer

    • Voted
    • Oldest
    • Recent
    1. I'M ADMIN
      I'M ADMIN
      2023-02-19T13:00:11+05:30Added an answer on February 19, 2023 at 1:00 pm

      Use Offline IDE like Sublime, VScode , IntelliJ to run this code.

       

      package sikshapath; //create your own package
      import java.util.*;
      import java.text.DateFormat;
      import java.text.SimpleDateFormat;
      import java.util.Scanner;
      
      class EmailId
      {
      
          String domainID,username,password;
      
          EmailId()
          {
              domainID="K7";
              username="K";
              password="constructc000";
          }
      
          EmailId(String user,String pass,String domID)
          {
              domainID=domID;
              username=user;
              password=pass;
          }
      
          public static void main(String[] args) {
              String user,pass, domID;
              int p=-1,up=-1,u=-1,d=-1;
      
              EmailId obj=new EmailId();
      
              Scanner sc= new Scanner(System.in);
              System.out.println("Enter username: ");
              user=sc.nextLine();
              System.out.println("\nEnter password: ");
              pass=sc.nextLine();
              System.out.println("\nEnter Domain ID: ");
              domID=sc.nextLine();
              System.out.println("Enter a date in dd/mm/yyyy format :");
              String date = sc.next();
      
              EmailId obj1=new EmailId(user,pass,domID);
      
              if((obj.username).equals(obj1.username))
              {
                  u=1;
                  if(obj.password.equals(obj1.password))
                  {
                      up=1;
                  }
                  else
                  {
                      p=0;
                  }
              }
              else
              {
                  u=0;
              }
      
              if(dateValidation(date)==true)
                  d=1;
              else
                  d=0;
      
              if(d==1)
              {
                  if(u==0)
                  {
      
                      try{
                          throw new InvalidUsernameException(user);
                      }
      
                      catch (Exception e) {
                          System.out.println(e) ;
                      }
                  }
      
                  if (p==0){
                      {
                          try{
      
                              throw new InvalidPasswordException(pass);
                          }
                          catch (Exception e) {
                              System.out.println(e) ;
                          }
                      }
                  }
      
                  if(up==1)
                  {
                      System.out.println("Valid email id");
                  }
              }
              else{
                  System.out.println("Not a Valid email id");
              }
      
          }
      
          public static boolean dateValidation(String date)
          {
              boolean status = false;
      
              if (checkDate(date)) {
                  DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
                  dateFormat.setLenient(false);
                  try {
                      dateFormat.parse(date);
                      status = true;
                  } catch (Exception e) {
                      status = false;
                  }
              }
              return status;
          }
      
          static boolean checkDate(String date) {
              String pattern = "(0?[1-9]|[12][0-9]|3[01])\\/(0?[1-9]|1[0-2])\\/([0-9]{4})";
              boolean flag = false;
              if (date.matches(pattern)) {
                  flag = true;
              }
              return flag;
      
          }
      
      
      
      }
      
      class InvalidUsernameException extends Exception{
          String num1;
          InvalidUsernameException(String num2) {
              num1=num2;
          }
          public String toString(){
              return ("exception in thread ‘main’ InvalidUsernameException: Username: "+ num1 + " doesn’t match") ;
          }
      }
      
      class InvalidPasswordException extends Exception{
          String num1;
          InvalidPasswordException(String num2) {
              num1=num2;
          }
          public String toString(){
              return ("exception in thread ‘main’ InvalidPasswordException: Username: "+ num1 + " doesn’t match") ;
          }
      }
        • -2
      • Reply
      • Share
        Share
        • Share on WhatsApp
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    Sidebar

    store ads

    Stats

    • Questions 1k
    • Answers 1k
    • Posts 149
    • Best Answers 89
    • This Free AI Tool Translates Entire Books in Minute !
    • AI News: 🎬 Hollywood’s AI Studios, 🎓 OpenAI’s Latest Gift to Educators, 🚚 Class8 Bags $22M, 🧠 Google Gemini’s Memory Upgrade
    • AI NEWS: Legal Action Against OpenAI, $16M Paid, & Elon Musk’s Praise from Investor 🤖💰📑 | AI Boosts Cloud Seeding for Water Security 🌱💧
    • AI News: 🎬AI Video Tool Scam Exposed🤯, 🛰️ AI-Powered Drones to Ukraine 😱, Google’s $20M AI Push, Sam Altman Joins SF’s Leadership Team
    • AI News: 🤝 Biden Meets Xi on AI Talks, 💡 Xavier Niel’s Advice for Europe, ♻️ Hong Kong’s Smart Bin Revolution, 🚀 AI x Huawei

    Explore

    • Recent Questions
    • Questions For You
    • Answers With Time
    • Most Visited
    • New Questions
    • Recent Questions With Time

    Footer

    SIKSHAPATH

    Helpful Links

    • Contact
    • Disclaimer
    • Privacy Policy Notice
    • TERMS OF USE
    • FAQs
    • Refund/Cancellation Policy
    • Delivery Policy for Sikshapath

    Follow Us

    © 2021-24 Sikshapath. All Rights Reserved

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.

        Notifications