Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

7 . 2 0 zyLab Warm - up: Format checking / ordering Strings ( product codes ) JAVA BETA feature to see your program run

7.20 zyLab Warm-up: Format checking/ordering 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 2 other existing product codes.
Each product code should be formatted as: XX99
(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.
(i.e. 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.
(1)
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 1:
Issue one of the error messages shown below:
Length error! One character too short - adding digit 0 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 1, display:
Length error! Incorrect code length of CODE is not fixable
If the input is:
AB888
the output is:
Length error! One character too long - shortening it by one
Corrected product code is now AB88
If the input is:
XYZZ888
the output is:
Length error! Incorrect code length of XYZZ888 is not fixable
(2)
When the product code length is now correct, check the product code formats.
Issue error message(s) like those shown below for any errors found:
Format error! First 2 characters in code are not letters
Format error! Last 2 characters in code are not digits
If the input is:
FGH22
the output is:
Length error! One character too long - shortening it by one
Corrected product code is now FGH2
Format error! Last 2 characters in code are not digits
WARNING: If you earn points for tests 3 & 4, but your program has errors that cause it to crash
(i.e. throw an Exception), then the points will not count.
(3)
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:
GN3
the output is:
Length error! One character too short - adding digit 0 to end
Corrected product code is now GN30
Ordered product codes:
GK93
GN30
SA14
If the input is:
WB82
the output is:
Ordered product codes:
GK93
SA14
WB82
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

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 Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago