Question: 2 . 7 LAB: Introduction to data structures labs LAB ACTIVITY 2 . 7 . 1 : LAB: Introduction to data structures labs 0 /

2.7 LAB: Introduction to data structures labs
LAB ACTIVITY
2.7.1: LAB: Introduction to data structures labs
0/10
zyLabs allow you to run Java programs from your web browser. Click the Tutorial button near the upper-right corner of the Lab Activity below to see the key features of the zyLab IDE.
Step 1: Produce correct output
Three commented-out lines of code exist in main(). Uncomment the lines and click the Run button. Verify that the program's output is:
2+2=4
Unknown method: printPlus2
Secret string: "abc"
Click the "Submit for grading" button to submit your code to the auto-grader. The auto-grader will run two tests against the submitted code: a "Compare output" test and a "Unit test".
The submission will pass the "Compare output" test because the program's output matches the expected output. Passing the test achieves 1 of the 10 possible points.
The "Unit test" fails because the LabPrinter object created in main() was not used. Steps that follow outline how to use the LabPrinter object to satisfy this lab's requirements and achieve 10/10 points.
Step 2: Inspect the LabPrinter class
Inspect the LabPrinter class implemented in the LabPrinter.java file. Methods print2Plus2() and printSecret() print strings using System.out.println().
Step 3: Implement callMethodNamed()
Remove the three uncommented lines from main(). Then implement the callMethodNamed() method in Main.java to handle three cases:
If methodName is "print2Plus2", call printer's print2Plus2() method.
If methodName is "printSecret", call printer's printSecret() method.
If methodName is anything other than the two strings mentioned above, print "Unknown method: xyz", where xyz is methodName's value.
After implementing callMethodNamed(), click the Run button. Verify that the program's output is, once again:
2+2=4
Unknown method: printPlus2
Secret string: "abc"
Step 4: Submit code for 10/10 points
Once callMethodNamed() is properly implemented, submitting the code should receive 10 out of 10 points. The program's output is exactly the same as the implementation from step 1. But step 3's implementation uses the LabPrinter object and step 1 does not.
Step 5: Understand the difference
The unit test uses a different implementation of LabPrinter than what's shown in LabPrinter.java. Calls to each method are tracked, so the unit test determines whether or not callMethodNamed() was actually implemented according to lab requirements.
Most labs in this book are similar. Program output matters, but how the output is achieved matters more. Methods to implement will commonly require use of an object passed as an argument.
Submit for grading
Coding trail of your work
What is this?
5/20
M
-

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!