java - String modifications assistance -


i've spend day working on these 2 classes. i've come further expecting yet needless i'm running issues.

basically have take inputted string , return uppercase letters, every second letter, entire string vowels exchanged underscore, number of vowels in string, , lastly positions of vowels in string.

i designed tester class, believe correctly, have menu try each command separately i'm able test each one.

this tester class..

//****************************************** // lettertest.java  // written sanchez // 2013 //*******************************************  //=========================================== // program tests charapi class. //===========================================  import java.util.scanner;  public class lettertest {  public static void main(string[] args){     //create scanner user input     scanner in = new scanner(system.in);      //get user input         system.out.println("please enter string of letters");         string input = in.nextline();     system.out.println("\nchoose option: "         +"\n1 - uppercase, "         +"\n2 - every second letter, "         +"\n3 - replace vowels "         +"\n4 - number of vowels "         +"\n5 - positions of vowels");     int choice = in.nextint();      //call method based on user choice  if (choice == 1)  {         //each method returns string     system.out.println(letterapi.bigletters(input) ); } else if (choice ==2)  {     system.out.println(letterapi.secondletter(input) ); } else if (choice ==3)  {      system.out.println(letterapi.vowelsgone(input) ); } else if (choice ==4)  {      system.out.println(letterapi.vowelnumber(input) ); } else {     system.out.println(letterapi.vowelpositions(input) ); } } } 

that seems working pretty , i'm happy it.

the issue i'm having in class objects manipulation i've used // on couple things compile. 1st, 2nd, , 4th, straight don't return anything. third 1 exchanges last letter underscore if it's not vowel, , fifth 1 works pretty except i'd add 1 numbers results start @ 1 , not 0. understand there's lot going on here i've spent day on , submitting in dire need of help.

this code objects...

//****************************************** // letterapi.java  // written sanchez // 2013 //*******************************************  //=========================================== // objects of class manipulate inputted string. //===========================================  import java.util.scanner;  //contains set of methods maniuplaing string public class letterapi {  //print uppercase letters public static string bigletters(string input) {     string result = "";     (int = 0; <input.length(); i++) {     char currentletter=input.charat(i);     if (character.isuppercase(currentletter))     result = result;     }     return result;   } //print every second letter public static string secondletter(string input) {     string result = "";     (int = 0; <input.length(); i++) {     //result = input.charat(input);     }     return result;   } //all vowels replaced underscores public static string vowelsgone(string input) {     string result ="aeiouaeiou";     (int = 0; i<result.length();i++) {     result=input.replace(result.charat(i), '_');     }     return result;   } //the numbers of vowels public static string vowelnumber(string input) {     string result = "";     (int = 0; <input.length(); i++) {          if (character.tolowercase(input.charat(i)) == 'a' || character.tolowercase(input.charat(i)) == 'e' || character.tolowercase(input.charat(i)) == 'i' || character.tolowercase(input.charat(i)) == 'o' || character.tolowercase(input.charat(i)) == 'u') {             i++;         }      }     return result;  } //the positions of vowels public static string vowelpositions(string input) {     string result = "";     (int = 0; <input.length(); i++) {          if (character.tolowercase(input.charat(i)) == 'a' || character.tolowercase(input.charat(i)) == 'e' || character.tolowercase(input.charat(i)) == 'i' || character.tolowercase(input.charat(i)) == 'o' || character.tolowercase(input.charat(i)) == 'u') {             result = result + + " ";         }     }     return result;  } } 

===update===

thank everyone! i've made progress thank god. i've gotten 3rd , 4th work great. first 1 giving last uppercase repeating input. second 1 giving me 1st letter. last 1 tried parenthesis seemed have broke put now. that's not critical..at least works! if can't figure out i'll have put note count starts @ 0. first 2 killing me..at least compiles. here's i'm @ far...

//****************************************** // letterapi.java  // written sanchez // 2013 //*******************************************  //=========================================== // objects of class manipulate inputted string. //===========================================  import java.util.scanner;  //contains set of methods maniuplaing string public class letterapi {  //print uppercase letters public static string bigletters(string input) {     string result = "";     char cl;     (int = 0; <input.length(); i++) {     cl=input.charat(i);     if (character.isuppercase(cl))     input = input + cl;     }     return input;   } //print every second letter public static string secondletter(string input) {     string result = "";     (int i=0; i<input.length(); i+=2) {     input = input + input.charat(i) + " ";     }     return input;   }  //all vowels replaced underscores public static string vowelsgone(string input) {     string vowels ="aeiouaeiou";     (int = 0; i<vowels.length();i++) {     input=input.replace(vowels.charat(i), '_');     }     return input;   } //the numbers of vowels public static string vowelnumber(string input) {     string result = "";     int count = 0;     (int = 0; <input.length(); i++) {          if (character.tolowercase(input.charat(i)) == 'a' || character.tolowercase(input.charat(i)) == 'e' || character.tolowercase(    input.charat(i)) == 'i' || character.tolowercase(input.charat(i)) == 'o' || character.tolowercase(input.charat(i)) == 'u') {             count++;             result = count + " ";         }      }     return result;  } //the positions of vowels public static string vowelpositions(string input) {     string result = "";     (int = 0; <input.length(); i++) {          if (character.tolowercase(input.charat(i)) == 'a' || character.tolowercase(input.charat(i)) == 'e' || character.tolowercase(input.charat(i)) == 'i' || character.tolowercase(input.charat(i)) == 'o' || character.tolowercase(input.charat(i)) == 'u') {             result = result + + " ";         }     }     return result;  } } 

hints:

  1. in part 1, this: result = result; nonsensical. nothing.

  2. in part 2, compilation error because trying assign char string. that's not legal. not should trying do. (think "append", not "assign" ...)

  3. in part 3, first mistake this: string result = "aeiouaeiou";. in fact, should string result = input;.

  4. in part 4, counting vowels, not each different vowel. need turn count (or counts) string (in result).

  5. about part 5 say: "works pretty except i'd add 1 numbers". it!


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -