Answered step by step
Verified Expert Solution
Question
1 Approved Answer
* @param n * @return the absolute value for n. * absolute value is defined as the number without the negative sign, if any
* @param n * @return the absolute value for n. * absolute value is defined as the number without the negative sign, if any * For example, absolute(-6) = 6, absolute(9) = 9 */ public static int absolute(int n) { } return 0; //to be completed public void testAbsolute() { } assertEquals(10, Stage2.absolute (10)); assertEquals(10, Stage2.absolute (-10)); assertEquals(0, Stage2.absolute()); assertEquals(1237, Stage2.absolute (-1237)); currentMethodName = new Throwable().getStackTrace( ) [].getMethodName(); Throwable().getStackTrace()[0].getMethodName(); * @param x @param y * @return the quadrant in which coordinate (x, y) exists quadrant 1: non-negative x, non-negative y * quadrant 2: negative x, non-negative y * quadrant 3: negative x, negative y * quadrant 4: non-negative x, negative y public static int getQuadrant(int x, int y) { return 0; //to be completed } public void testGetQuadrant() { } assertEquals(1, Stage2.getQuadrant (0, 0)); assertEquals(1, Stage2.getQuadrant (2,2)); assertEquals(2, Stage2.getQuadrant (-2,3)); assertEquals(3, Stage2.getQuadrant (-3,-4)); assertEquals(4, Stage2.getQuadrant (3,-3)); currentMethodName = new Throwable().getStackTrace()[0].getMethodName(); ** * * @param n (n could be positive, negative or zero) @return the last digit of the number * For example, * lastDigit(15) = 5 * lastDigit(-15) = 5 * lastDigit(0) = 0 * lastDigit(8) = 8 */ public static int lastDigit(int n) { } return str.lastDigit()-1; //to be completed public void testLastDigit() { } assertEquals(0, Stage2. LastDigit(0)); assertEquals(8, Stage2. LastDigit(8)); assertEquals(5, Stage2. LastDigit(15)); assertEquals(5, Stage2. LastDigit(-15)); assertEquals(7, Stage2. LastDigit(-1000007)); assertEquals(4, Stage2. LastDigit (1000004)); assertEquals(5, Stage2. LastDigit(5555)); currentMethodName = new Throwable().getStackTrace()[0].getMethodName(); /** * @param val (assume val is more than or equal to zero) wwww * @return floor of val wwwww * floor of a floating-point value is defined as the highest integer * that is less than or equal to the value. * For example, floor(4.2) = 4, floor(7.0) = 7, floor (5.9999) = 5 */ public static int floor (double val) { } return 0; //to be completed * @param str: assume it contains at least one character * @return the last character in the String */ public static char getLastChar(String str) { } /* return 'a'; //'a' used as default value (to be completed) * @param str: assume it contains at least one character @return the String with the last character removed */ public static String getWithout LastChar(String str) { return ""; //to be completed } public void test Floor() { } assertEquals(1, Stage2.floor(1.99)); assertEquals(0, Stage2.floor(0.75)); assertEquals(7, Stage2.floor(7.00)); assertEquals(5, Stage2.floor(5.9999)); assertEquals(400, Stage2.floor(400.001)); currentMethodName = new Throwable().getStackTrace()[0].getMethodName(); @Test @Graded (description = "getlastchar", marks = 1) public void testGetLastChar() { } assertEquals('r', Stage2.getLastChar("Super")); assertEquals('!', Stage2.getLastChar("This is fun!")); assertEquals('x', Stage2.getLastChar("x")); currentMethodName = new Throwable().getStackTrace()[0].getMethodName(); @Test @Graded(description = "getwithoutlastchar", marks = 1) public void testGetWithoutLastChar() { } assertEquals("Supe", Stage2.getWithoutLastChar("Super")); assertEquals("This is fun", Stage2.getWithoutLastChar("This is fun!")); assertEquals("", Stage2.getWithoutLastChar("x")); currentMethodName = new Throwable().getStackTrace()[0].getMethodName();
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started