Menu

Java Run Eclipse Test Cases Would Cause Two Methods Produce Error Code Four Methods Two Er Q43856772

In Java run through Eclipse, What test cases would cause two ofthese methods to produce an error?

* This is code for four methods, two of which have errors.
* You should create a second file calledTestThisClassTest.java
* which provides at least three test cases for each method.
* The methods with errors should be left with errors, but the
* code should expose the problem with them.
*
*
* @author Jason Yoder, Aaron Wilkin, and Joe Hollingsworth
*
*/

public class TestThisClass {

  
   /**
   * Given a string, returns the number of Xs. Both
   * uppercase and lowercase Xs should be included inthe
   * count.
   *
   * @param the string
   */
   public static int numberOfXs(String input) {
       int count, count2;
       count = 0;
       count2 = 0;
       for(int i = 0; i <input.length(); i++) {
          if(input.charAt(i) == ‘X’)
              count++;
          if(input.charAt(i) == ‘x’)
              count2++;
       }
       return count;
   }
  
  
  
   /**
   * Given an input string, count the number ofoccurrences of
   * the string “Chocula”, case-sensitive.
   *
   */
   public static int countChocula(String input) {
       int choculas=0;
       for (int i=0; i<input.length()-7; i++) {
           if (input.substring(i,i+7).equals(“Chocula”)) {
              choculas++;
           }
       }
       return choculas;  
   }
  
  
   /**
   * Given a length and width of a floor in feet and thecost of
   * paint in dollar per square foot, calculate the costto paint the room.
   * If any non-positive values are used for anyparameters the result should be -1.
   * The cost in dollars should be rounded up to thenearest whole dollar.
   *
   *
   * @param length, width, dollarsPerSqFoot
   */
   public static int paintCost(int length, int width, intdollarsPerSqFoot) {
       if ( Math.min(length, Math.min(width, dollarsPerSqFoot)) < 0) {
           return -1;
       }
       returnlength*width/dollarsPerSqFoot;
   }
  
  
   /**
   * Given an ArrayList of String describing Pizza, thecost should be calculated as follows:
   * Zero toppings means the pizza costs $8. The firsttwo toppings are $2 each and after that
   * each other topping costs $1. There is a special ifthere are exactly the toppings:
   * “pepperoni”, “onions” and “sausage” (order does notmatter) and then the cost is $12.
   *
   *
   * @param toppings
   */
   public static intpizzaCostCalculator(ArrayList<String> toppings) {
       ArrayList<String> special =new ArrayList<String>();
       special.add(“pepperoni”);
       special.add(“onions”);
       special.add(“sausage”);
      
       int numToppings =toppings.size();
      
       if (numToppings == 0) {
           return 8;
       } else if (numToppings < 3){
           return 8 + 2*numToppings;
       } else if (numToppings == 3){
           if (toppings.containsAll( special )) {
              return 12;
           } else {
              return 13;
           }
       } else {
           return 12 +(numToppings – 2);
       }

      
      
   }
      
  
  
}

Expert Answer


Answer to In Java run through Eclipse, What test cases would cause two of these methods to produce an error? * This is code for fo…

OR