JAVA(use code provided) This code currently takes the tokens in a string and puts it into an array list. For example "6 + 7 -84.2" ===> 6, +, 7, -, 84.2

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Question
Computer science
JAVA(use code provided)
This code currently takes the tokens in a string and puts it into an array list. For
example "6 +7 -84.2" ===> 6, +, 7, -, 84.2
For example " - +*" - -+,*
For example "5" - 5
For example 67 + 12/45/7%0 ===> 67, +, 12, /, 45, /, 7, %, 0
Please make it so that it returns null when the string expression is
invalid/mathematically does not make sense.
For example "1x + 5 + 10" - null
For example ".9 +.7 - 2" null
ONLY USE BASIC IF STATEMENTS FOR THIS. NO JAVA FUNCTIONS LIKE
isletter() or isdigit(). NO STRINGBUILDER as well. NO LIBRARIES AS WELL.
ONLY IF STATEMENTS. KEEP IT BASIC PLEASE. Remember that it needs to take
out individual tokens in a string, and put them into the arraylist as well like was
done in my code. ===> NULL ===> NULL 53 ===> 536+7-84.2 ===> 6+7-
84.2 - +* ===> - + *
89x + 4 ===>
NULL
.9 +7. - 2 ===> NULL
import java.util.ArrayList;
import java.util.List;
public class Math (
static public List tokenizer(String exprn) {
List tokens = new ArrayList();
String currentToken = "";
for (int i = 0; i< exprn.length(); i++){
char c = exprn.charAt(i);
if (c == '') {
if (currentToken.length() > 0) {
tokens.add(currentToken);
currentToken = "";
else if (c == " || (c >= '0' && c <= '9')) {
currentToken += c;
else {
if (currentToken.length() > 0) {
tokens.add(currentToken);
currentToken = "" + c;
tokens.add(currentToken);
currentToken = "";
}
if (currentToken.length() > 0) {
tokens.add(currentToken);
return tokens;
Transcribed Image Text:JAVA(use code provided) This code currently takes the tokens in a string and puts it into an array list. For example "6 +7 -84.2" ===> 6, +, 7, -, 84.2 For example " - +*" - -+,* For example "5" - 5 For example 67 + 12/45/7%0 ===> 67, +, 12, /, 45, /, 7, %, 0 Please make it so that it returns null when the string expression is invalid/mathematically does not make sense. For example "1x + 5 + 10" - null For example ".9 +.7 - 2" null ONLY USE BASIC IF STATEMENTS FOR THIS. NO JAVA FUNCTIONS LIKE isletter() or isdigit(). NO STRINGBUILDER as well. NO LIBRARIES AS WELL. ONLY IF STATEMENTS. KEEP IT BASIC PLEASE. Remember that it needs to take out individual tokens in a string, and put them into the arraylist as well like was done in my code. ===> NULL ===> NULL 53 ===> 536+7-84.2 ===> 6+7- 84.2 - +* ===> - + * 89x + 4 ===> NULL .9 +7. - 2 ===> NULL import java.util.ArrayList; import java.util.List; public class Math ( static public List tokenizer(String exprn) { List tokens = new ArrayList(); String currentToken = ""; for (int i = 0; i< exprn.length(); i++){ char c = exprn.charAt(i); if (c == '') { if (currentToken.length() > 0) { tokens.add(currentToken); currentToken = ""; else if (c == " || (c >= '0' && c <= '9')) { currentToken += c; else { if (currentToken.length() > 0) { tokens.add(currentToken); currentToken = "" + c; tokens.add(currentToken); currentToken = ""; } if (currentToken.length() > 0) { tokens.add(currentToken); return tokens;
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY