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

Objective: Write a program that creates a helper class called StringHelper . Thi

ID: 3811695 • Letter: O

Question

Objective:

Write a program that creates a helper class called StringHelper. This class has methods not already built into strings, but should be because they are super useful.

First create a class called StringHelper which has the following static methods

meshStrings: This method takes in two strings via parameters, meshes them together, and returns the meshed strings. Meshing alternates the each character in the first string with every character in the next string. If there are not enough characters to fully mesh then the rest will be appended to the end. For instance if the two strings were “harp” and “fiddle” the returned string will be “hfairdpdle”.
replaceVowelsWithOodle: This method takes in one string via parameter, and returns the string with every vowel (a,e,i,o,u) replaced by the phrase “oodle”. For instance if the string is “burrito” then the returned string would be “boodlerroodletoodle”. Also case does not matter.
weight: Much like length returns the number of characters in a string, the weight gives the weight in kilograms. This method takes in a string and returns a double value corresponding to its weight. Everyone knows that a word’s weight is determined by each vowel (a,e,i,o,u) counting as 2.5 kilograms and each consonant as 3.4 kilograms.

Finally create a class called StringHelperTester

This class DOES HAVE a main method
Test each method multiple times to determine if they work.

Example Dialog:

Welcome to the String Helper Tester

Meshing harp with fiddle

hfairdpdle

Replacing vowels with oodle in the word burrito

Boodlerroodletoodle

The weight of the word taco is

11.8

Explanation / Answer

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package stringhelper;

/**
*
* @author admin
*/
public class StringHelper {

/**
* @param args the command line arguments
*/
public static String meshStrings(String a, String b)
{
int l1, l2;
l1 = a.length();
l2 = b.length();
String ret = "";
int m = l1;
if(l1 > l2)
m = l2;
int i;
for(i = 0; i < m; ++i) {
ret = ret +""+a.charAt(i);
ret = ret +""+b.charAt(i);
}
for(i = m; i < l1; ++i)
ret = ret+""+a.charAt(i);
for(i = m; i < l2; ++i)
ret = ret+""+b.charAt(i);
  
return ret;
}
  
public static String replaceVowelsWithOodle(String a)
{
String ret = "";
int l1 = a.length();
int i;
for(i = 0; i < l1; ++i) {
if(a.charAt(i) == 'a' || a.charAt(i) == 'e' || a.charAt(i) == 'i' ||a.charAt(i) == 'o' ||a.charAt(i) == 'u' ||a.charAt(i) == 'A' ||a.charAt(i) == 'E' ||a.charAt(i) == 'I' ||a.charAt(i) == 'O' ||a.charAt(i) == 'U' )
ret = ret + "oodle";
else
ret = ret + "" +a.charAt(i);
  
}
return ret;
}
  
public static double weight(String a)
{
double ret = 0.0;
int l1 = a.length();
int i;
for(i = 0; i < l1; ++i) {
if(a.charAt(i) == 'a' || a.charAt(i) == 'e' || a.charAt(i) == 'i' ||a.charAt(i) == 'o' ||a.charAt(i) == 'u' ||a.charAt(i) == 'A' ||a.charAt(i) == 'E' ||a.charAt(i) == 'I' ||a.charAt(i) == 'O' ||a.charAt(i) == 'U' )
ret = ret + 2.5;
else
ret = ret + 3.4;
}
return ret;
}
  
}