Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 with the signature "public static int toDecimal( String base2)" that converts the given base2 String to its decimal --base10-- equivalent, as an int. For example, if base2 is "110", it should return 6, whereas if it was "1011", it should return 11. You should be able to do this without using Math class methods, and without computing the power of the most significant digit.

- write a method that converts a positive decimal int value into the corresponding binary String.

- 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 two binary (base-2) Strings from the user, convert them to decimal, then add them together and print the result in binary form.

- 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".

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