Question
  • In JAVA: Define a test suite method, define a test method testcube that exercises Calculation.cube() in Calculation class, and Organize your tests in your test suite (testfindMax & testcube)

Given the following code below: 6. 7. 1. public class Calculation { 2. //method that returns cube of the given number 3. publ

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Java code for above problem

class Calculation
{
   public int findMax(int arr[])
   {
       int max=0;
       for(int i=1;i<arr.length;i++)
       {
           if(max<arr[i])
           {
               max=arr[i];
           }
              
       }
       return max;
   }
   public static int cube(int n)
   {
       return n*n*n;
   }
}
class Main
{
   // test suite method
   public static void main(String args[])
   {
       System.out.println(Calculation.cube(3));   // prints 27
      
       int [] arr=new int[]{1,2,3,4,5};
       Calculation obj=new Calculation();
       System.out.println(obj.findMax(arr));       // prints 5
   }
}

Mention in comments if any mistakes or errors are found. Thank you.

Add a comment
Know the answer?
Add Answer to:
In JAVA: Define a test suite method, define a test method testcube that exercises Calculation.cube() in...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Define a test method testfindMax that exercises Calculation.findMax() in Calculation class Define a tearDown() method Given...

    Define a test method testfindMax that exercises Calculation.findMax() in Calculation class Define a tearDown() method Given the following code below: 6. 7. 1. public class Calculation { 2. //method that returns cube of the given number 3. public int findMax(int ac[]}{ 4. int max=0; 5. for(int į=1;i<acr.length;i++){ if(max<arc[i]). max=acc[i]; } 8. return max: 10. } 11. //method that returns cube of the given number 12. public static int cube(int n){ 13. return n*n*n; 14. 15. } } 9. }

  • Hi everyone! I need help on my Java assignment. I need to create a method that...

    Hi everyone! I need help on my Java assignment. I need to create a method that is called sumIt that will sum two values and will return the value.It should also invoke cubeIt from the sum of the two values. I need to change the currecnt program that I have to make it input two values from the console. The method has to be called sumIt and will return to the sum that will produce the cube of the sum...

  • Fix Java Code Question: Coding AList Get Position Write a method for the AList class that...

    Fix Java Code Question: Coding AList Get Position Write a method for the AList class that returns the first position of a given object in the list with the method header below. public int getPosition(T anObject) Answer: public int getPosition(T anObject) { int position = 0; for (int i = 0; i < length; i++) if (list[i].equals(anObject)) { position = i + 1; } return position; }

  • JAVA (advanced data structures) write a completed program using HashIntSet and HashMain include the method in the main...

    JAVA (advanced data structures) write a completed program using HashIntSet and HashMain include the method in the main if possible. those are just the sample HashIntSet and HashMain (don't have to be the same but follow the Q requirement. thanks HashIntSet.java public class HashIntSet { private static final double MAX_LOAD_FACTOR = 0.75; private HashEntry[] elementData; private int size; // Constructs an empty set. public HashIntSet() { elementData = new HashEntry[10]; size = 0; } // Adds the given element to...

  • Write in Java Implement the parse method and test it by calling with three different strings...

    Write in Java Implement the parse method and test it by calling with three different strings and by printing the results. The Scanner method can be used to read values from strings, files, or System.in. We need to invoke the useDelimiter method to define what symbols can separate, or terminate, the digits of a Fraction. public static Fraction parse(String input) t Scanner s new Scanner(input) useDelimitercTVMitln"); int num s.nextlnt() int denom s.nextlnt); s.close): return new Fraction(num, denom) class Codechef static...

  • Consider the Rectangle2 java class definition below. Write the definition of an equals) method that checks...

    Consider the Rectangle2 java class definition below. Write the definition of an equals) method that checks if two Rectangle objects have the same dimensions Write a Java program to test the equals method public class Rectangle2 K private int width, length; public Rectangle2(int w, int 1) { setWidth(w); setLength(1); System.out.println("Inside parameterized!!!"); } public void setWidth(int w) { width = w;} public void setLength(int i) { length = 1;} int getWidth() { return width; } int getLength() { return length; }...

  • I must implement a class to calculate n-th row of Pascal's Triangle (in Java). I need...

    I must implement a class to calculate n-th row of Pascal's Triangle (in Java). I need to create a static method that takes an argument "n" and returns the n'th line of pascal's triangle. the main method, which will call the class, is already done and the class is set up. Please build this without modifying the main method and without modifying exactly what the static method returns. public class Main { public static void main(String[] args) { int n...

  • JAVA Code: Complete the method, sumOdds(), below. The method takes in an array of integers, numbers,...

    JAVA Code: Complete the method, sumOdds(), below. The method takes in an array of integers, numbers, and returns the sum of all the odd numbers in the array. The method should return 0 if the array contains no odd numbers. For example, if the given array is [12, 10, 5, 8, 13, 9] then the method should return 27 (5+13+9=27). Starter Code: public class Odds { public static int sumOdds(int[] numbers) { //TODO: complete this method    } }

  • Need help with a few questions! Using the JAVA language please. 1) exercises - branching Write...

    Need help with a few questions! Using the JAVA language please. 1) exercises - branching Write a method whatToWear(int temp) that takes a temperature and then outputs a string for what to wear in different weather conditions. There must be at least 3 categories. For example, whatToWear(90) might return “shorts” and whatToWear(30) might return “down coat” 2) Enum exercise • Define an enum Seasons, and rewrite the whatToWear method to use enums and switch statement 8) 2D array exercise 1....

  • need help editing or rewriting java code, I have this program running that creates random numbers...

    need help editing or rewriting java code, I have this program running that creates random numbers and finds min, max, median ect. from a group of numbers,array. I need to use a data class and a constructor to run the code instead of how I have it written right now. this is an example of what i'm being asked for. This is my code: import java.util.Random; import java.util.Scanner; public class RandomArray { // method to find the minimum number in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT