Write a code in Java programming You are working in a company, and your new task is creating an encoding algorithm to secure a given data. Given a code, write a method called encode() that takes a String and returns a new String based on the frequency of the characters. All the even-frequency characters should be placed before the odd-frequency characters, and finally, all characters should be sorted in increasing order. Your colleague is sick again, and he cannot finish his task. He gave you an unfinished code like the following: public static String encode(String code) { // MyFunction mf = // TODO return mf.encode(code); } Your job is to complete the implementation of the functional interface MyFunction that encode() method should use to encode the given String code. The MyFunction interface should have the following signature: interface MyFunction {

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 a code in Java programming

You are working in a company, and your new task is creating an encoding algorithm to secure a given data. Given a code, write a method called encode() that takes a String and returns a new String based on the frequency of the characters. 

All the even-frequency characters should be placed before the odd-frequency characters, and finally, all characters should be sorted in increasing order.

Your colleague is sick again, and he cannot finish his task. He gave you an unfinished code like the following:

public static String encode(String code) {

// MyFunction mf = // TODO

return mf.encode(code);

}

Your job is to complete the implementation of the functional interface MyFunction that encode() method should use to encode the given String code.

The MyFunction interface should have the following signature:

interface MyFunction {

String encode(String code);

}

Additionally, your algorithm should handle the following cases:

1. If the input String is null, the encode() method should return null.

2. If the input string is empty or contains only whitespaces, the encode() method should return an empty string.

3. If the input String contains non-alphanumeric characters, the encode() method should ignore them.

Thus, if you complete the above code correctly, you should have an output like the following:

encode("98089911223") returns "11228803999"

encode("333000111") returns "000111333"

encode("001119772") returns "007711129"

encode("") returns ""

encode(null) returns null

encode(" \t\n") returns ""

encode("aBcD-12!") returns "12Bac"

Note that you should not change the method signature of the MyFunction interface or the encode() method.

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Time complexity
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