Varsity Tutors connects learners with a variety of experts and professionals. Varsity Tutors does not have affiliation with universities mentioned on its website. Media outlet trademarks are owned by the respective media outlets and are not affiliated with Varsity Tutors.Īward-Winning claim based on CBS Local and Houston Press awards. Well, I'm going to have to a test a method which computes the area of a circle.Names of standardized tests are owned by the trademark holders and are not affiliated with Varsity Tutors LLC.Ĥ.9/5.0 Satisfaction Rating based upon cumulative historical session ratings through 12/31/20. Your imaginary thought process is in italics. Below I'm using skeletal JUnit3 for that, not sure what you are using in your class. One approach: When you are stuck, (or, as many will argue, all the time), you should Start with the Test Code. Return Math.PI * radius * radius * height //calculates and returns area of cylinder Public static double getArea(double radius, double height) //method to get area of cylinder * Method should calculate the area of a cylinder Return length * width //calculates and returns rectangle area Public static double getArea(int length, int width) //method to get area of rectangle * Method should calculate the area of a rectangle Return Math.PI * radius * radius //calculates and returns circle area Public static double getArea(double radius) //method to get area of circle * Method should calculate the area of a circle Demonstrate the class in a complete program. * Because the three methods are to be overloaded, they should each have the same name, * geometric shapes: circles, rectangles, cylinders * Write a class that has three overloaded static methods for calculating the areas of the following * This program will calculate area of rectangle, circle, and cylinder. It is good to test values like 0 and 1 - but it is also good to test "non-obvious" numbers like "23.49" because they don't have the special properties and identities that 0 or 1 (or 2, or integers have) Write a basic test which compares your code's output with a known value - that is, the value which you calculated by hand. You can do a similar thing with your area-calculating code. In this case, one could go back and correct the code, looking for a problem with square(). If I ran this program, I would seen an error immediately - wait a sec, my output looks like this: Expected output: 4 squared = 16 ("Actual output: 4 squared = " + MathClass.square(4)) To write a bare-bones unit test for this, I might write: public static void main(String args) Let me make sure my square() function returns 16." So I might say, "Well, I know the square of 4. In order to test, you need to run your program - in this case, my square() function - and compare that to known output. Lets say I had a "calculate the square of a number" function: public class MathClass When it comes to testing, a simple way to do a test would be like this. Or, show us what you've got and we'll try to help then. Once you have that, you will find that it is very straightforward to write the actual BODY. If you figure out the question mark parts, you will have the "empty shells" of the functions. In other words, what would be the ?s in functions like the following? static ? areaOfCircle(?) Obviously, you are dealing with three different functions. Think about how you would write them in Java. Now to writing: obviously, you understand what these functions are mathematically. Hence, all the functions need to be "static", so you could write something like Area.circleArea(.) In other words, there is no Area "object". It provides services but never gets instantiated. Since you say you've been doing well in the class, I'll assume you know some Java already - this is never a first assignment in an intro to programming. Since this is a homework assignment, we can't give you the answer, but we can direct you in the correct way.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |