Write the following programs in Java: In the Converter class write the static method, bin2decimal(String bin). The parameter for this method is an unsigned (nonnegative) binary number represented by a string. The method returns the decimal equivalent for the binary parameter, as an integer. If the binary string is invalid (contains characters other than ‘0’ and ‘1’), the method returns -1. Convert from a binary (b) string with up to 16 digits to decimal (d) using the following formula: ? = ?0 + ?1 × 2 + ?2 × 22 +⋯+ ?7 × 215 where b0, b1, ?2, … ?7 are the binary digits in order of increasing significance. For example, 1101 is: 1 + 0×2 + 1×22 + 1×23 = 13 in decimal. Side note: You may NOT use the decode method of the Long wrapper class instead of this formula.   In the Converter class write another static method, english2encrypted(String english). The parameter for this method is a word or sentence represented by a string. The word or sentence should only contain letters (no digits, punctuation, or other special characters); however, it may contain both upper- and lower-case letters. If you want to include a number you must write out the word that represents the number (ie: 8 must be written out as “eight”). The method returns the encrypted equivalent for the English word or sentence parameter, as a string. If the String parameter contains any invalid characters (i.e. characters other than letters or spaces) then these characters will be skipped and not included in the return String (note: the words must not contain any invalid characters when applying the encryption rules below). The rules for encrypting the English words are as follows: • The encrypted words will all be in upper-case letters. • If a word has 2 or more letters, switch the first and last letter. • Replace all E’s in the English words with 3’s • Replace A’s in the English words with V’s, and replace V’s with A’s. • Replace all O’s with Q’s, and replace Q’s with O’s. • Replace all B’s with 8’s • Replace all Y’s with I’s, and replace I’s with Y’s. Examples: “Developer” becomes “R3A3LQP3D” “Dave and Jeni in a group” becomes “3VAD DNV Y3NJ NY V PRQUG” "I’m not sure!" becomes "MY TQN 3URS"

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write the following programs in Java:

In the Converter class write the static method, bin2decimal(String bin). The parameter for this method is an unsigned (nonnegative) binary number represented by a string. The method returns the decimal equivalent for the binary parameter, as an integer.
If the binary string is invalid (contains characters other than ‘0’ and ‘1’), the method returns -1. Convert from a binary (b) string with up to 16 digits to decimal (d) using the following formula:
? = ?0 + ?1 × 2 + ?2 × 22 +⋯+ ?7 × 215
where b0, b1, ?2, … ?7 are the binary digits in order of increasing significance. For example, 1101 is: 1 + 0×2 + 1×22 + 1×23 = 13 in decimal. Side note: You may NOT use the decode method of the Long wrapper class instead of this formula.

 

In the Converter class write another static method, english2encrypted(String english). The parameter for this method is a word or sentence represented by a string. The word or sentence should only contain letters (no digits, punctuation, or other special characters); however, it may contain both upper- and lower-case letters. If you want to include a number you must write out the word that represents the number (ie: 8 must be written out as “eight”). The method returns the encrypted equivalent for the English word or sentence parameter, as a string.

If the String parameter contains any invalid characters (i.e. characters other than letters or spaces) then these characters will be skipped and not included in the return String (note: the words must not contain any invalid characters when applying the encryption rules below).

The rules for encrypting the English words are as follows:

• The encrypted words will all be in upper-case letters.

• If a word has 2 or more letters, switch the first and last letter.

• Replace all E’s in the English words with 3’s

• Replace A’s in the English words with V’s, and replace V’s with A’s.

• Replace all O’s with Q’s, and replace Q’s with O’s.

• Replace all B’s with 8’s

• Replace all Y’s with I’s, and replace I’s with Y’s.

Examples:

“Developer” becomes “R3A3LQP3D”

“Dave and Jeni in a group” becomes “3VAD DNV Y3NJ NY V PRQUG”

"I’m not sure!" becomes "MY TQN 3URS"

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education