Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.67 KB | None | 0 0
  1. package string_methods;
  2. // Starting Template
  3. import java.util.Scanner;
  4. public class MyStringMethods {
  5.  private String myStr="";
  6.  
  7.  public void readString()
  8.  {
  9.  // Prompt the user and read in a String from a Scanner class from the
  10. keyboard
  11.  // with the nextLine() method and store it in "myStr"
  12.  }
  13.  public void setString(String s)
  14.  {
  15.  myStr =s;
  16.  }
  17.  public int countOccurrences(String s)
  18.  {
  19.  // use indexOf and return the number of occurrences of the string "s"
  20. in "myStr"
  21.  }
  22.  public int countOccurrences(char c)
  23.  {
  24.  // use indexOf and return the number of occurrences of the character
  25. "c" in "myStr"
  26.  }
  27.  int countUpperCaseLetters()
  28.  {
  29.  // return the number of upper case letters in "myStr"
  30.  }
  31.  int countLowerCaseLetters()
  32.  {
  33.  // return the number of lower case letters in "myStr"
  34.  }
  35.  public void printCounts(String s, char c)
  36.  {
  37.  System.out.println("***************************************");
  38.  System.out.println("Analyzing: myStr="+myStr);
  39.  System.out.println("Number of Upper case letters="+
  40. countUpperCaseLetters());
  41.  System.out.println("Number of Lower case letters="+
  42. countLowerCaseLetters());
  43.  System.out.println("Number of "+s + " is "+ countOccurrences(s));
  44.  System.out.println("Number of "+c + " is "+ countOccurrences(c));
  45.  }
  46.  public static void main(String[] args) {
  47.  MyStringMethods msm = new MyStringMethods();
  48.  msm.readString();
  49.  msm.printCounts("big", 'a');
  50.  
  51.  msm.setString("Parked in a van down by the river bank .... The van
  52. evan vanished near a lot of other vans");
  53.  msm.printCounts("van", 'a');
  54.  
  55.  MyStringMethods msm2 = new MyStringMethods();
  56.  msm2.setString("the elephant in the room wouldn't budge");
  57.  msm2.printCounts("the", 'i');
  58.  }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement