Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with these questions. Functions defined outside such as BigInteger class, StringBuilder class, methods from Math class (used as Math.(), such as Math.max(), Math.min(),

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.

imageimage

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 methods Passed = new ArrayList (); @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() + " "; 70 } 71 720 73 74 75 76 } 77 78 @After All public static void wrapUp() throws IOException { if (result.length() != 0) { System.out.println(" methods passed: + score); result = result.substring(0, result.length() - 1); // remove the last " " System.out.println(result); 79 } 80 } 81

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Primer Plus

Authors: Stephen Prata

6th Edition

978-0321776402, 0321776402

More Books

Students also viewed these Programming questions

Question

What is a smart grid?

Answered: 1 week ago