Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class StringsAndThings here.
- * @author Taarush
- */
- public class StringsAndThings{
- private String word;
- /**
- * Constructor for objects of class StringsAndThings
- * @param str is the String input
- */
- public StringsAndThings(String str){
- word = str;
- }
- /**
- * Counts how many of the characters in the string are not letters
- * @return the number of characters in the string are not letters
- */
- public int countNonLetters(){
- int counter = 0;
- for (int i = 0; i < word.length(); i++){
- if (Character.isLetter(word.charAt(i))){
- counter = counter + 1;
- }
- }
- int nonLetters =word.length() - counter;
- return nonLetters;
- }
- /**
- Tests whether a letter is a vowel
- @param letter a string of length 1
- @return true if letter is a vowel
- */
- public boolean isVowel(String let){
- String stringToCheck = "aeiouyAEIOUY";
- return (stringToCheck.contains(let));
- }
- /**
- * Finds whether a word has more vowels or consonants
- * @return returns if the string has more vowels
- */
- public boolean moreVowels(){
- int k = 0;
- int vowels = 0,consonants = 0;
- boolean test = true;
- String testLetter = word.substring(k, k + 1);
- while(k < word.length()){
- if(isVowel(testLetter)){
- vowels = vowels +1;
- }
- else
- {
- consonants = consonants + 1;
- }
- k = k+1;
- {
- if(consonants > vowels){
- test = false;
- }
- }
- }
- return test;
- }
- /**
- * Returns a string where each character in the phrase occurs once
- * @return the string mentioned
- */
- public String noDuplicates(){
- String str = "";
- for (int i = 0; i < word.length(); i++){
- if (str.contains(word.substring(i,i+1)) == false)
- {
- str = str + word.charAt(i);
- }
- }
- return str;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement