Answered step by step
Verified Expert Solution
Question
1 Approved Answer
7 . 2 0 zyLab Warm - up: Format checking / ordering Strings ( product codes ) JAVA BETA feature to see your program run
zyLab Warmup: Format checkingordering Strings product codes JAVA
BETA feature to see your program run with interleaved input and output while in Develop Mode unless you leave the input box empty is turned ON for this lab Remember to click in the running program window before typing any interactive inputs.
Testing in Submit Mode will remain the same as it was before input and output will NOT be interleaved
Start with the supplied code template, editing the top of program comment to include your FULL NAME.
Program description:
This program will evaluate new product code in relation to other existing product codes.
Each product code should be formatted as: XX
First two characters must be letters and the second two characters must be digits
Two product code values are constants in the template, and are already known to be in alphabetical order.
ie the first product code comes alphabetically before the second product code
The user will input a third product code.
This program will check the length and format of the third product code
and when valid, will also order it within the other two codes.
HINT: Use of boolean variables will make implementing this program easier.
Read the user entered product code into a String variable, uppercasing it before storing it in the variable.
Then check its length, using the constant defined in the template code.
When the length is not correct, and is only off by :
Issue one of the error messages shown below:
Length error! One character too short adding digit to end
Length error! One character too long shortening it by one
and modify the product code. Then display the modified value.
When the length is not correct, but is only off by more than display:
Length error! Incorrect code length of CODE is not fixable
If the input is:
AB
the output is:
Length error! One character too long shortening it by one
Corrected product code is now AB
If the input is:
XYZZ
the output is:
Length error! Incorrect code length of XYZZ is not fixable
When the product code length is now correct, check the product code formats.
Issue error messages like those shown below for any errors found:
Format error! First characters in code are not letters
Format error! Last characters in code are not digits
If the input is:
FGH
the output is:
Length error! One character too long shortening it by one
Corrected product code is now FGH
Format error! Last characters in code are not digits
WARNING: If you earn points for tests & but your program has errors that cause it to crash
ie throw an Exception then the points will not count.
When the length and format are both correct:
Use String methods to determine the alphabetical order of the three product codes,
and display them in alphabetical order, one per line.
Reminder: Relational operators cannot be used to compare Strings!
Otherwise:
Display: Cannot order invalid code
If the input is:
GN
the output is:
Length error! One character too short adding digit to end
Corrected product code is now GN
Ordered product codes:
GK
GN
SA
If the input is:
WB
the output is:
Ordered product codes:
GK
SA
WB
If the input is:
D
the output is:
Length error! Incorrect code length of D is not fixable
Cannot order invalid code
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started