
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

==========================================================
If you have any query please let me know first by comment i will give solutions
Need to fill the comments with code that works. Create The Starting Template for this program...
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 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 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 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 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 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...
Java Code please read comments and add the code to required lines....LINE 1 to LINE 5 ********************************************************************** * Program Summary: This program demonstrates these basic Java concepts: * - Creating an array based on user input * - Accessing and displaying elements of the array * * The program should declare an array to hold 10 integers. * The program should then ask the user for an integer. * The program should populate the array by assigning the user-input integer...
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 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...