Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

CODE GIVEN: 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

image text in transcribed

CODE GIVEN:

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

CODE FROM ONION CLASS:

4 ' ! " # $ onion Ljava/lang/String; ()V Code LineNumberTable LocalVariableTable this LOnion; (Ljava/lang/String;)V layer setOnion getOnion ()Ljava/lang/String; getLength ()I toString SourceFile Onion.java This is a default message layer. Sorry, I'm not gonna say! % & Onion java/lang/Object java/lang/String length 1 = * * F * *+ ? * - 2 * $ / * )

EXPECTED OUTPUT:

image text in transcribed

image text in transcribed

image text in transcribed

image 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 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 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 XD Index 30 Index 31 Index 32 Index 33 Index 34 Index 35 Index 36 Index 37 Index 38 Index 39 Index 40 ... DSD 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 IHO - IO 3 OSO OS n. 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 3DEO 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 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 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 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 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 XD Index 30 Index 31 Index 32 Index 33 Index 34 Index 35 Index 36 Index 37 Index 38 Index 39 Index 40 ... DSD 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 IHO - IO 3 OSO OS n. 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 3DEO 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 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

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