SlideShare a Scribd company logo
ISM3230 In-class lab Module 3 – Working with Strings and
String Methods Spring 2021
TASK
You are working for a farm corporation that serves as a major
supplier of lettuce to the US and
international markets. The corporation owns a large number of
fields spread across a large number of
farm locations in the lettuce-growing region.
You are helping to build a system tracking the origin of lettuce
back to the field where it was grown
across the many farm locations and fields where the corporation
grows lettuce. This system will not only
help with planning and forecasting, but will also allow for
tracking food-borne illness for public health
purposes. Your task involves transformi ng data about each head
of lettuce into an intermediary code
that is later sent into a bar code generator, to be included on the
packaging. The inputs to your program
will eventually be supplied by other systems, but for testing
purposes you will let the user enter the data
from the keyboard.
There are three input strings. These strings come in formats
produced by other systems; these formats
cannot be changed. The input strings and their formats are as
follows:
• The variety of lettuce. This could be any word or sequence of
words. Variety names are
guaranteed to be at least 4 letters long. Variety examples are:
“romaine”, “RUBY Loose Leaf”,
“Cimmaron”, “BIBB”, “Tom Thumb”, etc.
• The location ID within the corporation. This ID consists of a
number that represents the farm ID,
followed by the word “id” in any case, followed by a number
that represents the field ID. For
example, “54id4”, “9083ID451”, “8Id30” are three examples of
location IDs.
• The harvest date of the lettuce. This comes in a format of
day/month, where day is a number
between 0 and 31 and month is a full name of the month in any
capitalization (February, July,
etc.) Examples of production dates are: “1/February”,
“15/MARCH”, “31/december”. The two
parts of the date string are separated by a ‘/’ character. There
are no spaces allowed in the
production date string. Note that the day may be one or two
characters long and the month can
have any capitalization.
The output of the program is a string code that can later be used
to generate a bar code for the
packaging. It consists of some parts of each of the inputs. The
code has the following format:
VVV-Mm-fieldID-farmID
• VVV holds the first three letters of the variety in uppercase
• Mm encodes the first and last letters of the month, with the
first letter in uppercase and the last
letter in lowercase
• fieldID that is the second set of digits in the location ID
• farmID that is the first set of digits in the location ID
• all subparts of the code are separated with a hyphen (minus
sign) "-"
As input, let the user enter strings for the variety, location ID,
and harvest date, assuming the formatting
described above.
As output, print the formatted barcode sequence.
1. Create a new NetBeans project called yourname_Lab3.
2. Prompt user to enter the variety. Use Scanner's method
nextLine() to read the variety into a
String variable. You must read the variety into one variable
even if it contains multiple words.
o Do not use next() method.
3. Prompt user to enter the location ID. Use Scanner’s method
nextLine() to read the whole
location code string into a single String variable.
o Do not simplify this lab by taking separate user inputs for
farmID and fieldID.
4. Prompt user to enter harvest date. Use Scanner's method
nextLine() to read the whole date
string into a single String variable.
o Do not simplify this lab by taking separate user inputs for
date and month.
5. Checkpoint 1: Print out all the user input variabl es. Make
sure that you have 3 variables that
hold the data, and that they are appropriately named. They are
all String types. For example:
6. Create the pieces of the bar code by extracting various
elements of data from the inputs and
storing them in appropriately-typed variables. Store individual
pieces in separate variables with
names indicating what data they hold.
o A summary of helpful string manipulation methods is
provided below. Your task is to
figure out how to use those methods to achieve the goal set out
in this lab.
o HINT: you may need to use a combination of methods to find
and extract each of the
barcode data elements required in this lab.
7. Checkpoints: You should work on each part separately and
print out the part of the code to the
screen. You may find it useful to print out even subparts of the
individual code parts. For
example, when finding the first and last letters of the month,
one approach is to extract the
whole month into a separate variable. Printing the position of
the slash and then printing the
month string would be a good idea to check that it is correctly
extracted:
Another example is the variety code. Print it out when you
obtain the 3 letters and again when
you convert them to uppercase:
8. Finally, concatenate together all pieces to form the final
code, and store the final barcode in one
string variable.
9. Print the code to the screen.
10. Make sure that your prompts and output follow the examples
in the sample output, including
wording, spacing, and punctuation.
11. When your code is working, upload your .java file to the
Lab 3 dropbox.
String manipulation methods
Method Return
Type
Description
concat(String str) String Concatenates the specified string to the
end of this string.
indexOf(String str) int Returns the index within this string of
the first occurrence of
the specified substring.
indexOf(String str, int fromIndex) int Returns the index within
this string of the first occurrence of
the specified substring, starting at the specified index.
lastIndexOf(String str) int Returns the index within this string
of the last occurrence of
the specified substring.
length() int Returns the length of this string.
substring(int beginIndex) String Returns a new string that is a
substring of this string. The
substring begins with the character at the specified index
and extends to the end of this string.
substring(int beginIndex, int endIndex) String Returns a new
string that is a substring of this string. The
substring begins at the specified beginIndex and extends to
the character at index endIndex - 1.
toUpperCase() String Converts all of the characters in this
String to upper case.
toLowerCase() String Converts all of the characters in this
String to lower case.
SAMPLE OUTPUT

