

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A java practice quiz for a university or high school course. It includes a set of unit tests for various methods, as well as instructions to complete the implementation of a tax calculation method. The quiz also includes a question about the number of times 'hello' is printed in different loops and a request to write a new method for counting the occurrences of a specific integer in a given input string.
Typology: Quizzes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


@Test public void testExpressions() { int j = 5; int k = 3; double x = -1.5; String s = "U of Arizona"; assertEquals(2, j / k); // a. ______ assertEquals(1, j % k); // b. ______ assertEquals(-0.5, x + 1, 1e-12); // c. ______ assertEquals('U', s.charAt(1)); // d. ______ assertEquals(5, s.indexOf("Arizona")); // e. ______ assertEquals(0, s.indexOf("U of A")); // f. ______ assertTrue(s.compareTo("ASU") > 0); // g. ______ assertEquals(2.0, Math.sqrt(j), 1e-12); // h. ______ } }
Income $0 to $10,000 3% of income $10,000 to $20,000 $300, plus 4% of the amount over $10, $20,000 to $30,000 $700, plus 5% of the amount over $20, $30,000 and over $1,200, plus 6% of the amount over $30, @Test public void testGrade() { assertEquals(__________, tax(____________), 1e-12); assertEquals(__________, tax(____________), 1e-12); assertEquals(__________, tax(____________), 1e-12); assertEquals(__________, tax(____________), 1e-12); assertEquals(__________, tax(____________), 1e-12); } // Complete this method here public double tax(int income)
@Test public void testOccurences() { Scanner scanner = new Scanner("1 2 3 4 1 2 3 1 6"); assertEquals(3, occurencesOf(1, scanner)); assertEquals(1, occurencesOf(6, scanner)); assertEquals(0, occurencesOf(99, scanner)); }