Question
Need to fill the comments with code that works.
Create The Starting Template for this program is shown below. Fill in code where you see highlighted in these highlighted sections that do what the comments request. Dont modify maint) or the printCounts0 routine. When you run your program, you will need to eater in a string for the readString method. Use a package named string methods for this program ructions in the methods readString), countOccurrences0.. ete. Write code the string: Aardvarks get big and bigger as You feed them big and bigger ants who Feed on apples. package string methode : import dava.utst.scanrer: public class MystringMethods i tarting Template private sEring myst public void readString) // Prompt the user and read in a String rom a Scenner class from the keyboard // with the nextLine ( method and store it in mystr public vosd setString (String s) public int countoccurrences (String s) // use indexof and return the number of oceutrences of the string in mystr public int countoeeurrences (ehar c // use indexo and return the numbez of occurrences os the character myStr c in int countUppercaseletters () // return the number of upper case letters in aystz int countLowerCaseLetters()
media%2F721%2F721835d9-12e6-4541-ae9a-7c
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi please find the answer

If you have any query please let me know first by comment i will give solutions

===========================================================

MyStringMethods.java

import java.util.Scanner;

public class MyStringMethods {

private String myStr="";

public void readString()

{

// Prompt the user and read in a String form a Scanner class from the keyboard

// with the nextLine() method and store in "myStr"

System.out.println("Enter in the desired String:");

Scanner scan= new Scanner(System.in);

myStr=scan.nextLine();

}

// method to set the string

public void setString(String s)

{

myStr=s;

}

// method to count the number of occurrence of string

public int countOccurrences(String s)

{

// user indexOf and return the number of occurrences of the string "s"

// in "myStr"

int count=0;

String word[]=myStr.split(" ");

for(int i=0;i<word.length;i++)

{

int index=word[i].indexOf(s);

if(index!= -1)

{

count++;

}

}

return count;

}

public int countOccurrences(char c)

{

// use indexOf and return the number of occurrences of the character "c" in "myStr"

int count=0;

String word[]=myStr.split(" ");

for(int i=0;i<word.length;i++)

{

for (int j = -1; (j = word[i].indexOf(c, j + 1)) != -1; j++) {

if(j!= -1)

{

count++;

}

}

}

return count;

}

int countUpperCaseLetters()

{

// return the number of upper case letter in "myStr"

char[] ch=myStr.toCharArray();

int count=0;

for(int i=0; i<myStr.length();i++) {

if(Character.isUpperCase(myStr.charAt(i))){

count++;

}

}

return count;

}

int countLowerrCaseLetters()

{

// return the number of lower case letter in "myStr"

char[] ch=myStr.toCharArray();

int count=0;

for(int i=0; i<myStr.length();i++) {

if(Character.isLowerCase(myStr.charAt(i))){

count++;

}

}

return count;

}

public void printCounts(String s, char c)

{

System.out.println("**************************************");

System.out.println("Analyzing: myStr= "+myStr);

System.out.println("Number of Upper case Letters= "+countUpperCaseLetters());

System.out.println("Number of Lower case Letters= "+countLowerrCaseLetters());

System.out.println("Number of "+s +" is "+ countOccurrences(s));

System.out.println("Number of "+c +" is "+ countOccurrences(c));

}

public static void main(String[] args) {

MyStringMethods msm = new MyStringMethods();

msm.readString();

msm.printCounts("big", 'a');

msm.setString("Parked in a van down by the river bank .... The van evan vanished neart a lot of other vans");

msm.printCounts("van", 'a');

MyStringMethods msm2=new MyStringMethods();

msm2.setString("the elephant in the room wouldn't budge");

msm2.printCounts("the", 'i');

}

}

======================================================

Output

