NOTE: Each numeral representation should have a total of two full bars, and thre
ID: 3657623 • Letter: N
Question
NOTE: Each numeral representation should have a total of two full bars, and three 1/2 bars There are discrepancies in the chart and examples in my version of the text - see example Figure 7: I believe it should read | | : | : : would be 9 with the START prefix pipe added, : | : | : would be 5, | | : : : which is 11 designates zero, : : : | | is one, and : | : : | is for four, and finally : : :| | | is for check sum of one with the following END pipe symbol.. So the question is why are some designated with a pipe in the zero location and some are not! Be sure you do NOT follow the book error, remember 2 - full, 3 - halves! Note: the first digit is preceded by a | Note: the final check digit is followed by | Enable input of a five digit or nine digit zip code and convert to a series of colons and pipes. Enable input of a series of pipes and convert to a zip code. The correct use of classes described in the chapter should be implemented along with "good" programming conventionsExplanation / Answer
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class PostOffice extends JFrame implements ActionListener { //This appears on the screen as a clickable button private JButton zipCodeButton; //This appears as two text fields where you can type private JTextField zipCodeField, barCodeField; //This appears as text, a label next to the zip code field private JLabel zipCodeLabel; //This is the variable your professor has created to get input //from the GUI. private PostalZipCode myZip; public static void main () { //All of this code creates the GUI and shows it to you //You shouldn't be concerned with it, and you do not //need to alter it or add to it in any way. PostOffice myApplication = new PostOffice(); myApplication.setSize(400,140); myApplication.setTitle("Zip Code"); myApplication.createGUI(); myApplication.setVisible(true); } //Again, more code to create the GUI. You do not need to //change any of this code either private void createGUI() { setDefaultCloseOperation(EXIT_ON_CLOSE); Container window = getContentPane(); window.setLayout(new FlowLayout()); zipCodeLabel = new JLabel(" Zip Code "); window.add(zipCodeLabel); zipCodeField = new JTextField(5); window.add(zipCodeField); barCodeField = new JTextField(20); barCodeField.setHorizontalAlignment(JTextField.CENTER); barCodeField.setFont(new Font("Sans erif", Font.BOLD, 20)); window.add(barCodeField); zipCodeButton = new JButton("Display Postal Bar Code"); zipCodeButton.addActionListener(this); window.add(zipCodeButton); } //The code that you are primarily concerned with is in here. public void actionPerformed (ActionEvent e) { //Your professor reads in the zip code String userInput = zipCodeField.getText(); //Here, your professor takes a zip code, "userInput", and //calls a constructor that converts it to a PostalZipCode. //You need to write that constructor. Doing so involves creating a new class called PostalZipCode, writing a constructor called PostalZipCode that converts a Zip code to a PostalZipCode. myZip = new PostalZipCode(userInput); //In your PostalZipCode class, you need a method call getBarCode() that returns a String. The String should be the bar code. barCodeField.setText(myZip.getBarCode()); } } And here is an outline of what the class you are writing should look like and contain: public class PostalZipCode{ String thisZipCode = ""; String postalZipCode = ""; String barCode = ""; public PostalZipCode(String zipCode){ thisZipCode = zipCode; postalZipCode = convertZipcodeToPostal(zipCode); setBarCode(); } public String convertZipcodeToPostal(String aZip){ String postalCode = ""; //Do whatever you need to to aZip to convert it to a postalZipCode. return postalCode; } public void setBarCode(){ //write code that uses the zipCode to set the bar code } public String getBarCode(){ return barCode; } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.