Need help with these questions. Functions defined outside such as BigInteger class, StringBuilder class, methods from Math
Fantastic news! We've Found the answer you've been seeking!
Question:
Need help with these questions. Functions defined outside such as BigIntegerclass,StringBuilderclass, methods fromMathclass (used as Math.(),such asMath.max(), Math.min(), Math.abs() ...) orIntegerclass (used as Integer.(), such asInteger.parseInt()) or Character class (used asCharacter.(), such as Character.isDigit() can't be used. Cheers
Q1.
Transcribed Image Text:
16 17 18 19 20 public static int score = 0; 21 22 23 24 250 26 27 28 29 30 31 32 } 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 } 50 510 52 53 54 55 56 57 58 59 600 61 62 63 64 65 66 67 68 69 } 1 2 package practicePackage._03_classesObjects.testsAttempts; 3+ import java.util.ArrayList; public class CarTripTest { public CarTrip tripl, trip2, trip3, trip4; public static String result = ''; public static String currentMethodName = null; ArrayList<String> methods Passed = new ArrayList<String>(); @BeforeEach public void run() { trip1 = new CarTrip (5, 4); trip2 = new CarTrip(6, 4.8); trip3 = new CarTrip(4.8, 2.1); trip4 = new CarTrip (5, 8.2);" currentMethodName = null; @Test @Graded (description = "cartrip", marks = 1) public void testCarTrip() { assertEquals(5, tripl.distance, 0.01); assertEquals(4, tripl.time, 0.01); trip1 = new CarTrip (-2, 5.1); assertEquals(0, tripl.distance, 0.01); assertEquals(5.1, trip1.time, 0.01); trip1 = new CarTrip(1.4, -5.1); assertEquals(1.4, tripl.distance, 0.01); assertEquals(0, trip1.time, 0.01); currentMethodName = new Throwable().getStackTrace()[0].getMethodName(); @Test @Graded (description = "tostring", marks = 1) public void testToString() { } assertEquals("5.0 kms travelled in 4.0 hours", tripl.toString()); assertEquals("6.0 kms travelled in 4.8 hours", trip2.toString()); assertEquals("4.8 kms travelled in 2.1 hours", trip3.toString()); currentMethodName = new Throwable().getStackTrace()[0].getMethodName(); @AfterEach public void logSuccess() throws NoSuchMethodException, SecurityException { if (currentMethodName != null && ! methods Passed.contains(currentMethodName)) { methodsPassed.add(currentMethodName); Method method = getClass().getMethod(currentMethodName); Graded graded = method.getAnnotation (Graded.class); score += graded.marks(); score = Math.min(score, 100); result += graded.description() + " passed. Marks awarded: + graded.marks() + "\n"; 70 } 71 720 73 74 75 76 } 77 78 @After All public static void wrapUp() throws IOException { if (result.length() != 0) { System.out.println("\nmethods passed: + score); result = result.substring(0, result.length() - 1); // remove the last "\n" System.out.println(result); 79 } 80 } 81 16 17 18 19 20 public static int score = 0; 21 22 23 24 250 26 27 28 29 30 31 32 } 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 } 50 510 52 53 54 55 56 57 58 59 600 61 62 63 64 65 66 67 68 69 } 1 2 package practicePackage._03_classesObjects.testsAttempts; 3+ import java.util.ArrayList; public class CarTripTest { public CarTrip tripl, trip2, trip3, trip4; public static String result = ''; public static String currentMethodName = null; ArrayList<String> methods Passed = new ArrayList<String>(); @BeforeEach public void run() { trip1 = new CarTrip (5, 4); trip2 = new CarTrip(6, 4.8); trip3 = new CarTrip(4.8, 2.1); trip4 = new CarTrip (5, 8.2);" currentMethodName = null; @Test @Graded (description = "cartrip", marks = 1) public void testCarTrip() { assertEquals(5, tripl.distance, 0.01); assertEquals(4, tripl.time, 0.01); trip1 = new CarTrip (-2, 5.1); assertEquals(0, tripl.distance, 0.01); assertEquals(5.1, trip1.time, 0.01); trip1 = new CarTrip(1.4, -5.1); assertEquals(1.4, tripl.distance, 0.01); assertEquals(0, trip1.time, 0.01); currentMethodName = new Throwable().getStackTrace()[0].getMethodName(); @Test @Graded (description = "tostring", marks = 1) public void testToString() { } assertEquals("5.0 kms travelled in 4.0 hours", tripl.toString()); assertEquals("6.0 kms travelled in 4.8 hours", trip2.toString()); assertEquals("4.8 kms travelled in 2.1 hours", trip3.toString()); currentMethodName = new Throwable().getStackTrace()[0].getMethodName(); @AfterEach public void logSuccess() throws NoSuchMethodException, SecurityException { if (currentMethodName != null && ! methods Passed.contains(currentMethodName)) { methodsPassed.add(currentMethodName); Method method = getClass().getMethod(currentMethodName); Graded graded = method.getAnnotation (Graded.class); score += graded.marks(); score = Math.min(score, 100); result += graded.description() + " passed. Marks awarded: + graded.marks() + "\n"; 70 } 71 720 73 74 75 76 } 77 78 @After All public static void wrapUp() throws IOException { if (result.length() != 0) { System.out.println("\nmethods passed: + score); result = result.substring(0, result.length() - 1); // remove the last "\n" System.out.println(result); 79 } 80 } 81
Expert Answer:
Answer rating: 100% (QA)
It is required to perform the following tasks Implement a class with a constructor that creates a copy of an array and ensures that two instances do not refer to the same array Design and implement me... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Explain how to apply the rules of Section (61)a to determine taxable items.
-
Ayayai Company prepares its statement of cash flows using the direct method for operating activities. For the year ended December 31, 2024, Ayayai Company reports the following: Sales on account...
-
On January 1, 2019, Chiz Company acquired equipment to be used in its manufacturing operations. The equipment has an estimated useful life of 10 years and an estimated residual value of P50,000. The...
-
During 2016, Jerry is a self-employed therapist, and his net earned income is $160,000 from his practice. Jerry's SEP Plan, a defined contribution plan, states that he will contribute the maximum...
-
Exercises 3150 contain rational equations with variables in denominators. For each equation, a. Write the value or values of the variable that make a denominator zero. These are the restrictions on...
-
What is the purpose of timelines in an investigation?
-
Cost data for Tiwana Manufacturing Company for the month ended May 31, 2014, are as follows: a. Prepare a cost of goods manufactured statement for May 2014. b. Determine the cost of goods sold for...
-
As an International Business Strategist advise on how Porter's Diamond is a useful concept in explaining home and host location strategies in International Business? Your answer should make reference...
-
Foud Limited has the following results. Trading profit (loss) Bank deposit interest accrued Rents receivable Year ended 31.3.2018 9,300 120 2,130 9 months to 31.12.2018 0 0 6,480 360 2,160 11,520...
-
Textotape Inc. (the "Company") is the largest and most technically advanced producer of pressure-sensitive labels and associated products in Texas. Its sales volume in the fiscal year ended December...
-
Provide a recommendation for improvement if Instructions to Assessors on how to assess candidates are not clear and concise such as missing information regarding reasonable adjustment, LLN levels for...
-
Benchmarking in Risk Management: Refer to Chapter 3 in the required text and create your blog entry that demonstrates your understanding of how benchmarking is used to identify risk. Can benchmarking...
-
Accurately reflecting the revised depreciation expense in financial statements is important. Inaccurate financial statements can mislead investors and stakeholders. How might investors react if they...
-
UML is a publicly traded corporation that makes various control devices used in manufacturing mechanical equipment. Joe is the president of UML and Tim is the purchasing agent, both have worked at...
-
A reaction turbine works at 500 r.p.m. under a head of 100 m. The diameter of turbine at inlet is 100 cm and flow area is 0.35 m2. The angles made by absolute and relative velocities at inlet are 15...
-
A non-charmed baryon has strangeness S = 2 and electric charge Q = 0. What are the possible values of its isospin I and of its third component I z ? What is it usually called if I = 1/2?
-
Write a function that normally takes one argument, the address of a string, and prints that string once. However, if a second, type int, argument is provided and is nonzero, the function should print...
-
The Bank of Heather would like to know what would happen if it added a second ATM. Modify the simulation in this chapter so that it has two queues. Assume that a customer will join the first queue if...
-
Write a program that asks the user to enter an hour value and a minute value.The main() function should then pass these two values to a type void function that displays the two values in the format...
-
Mexico has labor laws that specify a daily (rather than hourly) minimum wage. In 2018, the daily minimum wage in Mexico was about 103 pesos per day, and the exchange rate between Mexican pesos and...
-
In 2017, an estimated 7.7 million Mexican-born immigrants were employed in the United States. a. If 60 percent of the Mexican-born immigrants remitted money to family members in Mexico in 2017, and...
-
A mathematical approximation called the rule of 70 tells us how long it will take for something to double in size if it grows at a constant rate. The doubling time is approximately equal to the...
Study smarter with the SolutionInn App