More Related Content

PPTX
Normalization
PPTX
L4 advanced spreadsheet skills
PPTX
Sumif () ppt
PPTX
Ma3696 Lecture 1
DOCX
Normalization
PDF
Cte handout for ict2
PPTX
Reusable Test Matrices Presentaion
PPTX
EMPOWERMENT TECHNOLOGIES - LESSON 4
Normalization
L4 advanced spreadsheet skills
Sumif () ppt
Ma3696 Lecture 1
Normalization
Cte handout for ict2
Reusable Test Matrices Presentaion
EMPOWERMENT TECHNOLOGIES - LESSON 4

Similar to Ism3230 in class lab module 3 – working with strings and strin (20)

PPT
Symbol Table, Error Handler & Code Generation
PPTX
Chapter 2.datatypes and operators
PDF
C Programming Assignment
PDF
Comparison of analyzers' diagnostic possibilities at checking 64-bit code
PPTX
The Application of Barcode in library...
PPTX
Data Type in C Programming
PDF
20 issues of porting C++ code on the 64-bit platform
PDF
20 issues of porting C++ code on the 64-bit platform
PDF
Program errors occurring while porting C++ code from 32-bit platforms on 64-b...
PPS
Excel tips advance
PPS
Excel tips advance
PPS
Advance Excel tips
PPS
Excel tips advance
PPS
Excel tips advance
PPT
Ppt chapter03
PPT
Ppt chapter03
PPT
C language Unit 2 Slides, UPTU C language
PPTX
Lec 02 Introduction to C Programming.pptx
PDF
The static code analysis rules for diagnosing potentially unsafe construction...
PPT
Escape Sequences and Variables
Symbol Table, Error Handler & Code Generation
Chapter 2.datatypes and operators
C Programming Assignment
Comparison of analyzers' diagnostic possibilities at checking 64-bit code
The Application of Barcode in library...
Data Type in C Programming
20 issues of porting C++ code on the 64-bit platform
20 issues of porting C++ code on the 64-bit platform
Program errors occurring while porting C++ code from 32-bit platforms on 64-b...
Excel tips advance
Excel tips advance
Advance Excel tips
Excel tips advance
Excel tips advance
Ppt chapter03
Ppt chapter03
C language Unit 2 Slides, UPTU C language
Lec 02 Introduction to C Programming.pptx
The static code analysis rules for diagnosing potentially unsafe construction...
Escape Sequences and Variables
Ad

More from ssuserd93c47 (20)

