Question

Assignment 14.3: Valid Email (10 pts)

image source

Intenet E nail Address Your e-mai addess ia the addresa other people use to send e-mail messeges to you E-mail adresz mnichGb

  • Write a program that takes as input an email address, and reports to the user whether or not the email address is valid.
  • For the purposes of this assignment, we will consider a valid email address to be one that contains an @ symbol
  • The program must allow the user to input as many email addresses as desired until the user enters "q" to quit.
  • For each email entered, the program should display "That email address is valid" or "That email address is invalid"
  • Note that you are not allowed to use any String methods other than substring, charAt, and length in this program, and are required to use a for loop to iterate the String as demonstrated during today's lesson.
  • You are also required to use the starter code provided below. Please do not change this starter code. Instead, you can add more lines of code to it.
  • Name your program Email.java and upload it to Canvas once it is working as shown in the sample output below

Starter Code

/**

* @author

* CIS 36A

*/

import java.util.Scanner;

public class Email {

    public static void main() {

        String email = "";

        Scanner input = new Scanner(System.in);

        //Welcome and prompt user here

        while (!email.equalsIgnoreCase("q")) {

           boolean isValid = false;

            //add your for loop here

       if (isValid) {

            System.out.println("The email address is valid.");

        } else {

            System.out.println("The email address is invalid.");

        }

        }

        

    }

}

The output of your program should look identical to the sample output below except user input may vary.

Welcome! Enter an email and I will tell you if it is valid.

Please enter an email or q to quit: [email protected]

That email address is valid.

Please enter an email or q to quit: bobajobs.com

That email address is invalid

Please enter an email or q to quit: bob@jobs

That email address is valid.

Please enter an email or q to quit: q

Goodbye!

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

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

/**

* @author

* CIS 36A

*/

import java.util.Scanner;

public class Email {

                public static void main(String[] args) {

                                String email = "";

                                Scanner input = new Scanner(System.in);

                                // Welcome user and prompt for input

                                System.out

                                                               .println("Welcome! Enter an email and I will tell you if it is valid.\n");

                                System.out.print("Please enter an email or q to quit: ");

                                email = input.nextLine();

                                while (!email.equalsIgnoreCase("q")) {

                                               boolean isValid = false;

                                               // looping through each index on email string

                                               for (int i = 0; i < email.length(); i++) {

                                                               //checking if current character is '@'

                                                               if (email.charAt(i) == '@') {

                                                                               //valid

                                                                               isValid = true;

                                                                               //end of loop

                                                                               break;

                                                               }

                                               }

                                               if (isValid) {

                                                               System.out.println("The email address is valid.");

                                               } else {

                                                               System.out.println("The email address is invalid.");

                                               }

                                               System.out.print("Please enter an email or q to quit: ");

                                               email = input.nextLine();

                                }

                                System.out.println("Goodbye!");

                }

}

/*OUTPUT*/

Welcome! Enter an email and I will tell you if it is valid.

Please enter an email or q to quit: [email protected]

The email address is valid.

Please enter an email or q to quit: bobajobs.com

The email address is invalid.

Please enter an email or q to quit: bob@jobs

The email address is valid.

Please enter an email or q to quit: q

Goodbye!

Add a comment
Know the answer?
Add Answer to:
Assignment 14.3: Valid Email (10 pts) image source Write a program that takes as input an...
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
  • User Profiles Write a program that reads in a series of customer information -- including name,...

    User Profiles Write a program that reads in a series of customer information -- including name, gender, phone, email and password -- from a file and stores the information in an ArrayList of User objects. Once the information has been stored, the program should welcome a user and prompt him or her for an email and password The program should then use a linearSearch method to determine whether the user whose name and password entered match those of any of...

  • Write a program that takes in a line of text as input, and outputs that line of text in reverse.

    Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text.Ex: If the input is:Hello there Hey quitthen the output is:ereht olleH yeHThere is a mistake in my code I can not find. my output is : ereht olleH ereht olleHyeHHow can I fix this?I saw some people use void or the function reverse but we didnt...

  • in java Complete Program that simulates a login procedure. The program reads a list of names,...

    in java Complete Program that simulates a login procedure. The program reads a list of names, email addresses and passwords from a file p3.txt. Store the information in parallel array lists names, emails and passwords. Your program will prompt the user for their email address. If the email is not in the system, prompt the user to try again. Provide the option to quit. If the email is found in the system, prompt the user to enter their password. After...

  • /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid...

    /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid input examples: F00D, 000a, 1010, FFFF, Goodbye, BYE Enter BYE (case insensitive) to exit the program. ****************************************************/ import java.util.Scanner; public class HexUtilitySOLUTION { public static void main(String[] args) { // Maximum length of input string final byte INPUT_LENGTH = 4; String userInput = ""; // Initialize to null string Scanner input = new Scanner(System.in); // Process the inputs until BYE is entered do {...

  • Write a program that takes in a line of text as input, and outputs that line...

    Write a program that takes in a line of text as input, and outputs that line of text in reverse. You may assume that each line of text will not exceed 50 characters. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text. Ex: If the input is: Hello there Hey quit then the output is: ereht olleH уен Hint: Use the fgets function to read a string with spaces from the user...

  • Please help me write down a program to check email address valid or not. Tip:parse the...

    Please help me write down a program to check email address valid or not. Tip:parse the string and count the special characters like '@', '.' .and at least one character. Suggested libc functions: printf() 1.Have to be by the argc/argv of main function 2.Connot use scanf/getchar and other user input functions 3.Please explain the details and steps for me cause I'm a beginner hhhhhh Thank you soooo much for helping me!

  • Extend this date validation program, so that it checks for valid leap years (in which the...

    Extend this date validation program, so that it checks for valid leap years (in which the month February has 29, instead of 28, days). A leap year is any year that is divisible by 4 but not divisible by 100, unless it is also divisible by 400. Do not allow February to have 29 days on years that are not leap years. **Please view both photos for the entire code and post new code with the leap year modification. Thank...

  • Please write in dr java Here is the driver: import java.util.*; public class SquareDriver { public...

    Please write in dr java Here is the driver: import java.util.*; public class SquareDriver { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String input =""; System.out.println("Welcome to the easy square program"); while(true) { System.out.println("Enter the length of the side of a square or enter QUIT to quit"); try { input = keyboard.nextLine(); if(input.equalsIgnoreCase("quit")) break; int length = Integer.parseInt(input); Square s = new Square(); s.setLength(length); s.draw(); System.out.println("The area is "+s.getArea()); System.out.println("The perimeter is "+s.getPerimeter()); } catch(DimensionException e)...

  • In python 3, 1. Write a program that takes a number of credit hours and returns...

    In python 3, 1. Write a program that takes a number of credit hours and returns a classification as follows: 29 credits or less: freshman; 30-59 credits: sophomore; 60-89 credits: junior; 90+ credits: senior. 2. Use a loop to valid input such that users can only enter positive numbers. 3. Use a loop to allow the user to keep entering credit hours and receiving classifications until they quit. All code must be in a function. I suggest the following structure:...

  • please type code in Python find all the VALID email address in this input text file...

    please type code in Python find all the VALID email address in this input text file and store them as a single column of valid email addresses in an output text file labeled OutputFile First cut/paste the block of text below into a separate text file and label that data file InputFile: FinancialAid Email: [email protected] Scholarships Financial Aid Phone: 979-555-3236 Email: [email protected] Financial [email protected] Aid [email protected] Help Desk Central [email protected] Dean's Office      Jill Educational Program Coordinator II    Create...

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