Question

In: Computer Science

Project Name: URLEncoder Target Platform: Console Programming Language: C# A Uniform Resource Identifier (URI) (Links to...

Project Name: URLEncoder Target Platform: Console Programming Language: C# A Uniform Resource Identifier (URI) (Links to an external site.) is a string of characters designed for unambiguous identification of resources and extensibility via the URI scheme. The most common form of URI is the Uniform Resource Locator (URL) (Links to an external site.), frequently referred to informally as a web address. A user has a need to generate URLs for files they are storing on a server. The purpose of this program is to generate the URL string so the user doesn’t have to type it out. The program asks the user for several pieces of information and then uses it to generate the URL string and presents it in the Console where the user can copy it. This is being done so the user doesn’t have to type out the URL and helps avoid mistakes from typing and from the use of invalid characters in a URL. The following is the format for a URL that is to be generated by the program. https://companyserver.com/content/[project_name]/files/[activity_name]/[activity_name]Report.pdf (Links to an external site.) The [project_name] and [activity_name] are placeholders for pieces of information that go in the string. The [ ] do not get included in the string. They surround an identifier for the piece of information and are not part of the content. So, if [project_name] is “DesignLab” and [activity_name] is “Furnishings” then the URL is to be https://companyserver.com/content/DesignLab/files/Furnishings/FurnishingsReport.pdf (Links to an external site.) There are a couple of rules that have to be adhered to when creating URLs. No spaces are allowed in URLs. So, if [project_name] is “Design Lab” it can’t be included as-is in the URL. Spaces in URLs must be replaced with “%20”. The URL can contain “Design%20Lab”. If a space is present in the user input it must be converted to “%20”. Note: spaces can also be replaced with a +, but for this assignment spaces are to be converted to “%20”. In addition to spaces, there are other characters that may not be placed in URLs. The HTML URL Encoding Reference (Links to an external site.) from w3schools shows how characters that aren’t allowed in a URL can be converted to a %[number] value that can be in the URL. control characters: these are ASCII coded characters 00–1F and 7F hexadecimal delimiter characters: < > # % and " If a control character appears in the content provided by the user, the user is to be given feedback that the input is invalid because it contains a control character and they are to be asked to provide a different input. If a delimiter appears in the content provided by the user, the delimiter character is to be converted into its %[number] URL encoded format. For example, < is to be encoded as “%3C” and > is to be encoded as “%3E”. The values for the other characters can be found in the documentation provided above. There are some other characters that are reserved for use in some parts of the URL. They may not be allowed in one part of the URL even if they are allowed in other parts. These characters are also to be converted to their URL encoded format using %[number]. The following characters are reserved within a query component, have special meaning within a URL, and are to be converted. ; / ? : @ & = + $ , The following list of characters are not disallowed, but they may cause problems. They should also be converted to their URL encoded format. { } | \ ^ [ ] ` The following is an example to illustrate the application of the rules. Project Name: Design Lab Activity Name: Network>Implementation Result URL: https://companyserver.com/content/Design%20Lab/files/Network%3EImplementation/Network%3EImplementationReport.pdf (Links to an external site.) Your application, when run, is to prompt the user for the Project Name and the Activity Name. If the input is invalid, the user should be re-prompted for the input with a feedback message. After the input is successfully received, the URL string is to be created based on the rules above and presented to the user in the Console. After the URL is presented, the user is to be prompted if they want to create another URL. If they do, prompt them again for input. If not, exit the program. Please do in visual studios 2019.

Solutions

Expert Solution

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace URLValidityChecker
{
class Program
{
//set of all the characters which are valid
const string _validChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~#[]@!'()*,;";
//set of all the characters which are invalid
const string _invalidChars = "/?:@&=+$<>#%{ }|\\^[]` ";
//final URL building template string
const string _urlPlaceholder = "https://companyserver.com/content/{0}/files/{1}/{2}Report.pdf";
static void Main(string[] args)
{
Console.WriteLine("-----------URL VALIDITY CHECKER------------");
Console.WriteLine("Please press X when programs ask for continuation to exit");
//will run untill correct exit criteria is met which in or case is empty of X
while (true)
{
Console.WriteLine("PLEASE ENTER THE PROJECT NAME");
//Take project name input from user
string prjctName = Console.ReadLine();
if (string.IsNullOrEmpty(prjctName))
{
InvalidMsgToUser();
continue;
}
//format the name as per the business logc and url's character acceptance
prjctName = StrFormatter(prjctName);

Console.WriteLine("PLEASE ENTER THE ACTIVITY NAME");
//Take project name input from user
string actName = Console.ReadLine();
if (string.IsNullOrEmpty(actName))
{
InvalidMsgToUser();
continue;
}
//format the activity name as per the business logc and url's character acceptance
actName = StrFormatter(actName);

Console.WriteLine("FINAL URL : ");
Console.WriteLine(string.Format(_urlPlaceholder,prjctName,actName,actName));

Console.WriteLine("WOULD YOU LIKE TO CONTINUE FOR ANOTHER URL OR WANT TO QUIT(Press X)");
string usrInpt=Console.ReadLine();
if(string.IsNullOrEmpty(usrInpt) || usrInpt.ToLower().Trim()=="x")
{
Console.WriteLine("PROCESS WILL EXIT NOW");
break;
}
}

Console.ReadLine();
}

static void InvalidMsgToUser()
{
Console.WriteLine("EMPTY OR INVALID ENTRY WAS MADE, PLEASE TRY AGAIN!");
}

/// <summary>
/// Convert the String to character url and check for it's presence in
/// valid or invalid collection of string defined at the top
/// for invalid ones we are simply converting them to the respective ASCII code and then getting
/// their hexadecimal values.
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
static string StrFormatter(string str)
{
char[] strArr = str.ToCharArray();
char[] validChrsArr = _validChars.ToCharArray();
char[] invalidChrArr = _invalidChars.ToCharArray();

string finalStr = string.Empty;
foreach (char item in strArr)
{
if (invalidChrArr.Contains(item))
{
int value = Convert.ToInt32(item);

//Get the hexadecimal string value using correct string conversion overload
finalStr += string.Format("%{0}", value.ToString("X2"));
}
else if (validChrsArr.Contains(item))
finalStr += item;
}

return finalStr;
}

}
}


Related Solutions

C# Programming Language Write a C# program ( Console or GUI ) that prompts the user...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user to enter the three examinations ( test 1, test 2, and test 3), homework, and final project grades then calculate and display the overall grade along with a message, using the selection structure (if/else). The message is based on the following criteria: “Excellent” if the overall grade is 90 or more. “Good” if the overall grade is between 80 and 90 ( not including...
Create a C# console application (do not create a .NET CORE project) and name the project....
Create a C# console application (do not create a .NET CORE project) and name the project. Generate two random integers, each between 1 and 50, that you will be adding together to test the user's ability to perform the addition operator. Display the numbers in the console, such as:             7 + 22 = ? Once the user provides their answer, check to see if it is correct and if not, tell them sorry, please try again. If their answer...
Create a C# console application (do not create a .NET CORE project) and name the project...
Create a C# console application (do not create a .NET CORE project) and name the project TuitionIncrease. The college charges a full-time student $12,000 in tuition per semester. It has been announced that there will be a tuition increase by 5% each year for the next 7 years. Your application should display the projected semester tuition amount for the next 7 years in the console window in the following format:             The tuition after year 1 will be $12,600. Note:...
Create a C# console application (do not create a .NET CORE project) and name the project...
Create a C# console application (do not create a .NET CORE project) and name the project TimeToBurn. Running on a particular treadmill, you burn 3.9 calories per minute. Ask the user how many calories they wish to burn in this workout session (this is their goal). Once they tell you, output on the console after each minute, how many calories they have burned (e.g. After 1 minute, you have burned 3.9 calories). Keep outputting the total amount of calories they...
The Programming Language is C++ Objective: The purpose of this project is to expose you to:...
The Programming Language is C++ Objective: The purpose of this project is to expose you to: One-dimensional parallel arrays, input/output, Manipulating summation, maintenance of array elements. In addition, defining an array type and passing arrays and array elements to functions. Problem Specification: Using the structured chart below, write a program to keep records and print statistical analysis for a class of students. There are three quizzes for each student during the term. Each student is identified by a four-digit student...
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
Complete the following assignment in C programming language. Get the user’s first name and store it...
Complete the following assignment in C programming language. Get the user’s first name and store it to a char array Declare a character array to hold at least 20 characters. Ask for the user’s first name and store the name into your char array. Hint: Use %s for scanf. %s will only scan one word and cannot scan a name with spaces. Get 3 exam scores from the user: Declare an array of 3 integers Assume the scores are out...
Problem: Make linkedList.h and linkList.c in Programming C language Project description This project will require students...
Problem: Make linkedList.h and linkList.c in Programming C language Project description This project will require students to generate a linked list of playing card based on data read from a file and to write out the end result to a file. linkedList.h Create a header file name linkedList Include the following C header files: stdio.h stdlib.h string.h Create the following macros: TRUE 1 FACES 13 SUITS 4 Add the following function prototypes: addCard displayCards readDataFile writeDataFile Add a typedef struct...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing chess himself to practice his abilities. The chess that Jojo played was N × N. When Jojo was practicing, Jojo suddenly saw a position on his chessboard that was so interesting that Jojo tried to put the pieces of Rook, Bishop and Knight in that position. Every time he put a piece, Jojo counts how many other pieces on the chessboard can be captured...
Java programming language Array - Single identifier which can store multiple values Example initialized with values:...
Java programming language Array - Single identifier which can store multiple values Example initialized with values: int[] mySimpleArray = {4, 17, 99}; Example with fixed length but no values: int[] myFixedArray = new int[11]; The brackets identify the index. Each value has its own index number. NOTE: First element is the zeroth element: mySimpleArray[0] is 4, [1] is 17 Make a new Netbeans project called ArraysAndLoops Create the simple array with 4, 17, 99. Use System.out.println with the variable with...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT