Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Java Language Overview: This Lab is a program to demonstrate Strings, the String Builder, and Regular Expressions Program Specification: This program accepts codes entered

Using Java Language

Overview: This Lab is a program to demonstrate Strings, the String Builder, and Regular Expressions

Program Specification: This program accepts codes entered into a textbox (simulating information coming in from a hand held scanner). This Program uses a StringBuilder to record the codes (to demonstrate its use) and uses String Functions and a Regular Expression to validate the information for the customers credit card number.

1.Create a Java Windows application. Change the title bar to the name of the company (you get to decide this yourself on this lab.)

2.Add Textboxes for a Code Scanned and Credit Card to Verify. Create labels with these textboxes to tell the user what they are.

3.Place 3 buttons on the frame. One to scan a code (add it to the StringBuilder if it passes), one to Verify the credit card, and one to Display the log (of the codes.)

4.Create 2 StringBuilders named: strBldrlog (or buffercodes if you likebut give it a descriptive name in any case), and strBldrFails (or bufferFails) as class level variables (so it will remember the values between button presses.)

(Note: It is not clear in the text. But, here is the deal with strings and string builders (and why you are going to use them here to work with them.) A string is used for most string objects in an OO language of this type. It saves memory by allowing multiple uses of the same word like John to all share the same reference and have only one place in memory they all use in something called the String Pool in the area of memory that stores objects. (This increased memory efficiency and program speed.) Butthis actually slows down the application if the same set of characters is being modified constantly and stored in one locationbecause the application searches for a match in the string pool, and either finds one or not, and if not it must call on the string constructor to create a new one. It is more efficient if you have something that is not being used multiple paces and changing all the time to use an actual Buffer type data structure like a StringBuilder if it is going to be modified constantly by the program. In this program its being used to keep a transaction log on the device.)

5.Under an actionPerformed event handler for the Scan button have it validate the code typed into that textfield. Use String methods from chapter 16 to make sure the code value typed by the user into its textbox is exactly 8 characters long and does not contain a space.

If it passed validation. Append the first three characters (lets say they are control codes, just to allow you to demonstrate a different set of String methods out of this chapter without writing 2 programs) to the StringBuilder recording the codes that pass in the order they were put in.

If it fails validationInsert the complete entry into the StringBuilder recording the ones that do not pass so the last one entered is the first one inside it.

6.Add code to handle a button click on the second button for the credit card verifier. (You can do this by using one action performed for all the buttons and checking the source or by creating separate event handlers. Its up to you.)

The code for this button should use a Regular Expression to test the value in the textbox. The valid format and range of values is: 4 sets of 4 digits separated by dashes, the leading digit in the first group cannot be 0, the second group of digits are each in the range of 1-3 [they are control numbers indicating the type of card.]

If the credit card number is not in a valid formatgive a JOptionPane message box or show a message in a JLabel so the user can see that the number entered is not a valid card number.

Example: 1234-1122-7474-1234 is a valid card number.

222-22-222, 0111-1111-1111-1111, and b123-5555-1111-1111 are not valid card numbers.

Hint: The pattern for checking a phone number is very similar and is shown in the chapter.

7. The third button should show the current values in the two StringBuilders for the user. (Remember one had the first three characters of the ones that pass in the order they were put in, and the second one has the ones that failed in the order of last entered.)

You can do this in Labels, JOptionPanes, or other controls. It is up to you how you display them for the user. (You can also use a JFrame Application where you drag the controls from the Netbeans toolbox. You do not have to set the controls or ActionListeners manually like the last chapter.)

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 Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions