Question

Add two more statements to main() to test inputs 3 and -1. Use print statements similar...

Add two more statements to main() to test inputs 3 and -1. Use print statements similar to the existing one (don't use assert).

...

import java.util.Scanner;

public class UnitTesting {
   // Method returns origNum cubed
   public static int cubeNum(int origNum) {
      return origNum * origNum * origNum;
   }

   public static void main (String [] args) {

      System.out.println("Testing started");
      System.out.println("2, expecting 8, got: " + cubeNum(2));

      /* Your solution goes here */

      System.out.println("Testing completed");
   }
}

Homework Answers

Answer #1
public class UnitTesting {
    public int cubeNum(int origNum) {
        return origNum * origNum * origNum;
    }

    public static void main(String[] args) {
        UnitTesting cubeTester = new UnitTesting();
        System.out.println("Testing started");
        System.out.println("2, expecting 8, got: " + cubeTester.cubeNum(2));

        System.out.println("3, expecting 27, got: " + cubeTester.cubeNum(3));
        System.out.println("-1, expecting -1, got: " + cubeTester.cubeNum(-1));

        System.out.println("Testing completed");
    }
}

Know the answer?
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
Similar Questions
6.25.1: Unit testing C++ Add two more statements to main() to test inputs 3 and -1....
6.25.1: Unit testing C++ Add two more statements to main() to test inputs 3 and -1. Use print statements similar to the existing one (don't use assert). #include <iostream> using namespace std; // Function returns origNum cubed int CubeNum(int origNum) { return origNum * origNum * origNum; } int main() { cout << "Testing started" << endl; cout << "2, expecting 8, got: " << CubeNum(2) << endl; /* Your solution goes here */ cout << "Testing completed" << endl;...
Write an expression that will cause "Foot or more" to print if the value of numInches...
Write an expression that will cause "Foot or more" to print if the value of numInches is greater than or equal to 12. import java.util.Scanner; public class EqualityAndRelational {    public static void main (String [] args) {       int numInches;       Scanner scnr = new Scanner(System.in);       numInches = scnr.nextInt(); // Program will be tested with values: 10, 11, 12, 13.       if (/* Your solution goes here */) {          System.out.println("Foot or more");       }       else {...
Write an expression that will cause "greater or equal to -10" to print if the value...
Write an expression that will cause "greater or equal to -10" to print if the value of userNum is greater than or equal to -10. import java.util.Scanner; public class EqualityAndRelational {    public static void main (String [] args) {       int userNum;       Scanner scnr = new Scanner(System.in);       userNum = scnr.nextInt(); // Program will be tested with values: -9, -10, -11, -12.       if (//solution goes here//) {          System.out.println("greater or equal to -10");       }       else...
Write an if-else statement that checks patronAge. If 55 or greater, print "Senior citizen", otherwise print...
Write an if-else statement that checks patronAge. If 55 or greater, print "Senior citizen", otherwise print "Not senior citizen" (without quotes). End with newline. import java.util.Scanner; public class DetectSenior {    public static void main (String [] args) {       Scanner scnr = new Scanner(System.in);       int patronAge; //Solution goes here//       patronAge = scnr.nextInt();    } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new...
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // Read the input string String input = sc.nextLine(); BalancedParentheses bp = new BalancedParentheses(); // Print whether the string has balanced parentheses System.out.println(bp.hasBalancedParentheses(input)); } } class BalancedParentheses { public boolean hasBalancedParentheses(String input) { // Remove this and implement code throw new UnsupportedOperationException(); } }
Fix the program: what if the input is three? import java.util.Scanner public class Test { public...
Fix the program: what if the input is three? import java.util.Scanner public class Test { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter an integer: "); int m = in.nextInt(); System.out.print("Enter another integer: "); int n = in.nextInt(); System.out.println(m + " " + n); } }
in JAVA Write a switch statement that checks origLetter. If 'a' or 'A', print "Alpha". If...
in JAVA Write a switch statement that checks origLetter. If 'a' or 'A', print "Alpha". If 'b' or 'B', print "Beta". For any other character, print "Unknown". Use fall-through as appropriate. End with newline. import java.util.Scanner; public class ConvertToGreek { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); char origLetter; origLetter = scnr.next().charAt(0); /* Your solution goes here */ } }
import java.util.Scanner; public class AroundTheClock {    public static void main(String[] args)    {       ...
import java.util.Scanner; public class AroundTheClock {    public static void main(String[] args)    {        Scanner input = new Scanner(System.in);        int departureTime = input.nextInt();        int travelTime = input.nextInt();        int arrivalTime;            departureTime =12;            departureTime = 0;            arrivalTime = (int) (departureTime + travelTime);            (arrivalTime = (arrivalTime >=12));            if (arrivalTime = arrivalTime %12)            {            System.out.println(arrivalTime);...
Print "userNum1 is negative." if userNum1 is less than 0. End with newline.Convert userNum2 to 0...
Print "userNum1 is negative." if userNum1 is less than 0. End with newline.Convert userNum2 to 0 if userNum2 is greater than 10. Otherwise, print "userNum2 is less than or equal to 10.". End with newline. public class UserNums {    public static void main (String [] args) {       int userNum1;       int userNum2;       userNum1 = -1;       userNum2 = 13; //solution goes here//       System.out.println("userNum2 is " + userNum2);    } }
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {       ...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {        Stack<Integer> new_stack = new Stack<>();/* Start with the empty stack */        Scanner scan = new Scanner(System.in);        int num;        for (int i=0; i<10; i++){//Read values            num = scan.nextInt();            new_stack.push(num);        }        int new_k = scan.nextInt(); System.out.println(""+smallerK(new_stack, new_k));    }     public static int smallerK(Stack s, int k) {       ...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT