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

Write a method named site. This method accepts the Scanner object as its paramet

ID: 3800727 • Letter: W

Question

Write a method named site. This method accepts the Scanner object as its parameter. This method reads a commercial website URL that starts with www and ends with .edu or .com. This method retrieves the name of the site and outputs the site without the www prefix and the domain suffix. If the user enters www.yahoo.com then this method outputs yahoo.

Sample output: You must generate this output exactly How many different website do you have > 3 Enter the URL of the website > www.sierracollege.edu The name of the website you entered is > sierracollege Enter the url of the website > www.csus.edu The name of the website you entered is > csus Enter the url of the website > www.yahoo.com The name of the website you entered is > yahoo

Explanation / Answer


import java.io.*;
import java.util.*;
import java.util.Scanner;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class HelloWorld {
  
public void site(Scanner in){
System.out.println("How many Websites do you want to enter?");
int n = in.nextInt();
for(int i=0;i<n;i++){
System.out.println("Enter the URL of the Website");
String s = in.next();
String pattern="(([wW]{3}.)[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*(.[cC][oO][mM]|.[eE][dD][uU]))";
if(s.matches(pattern)){
  
String[] a = s.split("[wW]{3}.");

String[] b = a[1].split(".[cC][oO][mM]|.[eE][dD][uU]");
System.out.println(" The name of the website you entered is '"+b[0]+"'");
  
}
else{
System.out.println("Please enter a valid URL type");
}
}
in.close();
}
  
// public static void main(String[] args) {
// HelloWorld h = new HelloWorld();
// Scanner sc = new Scanner(System.in);
// h.site(sc);
// }
  
}

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