Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help. Need this coded per instructions in JAVA. Source Code: /** * This Java program inlcudes several errors. One error will keep it from

Please help. Need this coded per instructions in JAVA.

image text in transcribedimage text in transcribedSource Code:

/** * This Java program inlcudes several errors. One error will keep it from compiling. * The remaining errors will throw exceptions and/or prevent correct output. * * Some errors could be the result of bad typing; some errors are the results of bad logic. * There are NO COMMENTS in this code, and not a lot of whitespace. * * Fix all the errors to produce the output shown in the lab instructions. * Submit your completed and CORRECT version of PeelOnion. * */ public class PeelOnion{ public static void main(String[] args){Onion[] myStuff = {new Onion("There should be some sort of text here..."),new Onion("Hello! How are you?"),new Onion("My name is "),new Onion(),new Onion("It's a lovely day in the neighborhood.")}; for(int x=0; x 

Expected output:

image text in transcribedimage text in transcribed

image text in transcribedimage text in transcribedimage text in transcribed

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. Attributes private onion: String Onion 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 Son DSD- 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 3 on Do +son + + Index 30 Index 31 Index 32 Index 33 Index 34 Index 35 Index 36 Index 37 Index 38 Index 39 Index 40 DJ t XD ... 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 IO HO - IO 3 OSO OS. The Onion at subscript 2: My name is This Onion is 11 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 The Onion at subscript 3: This is a default message layer. This Onion is 32 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 DO DO 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 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 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. Attributes private onion: String Onion 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 Son DSD- 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 3 on Do +son + + Index 30 Index 31 Index 32 Index 33 Index 34 Index 35 Index 36 Index 37 Index 38 Index 39 Index 40 DJ t XD ... 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 IO HO - IO 3 OSO OS. The Onion at subscript 2: My name is This Onion is 11 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 The Onion at subscript 3: This is a default message layer. This Onion is 32 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 DO DO 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 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 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

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions

Question

Make efficient use of your practice time?

Answered: 1 week ago