Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

* Java Only * This is for CS101 class. If you answer the questions accordingly, I would be glad. Thank you in advance. Introduction As

* Java Only *

This is for CS101 class. If you answer the questions accordingly, I would be glad. Thank you in advance.

Introduction

As programs get longer, managing them becomes increasingly difficult. That's where methods come in handy. In essence, a method is just a named collection of statements. Once declared, a method can be invoked any number of times. This lab will give you practice creating and using (static) methods.

image text in transcribed

Documenting your code

image text in transcribed

You can do this assignment in a single project within your lab06 workspace.

Design, implement and test the following simple methods, all of which can be in the same class as your main method

- write a method reverse that takes a String parameter, s, and returns a String that is the reverse of s. For example, if s is "abcd", the method should return "dcba".

Demonstrate your methods by doing the following:

- read a line of text from the user and output it again, but with each word reversed. For instance, were the user to enter "gnimmargorP si nuf", your program should output "Programming is fun".

The basic syntax for defining a (static) method is: accessModifier static returnType methodName( formalParameterList) gtatement where access.Modifier is either "public" "protected", "" (default), or "private" returnTipe is ary Java type or "void" if there is no return, methodName is the name given to the method, and formalParameterList is an optional list of ope name pairs, separated by commas Methods are defined inside a class (but not inside another method) Methods are invoked by name. If the method is in a different class/package, the full path to the method must be provided, e.g. apackage.asubpackage.aclass.methodNamel actualParameterList) When a method is invoked, values are passed to it via an actualParameterList, which is matched one-by-one in sequence to the formalParameterList. Use a return statement to specify the result of the method ("void" methods must not include return)

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

Question

=+How should it be delivered?

Answered: 1 week ago