Problems Javadoc DeclarationConsole 3 <terminated MyStringMethods [Java Applicationl C:1Program FilesJavare1.8.0 181bin iavaw.exe (27-Nov-2018, 2:35:41 AM Enter in the desired String: Aardvarks get big and bigger as You feed them big and bigger ants who Feed on apples. Analyzing: myStr- Aardvarks get big and bigger as You feed them big and bigger ants who Feed on apples. Number of Upper case Letters- 3 Number of Lower case Letters65 Number of big is 4 Number of a is 7 Analyzing: myStr- Parked in a van down by the river bank Number of Upper case Letters- 2 Number of Lower case Letters- 66 Number of van is 5 Number of a is 10 The van evan vanished neart a lot of other vans Analyzing: mystrs the elephant in the room wouldnt budge Number of Upper case Letters-0 Number of Lower case Letters 32 Number of the is 2 Number of 1 is 1

==========================================================

If you have any query please let me know first by comment i will give solutions

Add a comment
Know the answer?
Add Answer to:
Need to fill the comments with code that works. Create The Starting Template for this program...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help with adding comments to my code and I need a uml diagram for...

    I need help with adding comments to my code and I need a uml diagram for it. PLs help.... Zipcodeproject.java package zipcodesproject; import java.util.Scanner; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Zipcodesproject { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input=new Scanner(System.in); BufferedReader reader; int code; String state,town; ziplist listOFCodes=new ziplist(); try { reader = new BufferedReader(new FileReader("C:UsersJayDesktopzipcodes.txt")); String line = reader.readLine(); while (line != null) { code=Integer.parseInt(line); line =...

  • Hi, I am writing Java code and I am having a trouble working it out. The...

    Hi, I am writing Java code and I am having a trouble working it out. The instructions can be found below, and the code. Thanks. Instructions Here are the methods needed for CIS425_Student: Constructor: public CIS425_Student( String id, String name, int num_exams ) Create an int array exams[num_exams] which will hold all exam grades for a student Save num_exams for later error checking public boolean addGrade( int exam, int grade ) Save a grade in the exams[ ] array at...

  • I need to create a code for this prompt: In this project we will build a...

    I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...

  • need help with this JAVA lab, the starting code for the lab is below. directions: The...

    need help with this JAVA lab, the starting code for the lab is below. directions: The Clock class has fields to store the hours, minutes and meridian (a.m. or p.m.) of the clock. This class also has a method that compares two Clock instances and returns the one that is set to earlier in the day. The blahblahblah class has a method to get the hours, minutes and meridian from the user. Then a main method in that class creates...

  • Java Programming The program template represents a complete working Java program with one or more key...

    Java Programming The program template represents a complete working Java program with one or more key lines of code replaced with comments. Read the problem description and examine the output, then study the template code. Using the problem-solving tips as a guide, replace the /* */ comments with Java code. Compile and execute the program. Compare your output with the sample output provided. Modify class Time2 to include a tick method that increments the time stored in a Time2 object...

  • Extend the code from Lab6.A template is given to you with CircleHeader.h, Circle.cpp and CircleMain.cpp Use...

    Extend the code from Lab6.A template is given to you with CircleHeader.h, Circle.cpp and CircleMain.cpp Use the same Circle UML as below and make extensions as marked and as needed. Given below is a UML for the Painting Class. You will need to write PaintingHeader.h and Painting.cpp. The Painting Class UML contains a very basic skeleton. You will need to flesh out this UML and add more instance variables and methods as needed. You do NOT need to write a...

  • Hello, There are some elements in my code that aren't working properly that need to be...

    Hello, There are some elements in my code that aren't working properly that need to be fixed but I don't know what I have done wrong. The printHealthBars() should print out a '+' for each point of current health and a '-' for each difference between current & max health. So, for instance, suppose the pokemon had 6/8 health, the method should print: "[ ++++++-- ]" Something is up with the damage calculation method. The idea is that it should...

  • PLease, I need help with this Code. PLease create correctly documentations comments for better understanding. This...

    PLease, I need help with this Code. PLease create correctly documentations comments for better understanding. This is the input: JAV001 ARRIVE JAV002 ARRIVE JAV003 ARRIVE JAV004 ARRIVE JAV005 ARRIVE JAV001 DEPART JAV004 DEPART JAV006 ARRIVE JAV007 ARRIVE JAV008 ARRIVE JAV009 ARRIVE JAV010 ARRIVE JAV011 ARRIVE JAV012 ARRIVE JAV013 ARRIVE JAV014 ARRIVE JAV006 DEPART JAV014 DEPART JAV013 DEPART JAV005 DEPART JAV015 ARRIVE JAV010 DEPART JAV002 DEPART JAV015 DEPART JAV014 DEPART JAV009 DEPART JAV003 DEPART JAV008 DEPART JAV007 DEPART JAV012 DEPART JAV011...

  • Java/LinkedList Need help with a few of the TODO parts, more info below in comments in...

    Java/LinkedList Need help with a few of the TODO parts, more info below in comments in bold. Thanks, package lab4; import java.util.IdentityHashMap; public class IntNode implements Cloneable {    private int data;    private IntNode next;       public IntNode(int d, IntNode n) {        data = d;        next = n;    }       public IntNode getNext() {        return next;    }          /// Override methods from Object       @Override   ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT