Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

StringMethods.java is the only file that needs to be completed for part 1 of this homework. This is a full Class where you only need

  • StringMethods.java is the only file that needs to be completed for part 1 of this homework. This is a full Class where you only need to fill out the methods. This class contains the following six methods, and in order to get the full grade, your code should pass all the assertions successfully.
  • Public String findChar (String text, int ind)
  • This method takes the String and index of the target character as the arguments. You should use the appropriate string method to return the character at the location ind of text. Note that in Java we use indices that start from "0" (zero-indexed). Whenever we say "the first position" we are referring to index "0". The second position is index "1", and so on. If the requested character does not exist (index out of bounds), please return "none"; For example: The second character (at index 1) of the word "CS1111" is "S".

  • public boolean userChecker (String newUser, String oldUser)

    This method takes two strings as the arguments, the first one is the newUser and the second one is the existing username. You need to check and verify the requirements of the usernames. Some of the requirements are listed below. *The username should contain at least a number between 1 to 4 *The username should not start with a number *The username should not have any of the following punctuations (!,@,?) *The username should not be same as the oldUsername *The oldUser cannot be null or the empty string ("")

    If any of the requirements are not satisfied the method needs to return false.

  • public boolean urlChecker (String url)

    This method takes the url argument and verifies the scheme of the url. For this homework we only expect you to check .com,.edu,.net. domains

  • public String lengString (String text)

    This method takes a string argument and returns the length of that as a string.

  • public String emailGen (String fullname)

    This method takes a fullname exp. Magic Johnson and generates the domain in the following format "info@first character of the first name+Lastname.com

  • public String domainGen (String fullname)

    This method takes the fullname and generated the domain in following scheme www.firstname-lastname.com *Make sure to lowercase the domain

This is the code of assertions you need to follow

class StringMethods {

public String findChar (String text,int ind) {

//Write your Code here (replace the default return statement) return " "; } public boolean userChecker (String newUser, String oldUser) { //Write your Code here (replace the default return statement) return false; } public boolean urlChecker (String url) { //Write your Code here (replace the default return statement)

return false; } public String lengString (String text) { //Write your Code here (replace the default return statement) return "100"; } public String emailGen (String text) { //Write your Code here (replace the default return statement)

return ""; } public String domainGen (String text) { //Write your Code here (replace the default return statement) return ""; } public static void main(String[] args) { StringMethods M1=new StringMethods(); String s="CS1111 is the best class that I have ever taken."; assert "none".equals(M1.findChar(s,100)) : "100 is larger than the length of the string"; assert "t".equals(M1.findChar(s,10)) : "The character in the 10th place should be S"; assert "1".equals(M1.findChar(s,2)) : "The character in the 3d place should be 1";

//User Check

String username="user one 23"; assert !M1.userChecker(username,""): "User has space and not accepted"; username="userone1234?!"; assert !M1.userChecker(username,""): "user is accepted"; username=""; assert !M1.userChecker(username,""): "Empty username is not accepted"; username="User1"; assert !M1.userChecker(username,"User1"): "username is already taken";

//URL Check String url="http:\\www.gwu. edu"; assert !M1.urlChecker(url): "url contains a space"; url="http:\\www.gwu.edu"; assert M1.urlChecker(url): "url not verfied"; url="www.gwu.edu"; assert M1.urlChecker(url): "url not verfied"; url="ww.gwuedu"; assert !M1.urlChecker(url): "url verfied by mistake"; url="http:\\ww.gwuedu"; assert !M1.urlChecker(url): "url verfied by mistake"; //casting

assert "3".equals(M1.lengString("ABC")): "ABC length is 3"; assert "6".equals(M1.lengString("ABCDEF")): "ABCDEF length is 6"; assert "7".equals(M1.lengString("ABCDEF1")): "ABCDEF1 length is 7";

//String gen String name ="Magic Johnson"; assert "info@MJohnson.com".equals(M1.emailGen(name)): "name is not converted to the email address properly"; assert "www.magic-johnson.com".equals(M1.domainGen(name)):"name is not converted to the domain address properly"; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mastering Apache Cassandra 3 X An Expert Guide To Improving Database Scalability And Availability Without Compromising Performance

Authors: Aaron Ploetz ,Tejaswi Malepati ,Nishant Neeraj

3rd Edition

1789131499, 978-1789131499

More Books

Students also viewed these Databases questions