DOCX
Macy’s, inc.—2018 david, f. r., david, f. r., & david, m. e. (
DOCX
Level 2—permission level 2 is based entirely on relationships.
DOCX
Lecture 6 hello everyone. welcome back to lh 4430, history of
DOCX
Learning resources required readingsthyer, b. a. (2013).
DOCX
Learning resources required readingsdudley, j. r. (2020).
DOCX
Learning resources note to access this module’s required libra
DOCX
Last name 1 last name 1namemy nameclassdateth
DOCX
June 2013 (122) mis quarterly executive 65 misq uarterl
DOCX
James c. schwab, editor hazard mitigation integrating be
DOCX
Its 531 – business intelligence research project you are team of
DOCX
It for management on demand strategies for performance, growth,
DOCX
Introduction to macroeconomics 1 page 2 of 2 introduction to m
DOCX
Intl esay essaycomplete the midterm exam by composing a 6–8 pg.
DOCX
Interpersonal communication questions1. what is plain speech wh
DOCX
Interdisciplinary care plan7 class nur3400
DOCX
Integrated distributors incorporated scenariointegrated dis
DOCX
Int 220 module six assignment conference call invitation templat
DOCX
Instructions recently, you have noticed a change in the way your
DOCX
Instructions for this unit vi assignment, continue with the indus
DOCX
Instructions be advised, the template workbooks and worksheets are
Macy’s, inc.—2018 david, f. r., david, f. r., & david, m. e. (
Level 2—permission level 2 is based entirely on relationships.
Lecture 6 hello everyone. welcome back to lh 4430, history of
Learning resources required readingsthyer, b. a. (2013).
Learning resources required readingsdudley, j. r. (2020).
Learning resources note to access this module’s required libra
Last name 1 last name 1namemy nameclassdateth
June 2013 (122) mis quarterly executive 65 misq uarterl
James c. schwab, editor hazard mitigation integrating be
Its 531 – business intelligence research project you are team of
It for management on demand strategies for performance, growth,
Introduction to macroeconomics 1 page 2 of 2 introduction to m
Intl esay essaycomplete the midterm exam by composing a 6–8 pg.
Interpersonal communication questions1. what is plain speech wh
Interdisciplinary care plan7 class nur3400
Integrated distributors incorporated scenariointegrated dis
Int 220 module six assignment conference call invitation templat
Instructions recently, you have noticed a change in the way your
Instructions for this unit vi assignment, continue with the indus
Instructions be advised, the template workbooks and worksheets are
Ad

Recently uploaded (20)

PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Unit 4 Skeletal System.ppt.pptxopresentatiom
PDF
Computing-Curriculum for Schools in Ghana
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Lesson notes of climatology university.
PDF
IGGE1 Understanding the Self1234567891011
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
Trump Administration's workforce development strategy
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
RMMM.pdf make it easy to upload and study
PPTX
Cell Types and Its function , kingdom of life
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PPTX
Final Presentation General Medicine 03-08-2024.pptx
Final Presentation General Medicine 03-08-2024.pptx
Unit 4 Skeletal System.ppt.pptxopresentatiom
Computing-Curriculum for Schools in Ghana
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Lesson notes of climatology university.
IGGE1 Understanding the Self1234567891011
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Trump Administration's workforce development strategy
Paper A Mock Exam 9_ Attempt review.pdf.
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
RMMM.pdf make it easy to upload and study
Cell Types and Its function , kingdom of life
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Orientation - ARALprogram of Deped to the Parents.pptx
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
Weekly quiz Compilation Jan -July 25.pdf
Chinmaya Tiranga quiz Grand Finale.pdf
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
Final Presentation General Medicine 03-08-2024.pptx

Ism3230 in class lab module 3 – working with strings and strin

  • 1. ISM3230 In-class lab Module 3 – Working with Strings and String Methods Spring 2021 TASK You are working for a farm corporation that serves as a major supplier of lettuce to the US and international markets. The corporation owns a large number of fields spread across a large number of farm locations in the lettuce-growing region. You are helping to build a system tracking the origin of lettuce back to the field where it was grown across the many farm locations and fields where the corporation grows lettuce. This system will not only help with planning and forecasting, but will also allow for tracking food-borne illness for public health purposes. Your task involves transformi ng data about each head of lettuce into an intermediary code that is later sent into a bar code generator, to be included on the packaging. The inputs to your program will eventually be supplied by other systems, but for testing purposes you will let the user enter the data from the keyboard.
  • 2. There are three input strings. These strings come in formats produced by other systems; these formats cannot be changed. The input strings and their formats are as follows: • The variety of lettuce. This could be any word or sequence of words. Variety names are guaranteed to be at least 4 letters long. Variety examples are: “romaine”, “RUBY Loose Leaf”, “Cimmaron”, “BIBB”, “Tom Thumb”, etc. • The location ID within the corporation. This ID consists of a number that represents the farm ID, followed by the word “id” in any case, followed by a number that represents the field ID. For example, “54id4”, “9083ID451”, “8Id30” are three examples of location IDs. • The harvest date of the lettuce. This comes in a format of day/month, where day is a number between 0 and 31 and month is a full name of the month in any capitalization (February, July, etc.) Examples of production dates are: “1/February”, “15/MARCH”, “31/december”. The two parts of the date string are separated by a ‘/’ character. There
  • 3. are no spaces allowed in the production date string. Note that the day may be one or two characters long and the month can have any capitalization. The output of the program is a string code that can later be used to generate a bar code for the packaging. It consists of some parts of each of the inputs. The code has the following format: VVV-Mm-fieldID-farmID • VVV holds the first three letters of the variety in uppercase • Mm encodes the first and last letters of the month, with the first letter in uppercase and the last letter in lowercase • fieldID that is the second set of digits in the location ID • farmID that is the first set of digits in the location ID • all subparts of the code are separated with a hyphen (minus sign) "-" As input, let the user enter strings for the variety, location ID, and harvest date, assuming the formatting described above.
  • 4. As output, print the formatted barcode sequence. 1. Create a new NetBeans project called yourname_Lab3. 2. Prompt user to enter the variety. Use Scanner's method nextLine() to read the variety into a String variable. You must read the variety into one variable even if it contains multiple words. o Do not use next() method. 3. Prompt user to enter the location ID. Use Scanner’s method nextLine() to read the whole location code string into a single String variable. o Do not simplify this lab by taking separate user inputs for farmID and fieldID. 4. Prompt user to enter harvest date. Use Scanner's method nextLine() to read the whole date string into a single String variable. o Do not simplify this lab by taking separate user inputs for date and month. 5. Checkpoint 1: Print out all the user input variabl es. Make sure that you have 3 variables that
  • 5. hold the data, and that they are appropriately named. They are all String types. For example: 6. Create the pieces of the bar code by extracting various elements of data from the inputs and storing them in appropriately-typed variables. Store individual pieces in separate variables with names indicating what data they hold. o A summary of helpful string manipulation methods is provided below. Your task is to figure out how to use those methods to achieve the goal set out in this lab. o HINT: you may need to use a combination of methods to find and extract each of the barcode data elements required in this lab. 7. Checkpoints: You should work on each part separately and print out the part of the code to the screen. You may find it useful to print out even subparts of the individual code parts. For example, when finding the first and last letters of the month, one approach is to extract the
  • 6. whole month into a separate variable. Printing the position of the slash and then printing the month string would be a good idea to check that it is correctly extracted: Another example is the variety code. Print it out when you obtain the 3 letters and again when you convert them to uppercase: 8. Finally, concatenate together all pieces to form the final code, and store the final barcode in one string variable. 9. Print the code to the screen. 10. Make sure that your prompts and output follow the examples in the sample output, including wording, spacing, and punctuation. 11. When your code is working, upload your .java file to the Lab 3 dropbox. String manipulation methods
  • 7. Method Return Type Description concat(String str) String Concatenates the specified string to the end of this string. indexOf(String str) int Returns the index within this string of the first occurrence of the specified substring. indexOf(String str, int fromIndex) int Returns the index within this string of the first occurrence of the specified substring, starting at the specified index. lastIndexOf(String str) int Returns the index within this string of the last occurrence of the specified substring. length() int Returns the length of this string. substring(int beginIndex) String Returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string. substring(int beginIndex, int endIndex) String Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. toUpperCase() String Converts all of the characters in this String to upper case.
  • 8. toLowerCase() String Converts all of the characters in this String to lower case. SAMPLE OUTPUT