JAVA
Arrays are useful to process lists.
A top-level domain (TLD) name is the last part of an Internet domain name like .com in example.com. A core generic top-level domain (core gTLD) is a TLD that is either .com, .net, .org, or .info. A restricted top-level domain is a TLD that is either .biz, .name, or .pro. A second-level domain is a single name that precedes a TLD as in apple in apple.com.
The following program repeatedly prompts for a domain name, and indicates whether that domain name consists of a second-level domain followed by a core gTLD. Valid core gTLD's are stored in an array. For this program, a valid domain name must contain only one period, such as apple.com, but not support.apple.com. The program ends when the user presses just the Enter key in response to a prompt.
1-Run the program and enter domain names to validate.
2-Extend the program to also recognize restricted TLDs using an array, and statements to validate against that array. The program should also report whether the TLD is a core gTLD or a restricted gTLD. Run the program again.
import java.util.Scanner;
public class GtldValidation {
public static void main (String [ ] args) {
Scanner scnr = new Scanner(System.in);
// Define the list of valid core gTLDs
String [ ] validCoreGtld = { ".com", ".net", ".org", ".info" };
// FIXME: Define an array named validRestrictedGtld that has the names
// of the restricted domains, .biz, .name, and .pro
String inputName = "";
String searchName = "";
String theGtld = "";
boolean isValidDomainName = false;
boolean isCoreGtld = false;
boolean isRestrictedGtld = false;
int periodCounter = 0;
int periodPosition = 0;
int i = 0;
System.out.println("\nEnter the next domain name (<Enter> to exit): ");
inputName = scnr.nextLine();
while (inputName.length() > 0) {
searchName = inputName.toLowerCase();
isValidDomainName = false;
isCoreGtld = false;
isRestrictedGtld = false;
// Count the number of periods in the domain name
periodCounter = 0;
for (i = 0; i < searchName.length(); ++i) {
if (searchName.charAt(i) == '.') {
++periodCounter;
periodPosition = i;
}
}
// If there is exactly one period that is not at the start
// or end of searchName, check if the TLD is a core gTLD or a restricted gTLD
if ((periodCounter == 1) &&
(searchName.charAt(0) != '.') &&
(searchName.charAt(searchName.length() - 1) != '.')) {
isValidDomainName = true;
}
if (isValidDomainName) {
// Extract the Top-level Domain name starting at the period's position. Ex:
// If searchName = "example.com", the next statement extracts ".com"
theGtld = searchName.substring(periodPosition);
i = 0;
while ((i < validCoreGtld.length) && (!isCoreGtld)) {
if(theGtld.equals(validCoreGtld[i])) {
isCoreGtld = true;
}
else {
++i;
}
}
// FIXME: Check to see if the gTLD is not a core gTLD. If it is not,
// check to see whether the gTLD is a valid restricted gTLD.
// If it is, set isRestrictedGtld to true
}
System.out.print("\"" + inputName + "\" ");
if (isValidDomainName) {
System.out.print("is a valid domain name and ");
if (isCoreGtld) {
System.out.println("has a core gTLD of \"" + theGtld + "\".");
}
else if (isRestrictedGtld) {
System.out.println("has a restricted gTLD of \"" + theGtld + "\".");
}
else {
System.out.println("does not have a core gTLD."); // FIXME update message
}
}
else {
System.out.println("is not a valid domain name.");
}
System.out.println("\nEnter the next domain name (<Enter> to exit): ");
inputName = scnr.nextLine();
}
return;
}
}
Step by stepSolved in 4 steps with 5 images
- Java programming 1. Write the code that will read the inventory information from a file, populate the object, and populate a linked list with all the inventory objects. Then find a particular item in the linked list based on user input and display the information for that item. Inventory inventory = new Inventory (); Write the line of code to find an inventory object in the linked list using the property for InventoryIDarrow_forwardWrite a C#program that uses a class called ClassRegistration as outlined below: The ClassRegistration class is responsible for keeping track of the student id numbers for students that register for a particular class. Each class has a maximum number of students that it can accommodate. Responsibilities of the ClassRegistration class: It is responsible for storing the student id numbers for a particular class (in an array of integers) It is responsible for adding new student id numbers to this list (returns boolean) It is responsible for checking if a student id is in the list (returns a boolean) It is responsible for getting a list of all students in the class (returns a string). It is responsible for returning the number of students registered for the class (returns an integer) It is responsible for returning the maximum number of students the class is allowed (returns an integer) It is responsible for returning the name of the class. (returns a string) ClassRegistration -…arrow_forwardWritten in Python It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Docstrings for modules, functions, classes, and methodsarrow_forward
- member functions are dynamically bound to an address that is accessible using the object at runtime. This is unlike regular functions that are statically bound to an address at time. Write your answer here.arrow_forwardUsing C++ Without Using linked lists: Create a class AccessPoint with the following: x - a double representing the x coordinate y - a double representing the y coordinate range - an integer representing the coverage radius status - On or Off Add constructors. The default constructor should create an access point object at position (0.0, 0.0), coverage radius 0, and Off. Add accessor and mutator functions: getX, getY, getRange, getStatus, setX, setY, setRange and setStatus. Add a set function that sets the location coordinates and the range. Add the following member functions: move and coverageArea. Add a function overLap that checks if two access points overlap their coverage and returns true if they do. Add a function signalStrength that returns the wireless signal strength as a percentage. The signal strength decreases as one moves away from the access point location. Represent this with bars like, IIIII. Each bar can represent 20% Test your class by writing a main function that…arrow_forwardFor this assignment, you are to use the started code provided with QUEUE Container Adapter methods and provide the implementation of a requested functionality outlined below. Scenario: A local restaurant has hired you to develop an application that will manage customer orders. Each order will be put in the queue and will be called on a first come first served bases. Develop the menu driven application with the following menu items: Add order Next order Previous order Delete order Order Size View order list View current order Order management will be resolved by utilization of an STL-queue container’s functionalities and use of the following Queue container adapter functions: enQueue: Adds the order in the queue DeQueue: Deletes the order from the queue Peek: Returns the order that is top in the queue without removing it IsEmpty: checks do we have any orders in the queue Size: returns the number of orders that are in the queue While adding a new order in the queue, the program…arrow_forward
- Write a function that converts encoded HTML into actual HTML. The function will take a string of text, and then a hashmap, mapping html tags to a list of tuples, where each tuple represents the first and last index of the string that the tags need to encompassarrow_forwardProgram #11. Show the ArrayStackADT interface 2. Create the ArrayStackDataStrucClass<T> with the following methods: default constructor, overloaded constructor, copy constructor, initializeStack, isEmptyStack, isFullStack, push, peek, void pop 3. Create the PrimeFactorizationDemoClass: instantiate an ArrayStackDataStrucClass<Integer> object with 50 elements. Use a try-catch block in the main( ) using pushes/pops. 4. Exception classes: StackException, StackUnderflowException, StackOverflowException 5. Show the 4 outputs for the following: 3,960 1,234 222,222 13,780arrow_forwardIn C++ Create a new project named lab9_1 . You will need to implement a Course class. Here is its UML diagram: Course - department : string- course_num : string- section : int- num_students : int- is_full : bool + Course()+ Course(string, string, int, int)+ setDepartment(string) : void+ setNumber(string) : void+ setSection(int) : void+ setStudents(int) : void+ getDepartment() const : string+ getNumber() const : string+ getSection() const : int+ getStudents() const : int+ print() const : void Create a sample file to read from: CSS 2A 1111 35 Additional information: The Course class has two constructors. Make sure you have default values for your default constructor. Each course maxes out at 40 students. Therefore, you need to make sure that there aren’t more than 40 students in a Course. You can choose how you handle situations where more than 40 students are added. Additionally, you should automatically set is_full to false or true, based on the number of…arrow_forward
- 1. Build a web crawler function that starts with a URL representing a topic (a sport, your favorite film, a celebrity, a political issue, etc.) and outputs a list of at least 15 relevant URLs. The URLs can be pages within the original domain but should have a few outside the original domain.arrow_forwardGiven the following program segment. Assume the node is in the usual info-link form with the info of the type int. (list and ptr are reference variable of the LinkedListNode type. What is the output of this program? list = new LinkedListNode (); list.info = 20; ptr = new LinkedListNode (); ptr.info = 28; ptr.link= null; list.link ptr; ptr = list; list = new LinkedListNode (); list.info = 55; list.link = ptr; ptr = new LinkedListNode (); ptr.info = 30; ptr.link= list; list = ptr; ptr = new LinkedListNode (); ptr.info = 42; ptr.link= list.link; list.link= ptr; ptr = list; while (ptr!= null) { } System.out.println (ptr.info); ptr = ptr.link;arrow_forwardin c++ codearrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education