Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please solve this for state design pattern. (Since the answers need diagrams, please don't type out the diagrams and post pictures of hand-drawn diagrams if

Please solve this for state design pattern. (Since the answers need diagrams, please don't type out the diagrams and post pictures of hand-drawn diagrams if possible.)

A parser is a collection of classes that recognize tokens according to specific rules. CSV is an acronym for comma-separated-values. A CSV parser is a parser that detects each value in a CSV string. For example if the string to be parsed is

ABC,1,456.33,12345,,,,Smith, Jim,c c c

then the parser recognizes the following values:

ABC

1,456.33

12345

Smith, Jim

c c c

Note that this string would yield the same tokens:

ABC,1,456.33,12345,Smith, Jim,c c c

Tokens (values) in the string are delimited by commas, and optionally may be enclosed in a pair of double quotes. You could say there are two types of values in a CSV string: unquoted values and quoted values. The first value is either an unquoted value beginning in the first position, or it is a quoted value because the first character is a double quote. From techniques covered in courses like ACS-1903 and ACS-1904 one could code this parser using various character methods, loops, and if-else statements, but that is not the approach we want to take instead we are interested in designing a parser based on the State design pattern.

a) Construct a state chart diagram for this CSV parser. The parser will be in a certain state depending on characters encountered in the string. When the parser starts, it begins with the following code:

// the variable s contains the string to be parsed

for (int i = 0; i

// process the current character according to the current state

state.processChar(s.charAt(i));

}

b) Given your states in part a) show the corresponding class diagram.

c) Given your classes from part b) illustrate the sequence diagram when the CSV string to be parsed is A,BB

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

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions