Question: JAVA. For the purposes of this assignment, we will use three criteria to determine if an email address is valid: The address must end with

JAVA.

For the purposes of this assignment, we will use three criteria to determine if an email address is valid:

The address must end with one of the following extensions: .com, .org or .edu

The address must not contain a space

The address must have an @ character contained somewhere in the String

You will write 3 methods and 3 Javadoc comments. Each method will check each of the above conditions.

This is my code so far, but it is not working properly and i am not sure what's wrong: (not allowed to use any fancy ways, only very basic intro java, like i have used so far)

import java.util.Scanner;

public class Email {

public static void main(String[] args) {

String address;

Scanner input = new Scanner(System.in);

System.out.print("Enter your email address: ");

address = input.nextLine();

if (!containsAt(address)) {

System.out.println("Invalid email. Your email address must contain an @ symbol");

} else if (!validExtension(address)) {

System.out.println("Invalid email. Your email address cannot contain a space");

} else if (!containsSpace(address)) {

System.out.println("Invalid email. Your email must contain a .com, .edu or .org extension");

} else {

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

}

}

//Write JAVADOC comment here for validExtension

public static boolean validExtension(String address) {

if (!((address.substring(address.length()-4, address.length()).equalsIgnoreCase(".com") ||

address.substring(address.length()-4, address.length()).equalsIgnoreCase(".org") ||

address.substring(address.length()-4, address.length()).equalsIgnoreCase(".edu"))));

return false;

}

//Write JAVADOC comment here for containsSpace

public static boolean containsSpace(String address) {

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

if (address.charAt(i) == ' ')

return true;

}

return false;

}

//Write JAVADOC comment here for containsAt

public static boolean containsAt(String address) {

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

if (address.charAt(i) == '@')

return true;

}

return false;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!