Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package PostalBarCode; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class PostalBarCode{ private JPanel mainPanel; private JLabel zipCodeLabel; private JTextField zipCodeTextField; private JButton barButton; private JButton

image text in transcribed image text in transcribed package PostalBarCode; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class PostalBarCode{ private JPanel mainPanel; private JLabel zipCodeLabel; private JTextField zipCodeTextField; private JButton barButton; private JButton clearButton; private JButton zipButton; private JPanel buttonPanel; private JLabel barCodeLabel; private JTextField barCodeTextField; public PostalBarCode() { clearButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { barCodeTextField.setText(""); // Write empty string to text fields zipCodeTextField.setText(""); } }); barButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String barCodeText = toPostalBarCode(zipCodeTextField.getText()); barCodeTextField.setText(barCodeText); } }); zipButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String zipCodeText = toZipCode(barCodeTextField.getText()); zipCodeTextField.setText(zipCodeText); } }); } private void createUIComponents() { // TODO: place custom component creation code here } public JPanel getPanel() { return mainPanel; } public String toZipCode (String bc) { String zipCode = ""; String[] barCodeDigits = new String[]{"||:::", ":::||", "::|:|", "::||:", ":|::|", ":|:|:", ":||::", "|:::|", "|::|:", "|:|::"}; bc = bc.substring(1, bc.length() - 1); String[] barCodeArray = bc.split("\\|"); for (String barCodeDigit : barCodeArray) { for (int i = 0; i  

Here is code Please fix it. Code converts zip to barcode but it won't convert Bar Code to zip.

 There is come issue here this part is nopt working and public String toZipCode (String bc) { String zipCode = ""; String[] barCodeDigits = new String[]{"||:::", ":::||", "::|:|", "::||:", ":|::|", ":|:|:", ":||::", "|:::|", "|::|:", "|:|::"}; bc = bc.substring(1, bc.length() - 1); String[] barCodeArray = bc.split("\\|"); for (String barCodeDigit : barCodeArray) { for (int i = 0; i  

HERE IS CODE FOR GUI/APP THIS WILL HELP YOU TO RUN CODE:

package PostalBarCode; import javax.swing.*; public class PostalBarCodeApp { private PostalBarCode form; private JFrame frame; public void initialize() { form = new PostalBarCode(); frame = new JFrame("Postal Bar Code Application"); frame.add(form.getPanel()); frame.setSize(500, 400); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true); frame.pack(); } public static void main(String args[]) { try { for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (Exception e) { JFrame.setDefaultLookAndFeelDecorated(true); } PostalBarCodeApp myApp = new PostalBarCodeApp(); myApp.initialize(); } } 

PLEASE FIX IT

THANK YOU :)

For faster sorting of letters, the United States Postal Service encourages companies that send large volumes of mail to use a bar code denoting the Zip code. The encoding scheme for a five-digit ZIP code is shown above. There are full height frame bars on each side. The five encoded digits are followed by a correction digit, which is computed as follows: Add up all the digits, and choose the correction digit to make the sum a multiple of 10. For example, the ZIP code 95014 has sum of digits 19, so the correction digit is 1 to make the sum equal to 20. Each digit of the ZIP code, and the correction digit, is encoded according to the following table: where 0 denotes a half bar and 1 a full bar. Note that they represent all combinations of two full and three half bars. The digit can be easily computed from the bar code using the column weights 7, 4, 2, 1,0. For example, 01100 is 07+14+12+01+00=6. The only exception is 0 , which would yield 11 according to the weight formula. For this assignment, you are to create a Java Application, named PostalBarCode, which performs the following conversion processing. Your program should include a toZipCode method that accepts a bar code string and returns the converted zip code string and a toPostalBarCode method that accepts a zip code string and returns the converted bar code string. Your application should contain two text fields with appropriate labels: - A Zip Code text field for entry and display of a Zip Code string - A Postal Bar Code text field for the entry and display of a Postal Bar Code string. Your application should contain the following three buttons with associated event handling: - A button, with label "Bar", for converting a zip code to bar code. When the associated event is handled, the program should read the entered zip code string from the Zip Code text field, invoke the toPostalBarCode method, and then display the converted postal bar code in the Postal Bar Code Text Field. Your program should be able to handle both the 5-digit (i.e. 18512) and 9-digit (i.e. 18512-1602) zip codes. An error should be displayed when the input zip code does not match one of these formats. - A button, with label "Zip", for converting a bar code to a zip code. When the associated event is handled, the program should read the entered bar code string from the Postal Bar Code text field, invoke the toZipCode method, and then display the converted Zip Code in the Zip Code text field. An error should be printed when the input bar code is not valid. - A button, with label "Clear", for clearing text fields. When the associated event is handled for this button, both the zip code and bar code text fields should be cleared. Use ':' for half bars, ' ' for full bars. For example 95014 becomes ||:::::::::::::::::: The variables and methods defined within your Java classes must include comments. Your program should also be properly formatted, which includes indentation of code. Note: You must utilize the starting template posted to CANVAS to receive credit for this assignment

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

Data Management Databases And Organizations

Authors: Richard T. Watson

2nd Edition

0471180742, 978-0471180746

More Books

Students also viewed these Databases questions