11.8k views
2 votes
Java programing:

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 {
// Function 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");
return;
}
}
__________

1 Answer

2 votes

Answer:

import java.util.Scanner;

public class UnitTesting {

// Function 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));

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

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

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

return;

}

}

Step-by-step explanation:

Added statements are highlighted.

Since the cubeNum function calculates the cube of the given number and we are asked to write two statements to test inputs 3 and -1, pass the parameters 3 and -1 to the function called cubeNum and print the results using print statements

User Amesh
by
3.8k points