Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/** * This Java program inlcudes several errors. One error will keep it from compiling. * The remaining errors will throw exceptions and/or prevent correct

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

/** * 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. * * (c) 2020 Terri Davis */ 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

System.out.printf("This Onion is %d characters long. Here are the individual characters:%n",myStuff[x].getLength( ));

for(int a=0; a 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. IS 2041 Spring 2020 2020 Terri Davis p. 1 of 1 Lab 06 Expected Output Con 3D 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 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 t th Index 30 Index 31 Index 32 Index 33 Index 34 Index 35 Index 36 Index 37 Index 38 Index 39 Index 40 ... Dort 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 CO DO EOI OPPD The Onion at subscript 2: My name is This Onion is 11 characters long. Here are the individual characters: ID rt X Index 30 Index 31 Index 32 Index 33 Index 34 Index 35 Index 36 Index 37 Index 38 Index 39 Index 40 3D 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 UHHO- IO 3 OLOXOS. The Onion at subscript 2: My name is This Onion is 11 characters long. Here are the individual characters: Is 2041 Spring 2020 p. 2 of 5 Lab 06 2020, Terri Davis 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 200,00 HDD

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

More Books

Students also viewed these Databases questions