Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Task 2 (25 pts.) Create project: HW2_Wiki Submit java file: HW2_Wiki.java WIkipe

ID: 3747587 • Letter: T

Question

Task 2 (25 pts.) Create project: HW2_Wiki Submit java file: HW2_Wiki.java WIkipedia pages have a specific webpage address. Any address starts with https://en.wikipedia.org/wiki/ and then continues with the topic for that page e.g Computer science, Java_(programming language). See examples below https://en.wikipedia.org/wiki/computer science https://en.wikipedia.org/wiki/Java (programming_language) https://en.wikipedia.org/wiki/Imagine Dragons Write a program that reads a string from the user. If it is a valid wikipedia webpage, it extracts and prints the topic for that page. If it is not a valid address it prints the message Not a valid wikipedia webpage address. Hint: How can the fact that all valid addresses start with the same text before the topic name help you extract the topic name? You do NOT need to handle the case where the webpage address is correct, but it is written in uppercase letters. You can assume it is all lowercase the text is all in lowercase and . if the address is valid, then it will have at least one more character for the topic. That is, you do not need to handle an input like: https://en. wikipedia.org/wiki/. -- Sample run 1 This program will extract the topic from a valid Wikipedia webpage addre: Enter a web address: https://en.wikipedia.org/wiki/Computer science Topic: Computer science Sample run 2 This program will extract the topic from a valid Wikipedia webpage addre: Enter a web address: http://vlml.uta.edu/-alex/courses/1310/homework/hw0 Not a valid wikipedia webpage address. Bye -sample run 3 This program will extract the topic from a valid Wikipedia webpage addre: Enter a web address: https://en.wikipedia.org/wiki/ Topic: Bye.

Explanation / Answer

import java.util.*;

import java.io.*;

class WikiLinkChecker

{

public static void main (String[] args) throws IOException

{

// Scanner Object called for taking input from user

Scanner sc=new Scanner(System.in);

//Varibale Declaration

String str="", topic="";

int frontslashpos=0;

System.out.println("This program will extract the topic from a valid Wikipedia Webpage Address");

System.out.print("Enter a web address: ");

//Variable to store string given as input by user

str=sc.next();

//Variable to store position of frontslash before topic

frontslashpos = ordinalIndexOf(str, "/", 4);

topic = str.substring(frontslashpos+1);

if((str.substring(ordinalIndexOf(str,".",1)+1,ordinalIndexOf(str,"/",3)).equals("wikipedia.org")) && (str.substring(ordinalIndexOf(str,"/",3)+1,ordinalIndexOf(str,"/",4)).equals("wiki"))){

System.out.println("Topic: " +topic);

}

else

System.out.println("Not a valid Wikipedia Webpage Address.");

System.out.println("Bye.");

}

// Custom Function. Returns the Index of any character or string. Data to be passed includes input string by the user, string whoose location is to be found out and the nth position of the string to be found

public static int ordinalIndexOf(String str, String substr, int n) {

int pos = str.indexOf(substr);

while (--n > 0 && pos != -1)

pos = str.indexOf(substr, pos + 1);

return pos;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote