Question: 2 . 7 LAB: Introduction to data structures labs LAB ACTIVITY 2 . 7 . 1 : LAB: Introduction to data structures labs 0 /
LAB: Introduction to data structures labs
LAB ACTIVITY
: LAB: Introduction to data structures labs
zyLabs allow you to run Java programs from your web browser. Click the Tutorial button near the upperright corner of the Lab Activity below to see the key features of the zyLab IDE.
Step : Produce correct output
Three commentedout lines of code exist in main Uncomment the lines and click the Run button. Verify that the program's output is:
Unknown method: printPlus
Secret string: "abc"
Click the "Submit for grading" button to submit your code to the autograder. The autograder 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 of the 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 points.
Step : Inspect the LabPrinter class
Inspect the LabPrinter class implemented in the LabPrinter.java file. Methods printPlus and printSecret print strings using System.out.println
Step : Implement callMethodNamed
Remove the three uncommented lines from main Then implement the callMethodNamed method in Main.java to handle three cases:
If methodName is "printPlus call printer's printPlus 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:
Unknown method: printPlus
Secret string: "abc"
Step : Submit code for points
Once callMethodNamed is properly implemented, submitting the code should receive out of points. The program's output is exactly the same as the implementation from step But step s implementation uses the LabPrinter object and step does not.
Step : 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?
M
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
