Question: Need help with this. A core generic top-level domain (core gTLD) name is one of the following Internet domains: .com, .net, .org, and .info (ICANN:

Need help with this.

A core generic top-level domain (core gTLD) name is one of the following Internet domains: .com, .net, .org, and .info (ICANN: gTLDs). The following program asks the user to input a name and prints whether that name is a gTLD. The program uses the String method compareTo(), which returns a zero if the two compared strings are identical. Run the program, noting that the .info input name is not currently recognized as a gTLD. Extend the if-else statement to detect the .info domain name as a gTLD. Run the program again. Extend the program to allow the user to enter the name with or without the leading dot, so .com or just com.

import java.util.Scanner;

public class SearchForDomainName {

public static void main(String [ ] args) { Scanner scnr = new Scanner(System.in); String inputName; String searchName; String coreGtld1; String coreGtld2; String coreGtld3; // FIXME: Add a fourth core gTLD: .info boolean isCoreGtld;

coreGtld1 = ".com"; coreGtld2 = ".net"; coreGtld3 = ".org"; isCoreGtld = false;

System.out.println(" Enter a top-level domain name: "); inputName = scnr.nextLine(); // Case is irrelevant, so make all comparisons with lower case searchName = inputName.toLowerCase();

// FIXME: Allow the user to enter a name with or without a leading period

// Determine whether the user-entered name is a gTLD if (searchName.compareTo(coreGtld1) == 0) { isCoreGtld = true; } else if (searchName.compareTo(coreGtld2) == 0) { isCoreGtld = true; } else if (searchName.compareTo(coreGtld3) == 0) { isCoreGtld = true; } // FIXME: Add a check for the fourth domain name else { isCoreGtld = false; }

System.out.print("The name \"" + inputName + "\" "); if (isCoreGtld) { System.out.println("is a core gTLD."); } else { System.out.println("is not a core gTLD."); }

return; } }

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!