Question
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.
Documenting your code
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started