Question
JAVA Problem public static String quadrant(int x, int y) Given integer coordinates for x and y, give back a string that correctly describes what quadrant
JAVA Problem
public static String quadrant(int x, int y)
Given integer coordinates for x and y, give back a string that correctly describes what quadrant the point is in. The five valid responses are:
answer | applicable condition |
---|---|
"first" | x, y are both positive |
"second" | x is negative, y is positive |
"third" | x, y are both negative |
"fourth" | x is positive, y is negative |
"none" | one of x, y is zero |
public static int sumCubes(int a, int b)
Given two integers a and b, calculate the sum of the cubes of all values from a to b inclusive.
when a>b, return zero.
when a and b are equal, return a cubed.
exponentiation is available via the Math.pow(int base, int exp) method. It's always available (using it doesn't count as importing anything). But we could work around this, since it's always a value being cubed.
example:
sumCubes(2,4) == (2^3 + 3^3 + 4^3) == (8+27+64) == 99
public class Task2 { public static String quadrant(int x, int y){ throw new RuntimeException("not implemented!"); } public static int sumCubes(int a, int b){ throw new RuntimeException("not implemented!"); } }
Tester:
import org.junit.*; import static org.junit.Assert.*; import java.util.*; public class Task2Tests { public static void main(String args[]){ org.junit.runner.JUnitCore.main("Task2Tests"); } @Test public void task2_quadrant_01 (){ assertEquals( "first", Task2.quadrant( 4, 5)); } @Test public void task2_quadrant_02 (){ assertEquals( "second", Task2.quadrant( -6, 7)); } @Test public void task2_quadrant_03 (){ assertEquals( "third", Task2.quadrant( -9, -8)); } @Test public void task2_quadrant_04 (){ assertEquals( "fourth", Task2.quadrant( 10, -3)); } @Test public void task2_quadrant_05 (){ assertEquals( "none", Task2.quadrant( 5, 0)); } @Test public void task2_quadrant_06 (){ assertEquals( "none", Task2.quadrant( 0, -3)); } @Test public void task2_quadrant_07 (){ assertEquals( "none", Task2.quadrant( 0, 0)); } @Test public void task2_quadrant_08 (){ assertEquals( "first", Task2.quadrant( 1, 1)); } @Test public void task2_quadrant_09 (){ assertEquals( "second", Task2.quadrant(-100, 100)); } @Test public void task2_quadrant_10 (){ assertEquals( "fourth", Task2.quadrant( 300,-456)); } @Test public void task2_sumCubes_01 (){ assertEquals( 36, Task2.sumCubes( 0, 3)); } @Test public void task2_sumCubes_02 (){ assertEquals( 36, Task2.sumCubes( 1, 3)); } @Test public void task2_sumCubes_03 (){ assertEquals( 224, Task2.sumCubes( 2, 5)); } @Test public void task2_sumCubes_04 (){ assertEquals( 2925, Task2.sumCubes( 5, 10)); } @Test public void task2_sumCubes_05 (){ assertEquals( 855, Task2.sumCubes( 7, 8)); } @Test public void task2_sumCubes_06 (){ assertEquals( 64, Task2.sumCubes( 4, 4)); } @Test public void task2_sumCubes_07 (){ assertEquals( 1000, Task2.sumCubes( 10, 10)); } @Test public void task2_sumCubes_08 (){ assertEquals( 0, Task2.sumCubes( 10, 9)); } @Test public void task2_sumCubes_09 (){ assertEquals( 0, Task2.sumCubes(100, 1)); } @Test public void task2_sumCubes_10 (){ assertEquals( 2121155136, Task2.sumCubes( 1, 303)); }
}
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