Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do you complete this java code? Instructions: UML Diagram: Expected Output: Lab 06 Debugging Errors in Others' Code General Information This is a different

How do you complete this java code?

Instructions:

image text in transcribed

UML Diagram:

image text in transcribedExpected Output:

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Lab 06 Debugging Errors in Others' Code General Information This is a different sort of lab. You have the executable code for a class, Onion, and code to process a group of objects of that class, PeelOnion. The process code includes several errors. Your task is to find and correct all of those errors. Background I recommend that you read Chapter 11.7 again (perhaps twice more) before attempting this lab. As you by now have experienced, debugging code is a large part of programming. This exercise will give you some experience tracing a few common issues. In fact, you have almost definitely seen every one of the included issues in your own, or someone else's, code. Provided: These instructions The Expected Output from a correctly functioning PeelOnion.java UML describing the class Onion Onion.class-the executable code for class Onion (you will not need the source code) PeelOnion.java - this is the process code that you will fix' Task: Correct PeelOnion.java so that it produces the expected Results Deliverable: Your corrected version of PeelOnion.java Requirements The provided source code has no comments beyond the block comment discussing the lab assignment. There is very, very little whitespace included. You may find the code difficult to read in this format. Please feel free to add comments and white space to make the code more readable. If you choose not to do so, there will be no point deduction The first error will keep the code from compiling. Once you have corrected that error, others will appear in sequence. Some errors may be due to typos in the code; some may be due to logic errors in the code. It is also entirely possible to introduce additional (unplanned) errors while you are trying to debug the program. Testing After fully debugging the program, your results should exactly match those provided. Submitting Your Work Submit your corrected version of PeelOnion.java (source ONLY!) in a zipped folder. Grading A precise grading rubric would point you to the errors in the code, so there is none provided here. HOWEVER, code that does not, at a minimum, compile and execute without error, warning, or exception will earn a grade of zero (O). You will earn points for each (original) code issue solved, provided your solution compiles cleanly and executes without throwing any exception. Onion Attributes private onion: String Notes Contains a reference to a String object Operations public Onion(): Onion Description A null constructor, accepting no arguments, and returning a reference to an Onion object containing nuetral default values for its instance values. A full constructor, accepting appropriately typed values as arguments, and returning a reference to an Onion object with appropriately set instance values. public Onion( layers: String ): Onion public getOnionLength(): int Returns the length of the String object referenced by the onion instance variable Lab 06 Expected Output The Onion at subscript 6: There should be some sort of text here... This Onion is 41 characters long. Here are the individual characters: Index o Index 1 Index 2 Index 3 Index 4 Index 5 Index 6 Index 7 Index 8 Index 9 Index 10 Index 11 Index 12 Index 13 Index 14 Index 15 Index 16 Index 17 Index 18 Index 19 Index 20 Index 21 Index 22 Index 23 Index 24 Index 25 Index 26 Index 27 Index 28 Index 29 Index 30 Index 31 Index 32 Index 33 Index 34 Index 35 Index 36 Index 37 Index 38 Index 39 Index 40 The Onion at subscript 1: Hello! How are you? This Onion is 19 characters long. Here are the individual characters: Index o Index 1 Index 2 Index 3 Index 4 Index 5 Index 6 Index 7 Index 8 Index 9 Index 10 Index 11 Index 12 Index 13 Index 14 Index 15 Index 16 Index 17 Index 18 UCO DO EOI - OPPOI The Onion at subscript 2: My name is This Onion is 11 characters long. Here are the individual characters: Index o Index 1 Index 2 Index 3 Index 4 Index 5 Index 6 Index 7 Index 8 Index 9 Index 10 The Onion at subscript 3: This is a default message layer. This Onion is 32 characters long. Here are the individual characters: Index 0 Index 1 Index 2 Index 3 Index 4 Index 5 Index 6 Index 7 Index 8 Index 9 Index 10 Index 11 Index 12 Index 13 Index 14 Index 15 Index 16 Index 17 Index 18 Index 19 Index 20 Index 21 Index 22 Index 23 Index 24 Index 25 Index 26 Index 27 Index 28 Index 29 Index 30 Index 31 300 000 The Onion at subscript 4: It's a lovely day in the neighborhood. This Onion is 38 characters long. Here are the individual characters: Index o Index 1 Index 2 Index 3 Index 4 Index 5 Index 6 Index 7 Index 8 Index 9 Index 10 Index 11 Index 12 Index 13 Index 14 Index 15 Index 16 Index 17 Index 18 Index 19 Index 20 Index 21 Index 22 Index 23 Index 24 Index 25 Index 26 Index 27 Index 28 Index 29 Index 30 Index 31 Index 32 Index 33 Index 34 Index 35 Index 36 Index 37 Lab 06 Debugging Errors in Others' Code General Information This is a different sort of lab. You have the executable code for a class, Onion, and code to process a group of objects of that class, PeelOnion. The process code includes several errors. Your task is to find and correct all of those errors. Background I recommend that you read Chapter 11.7 again (perhaps twice more) before attempting this lab. As you by now have experienced, debugging code is a large part of programming. This exercise will give you some experience tracing a few common issues. In fact, you have almost definitely seen every one of the included issues in your own, or someone else's, code. Provided: These instructions The Expected Output from a correctly functioning PeelOnion.java UML describing the class Onion Onion.class-the executable code for class Onion (you will not need the source code) PeelOnion.java - this is the process code that you will fix' Task: Correct PeelOnion.java so that it produces the expected Results Deliverable: Your corrected version of PeelOnion.java Requirements The provided source code has no comments beyond the block comment discussing the lab assignment. There is very, very little whitespace included. You may find the code difficult to read in this format. Please feel free to add comments and white space to make the code more readable. If you choose not to do so, there will be no point deduction The first error will keep the code from compiling. Once you have corrected that error, others will appear in sequence. Some errors may be due to typos in the code; some may be due to logic errors in the code. It is also entirely possible to introduce additional (unplanned) errors while you are trying to debug the program. Testing After fully debugging the program, your results should exactly match those provided. Submitting Your Work Submit your corrected version of PeelOnion.java (source ONLY!) in a zipped folder. Grading A precise grading rubric would point you to the errors in the code, so there is none provided here. HOWEVER, code that does not, at a minimum, compile and execute without error, warning, or exception will earn a grade of zero (O). You will earn points for each (original) code issue solved, provided your solution compiles cleanly and executes without throwing any exception. Onion Attributes private onion: String Notes Contains a reference to a String object Operations public Onion(): Onion Description A null constructor, accepting no arguments, and returning a reference to an Onion object containing nuetral default values for its instance values. A full constructor, accepting appropriately typed values as arguments, and returning a reference to an Onion object with appropriately set instance values. public Onion( layers: String ): Onion public getOnionLength(): int Returns the length of the String object referenced by the onion instance variable Lab 06 Expected Output The Onion at subscript 6: There should be some sort of text here... This Onion is 41 characters long. Here are the individual characters: Index o Index 1 Index 2 Index 3 Index 4 Index 5 Index 6 Index 7 Index 8 Index 9 Index 10 Index 11 Index 12 Index 13 Index 14 Index 15 Index 16 Index 17 Index 18 Index 19 Index 20 Index 21 Index 22 Index 23 Index 24 Index 25 Index 26 Index 27 Index 28 Index 29 Index 30 Index 31 Index 32 Index 33 Index 34 Index 35 Index 36 Index 37 Index 38 Index 39 Index 40 The Onion at subscript 1: Hello! How are you? This Onion is 19 characters long. Here are the individual characters: Index o Index 1 Index 2 Index 3 Index 4 Index 5 Index 6 Index 7 Index 8 Index 9 Index 10 Index 11 Index 12 Index 13 Index 14 Index 15 Index 16 Index 17 Index 18 UCO DO EOI - OPPOI The Onion at subscript 2: My name is This Onion is 11 characters long. Here are the individual characters: Index o Index 1 Index 2 Index 3 Index 4 Index 5 Index 6 Index 7 Index 8 Index 9 Index 10 The Onion at subscript 3: This is a default message layer. This Onion is 32 characters long. Here are the individual characters: Index 0 Index 1 Index 2 Index 3 Index 4 Index 5 Index 6 Index 7 Index 8 Index 9 Index 10 Index 11 Index 12 Index 13 Index 14 Index 15 Index 16 Index 17 Index 18 Index 19 Index 20 Index 21 Index 22 Index 23 Index 24 Index 25 Index 26 Index 27 Index 28 Index 29 Index 30 Index 31 300 000 The Onion at subscript 4: It's a lovely day in the neighborhood. This Onion is 38 characters long. Here are the individual characters: Index o Index 1 Index 2 Index 3 Index 4 Index 5 Index 6 Index 7 Index 8 Index 9 Index 10 Index 11 Index 12 Index 13 Index 14 Index 15 Index 16 Index 17 Index 18 Index 19 Index 20 Index 21 Index 22 Index 23 Index 24 Index 25 Index 26 Index 27 Index 28 Index 29 Index 30 Index 31 Index 32 Index 33 Index 34 Index 35 Index 36 Index 37

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions

Question

Dividend Yield for delta airlines on excel

Answered: 1 week ago