1. Write a Java program that parses the frequency of occurrences of each word in a string and displays the word and the frequency at which it appears. (the words are separated by a space, such as "Hello World My First Unit Test");
2. Write unit tests for testing;
3. Use Elcemma to view code coverage, which requires coverage of up to 100%.
Import java.util.ArrayList;
Import java.util.Collections;
Import Java.util.Comparator;
Import Java.util.HashMap;
Import java.util.List;
Import Java.util.Map;
Import Java.util.Map.Entry;
public class One {
public static void Main (string[] args) {
String str = "Hello World My first Unit Test";
string[] items = Str.split ("");
map<string, integer> map = new hashmap<string, integer> ();
for (String S:items) {
if (Map.containskey (s))
Map.put (S, map.get (s) + 1);
else {
Map.put (S, 1);
}
}
list<entry<string, integer>> list = new arraylist<entry<string, integer>> ();
For (entry<string, integer> entry:map.entrySet ()) {
List.add (entry);
}
Collections.sort (list, new Entrycomparator ());
For (entry<string, integer> obj:list) {
System.out.println (Obj.getkey () + "Frequency of Occurrence:" + obj.getvalue ());
}
}
}
Class Entrycomparator implements Comparator<entry<string, integer>> {
public int Compare (entry<string, integer> O1, entry<string, integer> O2) {
return O1.getvalue () > O2.getvalue ()? 0:1;
}
}
Topic Two:
1. Write a Java program that reverses the order of words in an English sentence and then outputs it. For example, enter "How IS is", output "you is how";
2. Write unit tests for testing;
3. Use Elcemma to view code coverage, requiring coverage of up to 100%
public class-{
public static void Main (string[] args) {
System.out.println (Reverse ("How is You");
}
public static string reverse (String str) {
String temp = "";
StringBuffer buf = new StringBuffer ();
for (int i = Str.length ()-1; I >= 0; i--) {
char C = Str.charat (i);
if (c = = ") {
Buf.append (temp);
Buf.append (c);
temp = "";
} else {
temp = c + temp;
}
}
Buf.append (temp);
return buf.tostring ();
}
}
Minjiang College School of the next 2015-2016 years software testing Course-second assignment (personal assignment)