Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java How to fix the output? How to get the right length of the String? Code: import java.util.Arrays; public class PeelOnion { public static void

Java

How to fix the output? How to get the right length of the String?

Code:

import java.util.Arrays;

public class PeelOnion { public static void main(String[] args) throws Exception{ Onion[] myStuff = new Onion[5]; myStuff[0] = new Onion( "There should be some sort of text here..." ); myStuff[1] = new Onion( "Hello! How are you?" ); myStuff[2] = new Onion( "My name is " ); myStuff[3] = new Onion( ); myStuff[4] = new Onion( "It's a lovely day in the neighborhood." );

for( int h = 0; h

}

}

UML from the class Onion.java:

image text in transcribedExpected Output:

image text in transcribedThank You

Onion Attributes private onion: String Contains a reference to a String object Operations public Onion() nicn Null constructor; creates a default String object reference for onion public Onion( layer: String ): Onion Accepts a String object reference; assigns to instance variable onion 8 public getlength( ): int Returns an integer representing the length of the String object referenced by instance variable onion Notes Standard naming is used for set and get methods General coding standard apply Expected Output from PeelOnion.java There should be some sort of text here... The String at subscript 0 is 41 characters long. Hello! How are you? The String at subscript 1 is 19 characters long. My name is The String at subscript 2 is 11 characters long This is a default message layer. The String at subscript 3 is 32 characters long. It's a lovely day in the neighborhood The String at subscript 4 is 38 characters long

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

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

More Books

Students also viewed these Databases questions

Question

Address an envelope properly.

Answered: 1 week ago

Question

Discuss guidelines for ethical business communication.

Answered: 1 week ago