PLEASE HURRY
Software Testing
Don't make any changes to the provided code. Please write a test case for the below prompt using the provided java programs
Use the setString() function in MyCustomStringInterface to set the value to “Peter Piper picked a peck of pickled peppers.”. Then test to see if reverseNCharacters() function returns the reversed string when the characters are reversed in groups of 4 and padding is disabled (in this case, “etePiP r repkcipa decep fo kcip delkpep srep.”).
Next, test to see if reverseNCharacters() provides the correct output for the same input and grouping when padding is enabled (in this case, “etePiP r repkcipa decep fo kcip delkpep srepXXX.”).
MyCustomString.java
public class MyCustomString implements MyCustomStringInterface
{
private String string;
@Override
public String getString() {
return string;
}
@Override
public void setString(String string) {
this.string = string;
}
@Override
public int countNumbers() {
StringBuffer tmpString = new StringBuffer();
int count=0;
boolean inNumber=false;
//avoid null pointer exception!
if(string==null || string.isEmpty())
return 0;
for (int i = 0; i < string.length(); i++) {
char ch = string.charAt(i);
if (Character.isDigit(ch)) {
if (!inNumber) {
count++;
inNumber = true;
}
}
else {
if (inNumber) {
inNumber = false;
}
}
}
return count;
}
@Override
public String reverseNCharacters(int n, boolean padded) {
if (string == null) {
throw new NullPointerException();
}
if (n <= 0) {
throw new IllegalArgumentException();
}
StringBuffer tmpString = new StringBuffer();
StringBuffer resultString = new StringBuffer();
StringBuffer currString = new StringBuffer(string);
int i;
for (i = 0; i + n < currString.length(); i+=n) {
tmpString = tmpString.append(new
StringBuffer(currString.substring(i,i+n)).reverse());
}
if (padded)
{
for (int x = n - (currString.length() - i); x > 0; x--)
currString.append('X');
}
tmpString = tmpString.append(new
StringBuffer(currString.substring(i)).reverse());
return tmpString.toString();
}
@Override
public void convertDigitsToNamesInSubstring(int startPosition, int
endPosition) {
if (string == null) {
throw new NullPointerException();
}
if ((startPosition > endPosition)) {
throw new IllegalArgumentException();
}
if (endPosition > string.length() || (startPosition <
1)){
throw new MyIndexOutOfBoundsException();
}
StringBuffer tmpString = new StringBuffer();
String tmpDigit = new String();
boolean look_back = false;
for (int i = 0; i < string.length(); i++) {
char ch = string.charAt(i);
if ((i < startPosition - 1) || (i > endPosition - 1)) {
if(look_back) {
look_back = false;
}
tmpString.append(ch);
continue;
} else {
if (Character.isDigit(ch)) {
switch (ch) {
case '0':
tmpDigit = "Zero";
break;
case '1':
tmpDigit = "One";
break;
case '2':
tmpDigit = "Two";
break;
case '3':
tmpDigit = "Three";
break;
case '4':
tmpDigit = "Four";
break;
case '5':
tmpDigit = "Five";
break;
case '6':
tmpDigit = "Six";
break;
case '7':
tmpDigit = "Seven";
break;
case '8':
tmpDigit = "Eight";
break;
case '9':
tmpDigit = "Nine";
break;
}
if(look_back)
tmpString.append(tmpDigit.toLowerCase());
else
tmpString.append(tmpDigit);
look_back = true;
} else {
if(look_back){
look_back = false;}
tmpString.append(ch);
}
}
}
string = tmpString.toString();
}
}
MyCustomStringInterface.java
/**
* This is an interface for a simple class that represents a string,
defined
* as a sequence of characters.
*
* This interface should NOT be altered in any way.
*/
public interface MyCustomStringInterface {
/**
* Returns the current string. If the string is null, it should
return null.
*
* @return Current string
*/
String getString();
/**
* Sets the value of the current string.
*
* @param string The value to be set
*/
void setString(String string);
/**
* Returns the number of numbers in the current string, where a
number is defined as an
* unbroken sequence of digits.
*
* If the current string is null, empty, or uninitialized, the
method should return 0.
*
* Examples:
* - countNumbers would return 2 for string "My numbers are 11 and
9".
*
* @return Number of numbers in the current string
*/
int countNumbers();
/**
* Returns a string that consists of all characters in the original
string with each segment of n characters
* reversed.
* If padded is true, the final segment of characters will have the
character 'X' added to it enough time to make
* a full segment.
*
*
* Examples:
* - For n=2 and padded=true, the method would return the string
with every pair of characters swapped in place, and
* if there were an odd number of characters, an X would be added to
the last segment before it is reversed.
* - For n=3 and padded=false, the method would return the string
with every segment of 3 characters reversed in place,
* and the final segment would be reversed even if less than 3
characters without any additional characters added.
*
* Values n and padded are passed as parameters. The starting
character is considered to be in Position 1.
*
* @param n Determines size of the string segments to be
reversed
* @param padded Determines whether an incomplete final segment will
be padded with 'X'.
* @return String with the segments in their original order and the
contents of the segments reversed.
* @throws NullPointerException If the current string is null or
uninitialized.
* @throws IllegalArgumentException If "n" less than or equal to
zero, and the current string is not null.
*/
String reverseNCharacters(int n, boolean padded);
/**
* Replace the individual digits in the current string, between
startPosition and endPosition
* (included), with the corresponding English names of those digits,
with the first letter of a number (unbroken
* string of digits) capitalized. The first character in the string
is considered to be in Position 1.
*
* Examples:
* - String 460 would be converted to Foursixzero
* - String 416 would be converted to Fouronesix
*
* @param startPosition Position of the first character to
consider
* @param endPosition Position of the last character to consider
* @throws NullPointerException If the current string is null or
uninitialized.
* @throws IllegalArgumentException If "startPosition" >
"endPosition"
* @throws MyIndexOutOfBoundsException If "startPosition" < 1 or
"endPosition" is out of bounds (greater than the
* length of the string) and "startPosition" <=
"endPosition"
*/
void convertDigitsToNamesInSubstring(int startPosition, int
endPosition);
}
MyIndexOutOfBoundsException.java
public class MyIndexOutOfBoundsException extends
RuntimeException {
private static final long serialVersionUID =
8226094121089030034L;
public MyIndexOutOfBoundsException(String message)
{
super(message);
}
public MyIndexOutOfBoundsException() {
super();
}
}
Hi, I have answered previous part of this question (testing countNumbers). I’m assuming that by test case, you meant JUnit testing. Here is needed code for MyCustomStringTest class which has methods testCountNumbers and testReverseNCharacters, which will test the countNumbers function and reverseNCharacters methods of MyCustomStringInterface respectively as mentioned in the question. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
//MyCustomStringTest.java
import static org.junit.Assert.*;
import org.junit.Test;
public class MyCustomStringTest {
private MyCustomStringInterface myCustomStr;
// JUnit test method for testing countNumbers method
@Test
public void testCountNumbers() {
// initializing MyCustomString object
myCustomStr = new MyCustomString();
// using setString, updating the text
myCustomStr.setString("H3y, l3t'5 put s0me d161ts in this 5tr1n6!11!!");
// ensuring that the countNumbers return 9
assertEquals(myCustomStr.countNumbers(), 9);
}
// JUnit test method for testing reverseNCharacters method
@Test
public void testReverseNCharacters() {
// initializing MyCustomString object
myCustomStr = new MyCustomString();
// using setString, updating the text
myCustomStr.setString("Peter Piper picked a peck of pickled peppers.");
// ensuring that correct String is returned when the characters are
// reversed in groups of 4 and padding is disabled
assertEquals(myCustomStr.reverseNCharacters(4, false),
"etePiP r repkcipa decep fo kcip delkpep srep.");
// ensuring that correct String is returned when the characters are
// reversed in groups of 4 and padding is enabled
assertEquals(myCustomStr.reverseNCharacters(4, true),
"etePiP r repkcipa decep fo kcip delkpep srepXXX.");
}
}
PLEASE HURRY Software Testing Don't make any changes to the provided code. Please write a test...
package model; import java.util.Iterator; /** * This class implements interface PriorityList<E> to represent a generic * collection to store elements where indexes represent priorities and the * priorities can change in several ways. * * This collection class uses an Object[] data structure to store elements. * * @param <E> The type of all elements stored in this collection */ // You will have an error until you have have all methods // specified in interface PriorityList included inside this...
In Java Language. Modify the LinkedPostionalList class to support a method swap(p,q) that causes the underlying nodes referenced by positions p and q to be exchanged for each other. Relink the existing nodes, do not create any new nodes. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- package lists; import java.util.Iterator; import java.util.NoSuchElementException; public class LinkedPositionalList implements PositionalList { //---------------- nested Node class ---------------- /** * Node of a doubly linked list, which stores a reference to its * element and to both the previous and next...
For the code below complete the preOrder() method so that it performs a preOrder traversal of the tree. For each node it traverses, it should call sb.append() to add a "[" the results of traversing the subtree rooted at that node, and then a "]". You should add a space before the results of the left and right child traversals, but only if the node exists. code: package edu.buffalo.cse116; import java.util.AbstractSet; import java.util.Iterator; public class BinarySearchTree<E extends Comparable<E>> extends AbstractSet<E>...
Objectives Problem solving using arrays and ArrayLists. Abstraction. Overview The diagram below illustrates a banner constructed from block-letters of size 7. Each block-letter is composed of 7 horizontal line-segments of width 7 (spaces included): SOLID as in block-letters F, I, U, M, A, S and the blurb RThere are six distinct line-segment types: TRIPLE as in block-letter M DOUBLE as in block-letters U, M, A LEFT_DOT as in block-letters F, S CENTER_DOT as in block-letter...
Java StringNode Case Study: Rewrite the following methods in the StringNode class shown below. Leave all others intact and follow similar guidelines. The methods that need to be changed are in the code below. - Rewrite the indexOf() method. Remove the existing recursive implementation of the method, and replace it with one that uses iteration instead. - Rewrite the isPrefix() method so that it uses iteration. Remove the existing recursive implementation of the method, and replace it with one that...
Add a non-recursive inorder() method to class LinkedBinaryTree<E> to traverse binary tree. Test inorder() method. Implementation in Java #########LinkedBinary Tree class######### public class LinkedBinaryTree<E> extends AbstractBinaryTree<E> { //---------------- nested Node class ---------------- /** Nested static class for a binary tree node. */ protected static class Node<E> implements Position<E> { private E element; // an element stored at this node private Node<E> parent; // a reference to the parent node (if any) private Node<E> left; // a reference to the left...
I am not passing some of the code when i run the testing . PriorityQueue public class PriorityQueue<T extends Comparable<T>> implements IPriorityQueue<T> { private Vector<T> theVector = new Vector<>(0, 1); private int size = 0; @Override public void insert(T element) { theVector.pushBack(element); size++; bubbleUp(); } @Override public T peekTop() throws java.util.NoSuchElementException { if (isEmpty()) { throw new java.util.NoSuchElementException(); } ...
This is the code I have written for a BingoBall program, I'd appreciate it if someone could help me fix this public class BingoBall { private char letter; private int number; // NOTE TO STUDENT // We challenge you to use this constant array as a lookup table to convert a number // value to its appropriate letter. // HINT: It can be done with with a single expression that converts the number // to an index position in the...
Since we do not want to have to rewrite this code when the element type changes, this classes uses a Comparator to assist in ordering the elements. You will need to complete the siftUpComparator() and siftDownComparator() methods in the LinkedHeap Class. siftUp §Added element may violate heap-order property §siftUp() restores order starting at added node §Processing will continue working up the tree until: úFinds properly ordered node & parent úReaches the root (reaches node without parent) siftDown §Restores heap’s order...
I keep getting an Error after I ask the user for test scores. What is missing? package testscores; import java.util.Scanner; public class TestScores { /** * @param args the command line arguments */ private double[] scores; public TestScores(double[] score) throws IllegalArgumentException { scores = new double[scores.length]; for (int i = 0; i < scores.length; i++) { if (score[i] < 0 || score[i] > 100){ throw new IllegalArgumentException(); } scores[i]=score[i]; } } public double getAverage() { int sum=0;...