Question
Include the initial hierarchy chart, flowchart, and pseudocode for the logic of the program. VB Auto Sells its own brand of spark plugs. To Cross-refance to major brands, it keeps a table of equivalent part numbers. Vb Auto wants to Coumputerize the process of looking up part numbers in oerder to improve it's customer servace. The user should be able to enter the part number and the brand and look up the corresponding VBauto part number you may allo the user to select the brand ( Brand A, Brand C, or Brand X) form a List or from radio Buttons. You can shoose from two approches for the lookup table, Store the part numbers either in a 2 dimensional table or in an array of a structure. In eather case use the part number and brand enterd by the user; look up and display the vb Auto part number.
Explanation / Answer
import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.DefaultListModel; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; public class Ch10Assignment extends JFrame implements ActionListener, ListSelectionListener { JList pWrapList; DefaultListModel listElements = new DefaultListModel(); JLabel pWrapLbl,pInfo, pWrapInputLbl, brandAInputLbl, brandBInputLbl, brandCInputLbl; JTextArea brands; JTextField pWrapInputTxt, brandAInputTxt, brandBInputTxt, brandCInputTxt; JScrollPane scrollPane; String[][] partNumberString = { {"PR214", "MR43T", "RBL8", "14K22"}, {"PR223", "R43", "RJ6 ", "14K24"}, {"PR224", "R43N ", "RN4 ", "14K30"}, {"PR246", "R46N", "RN8 ", "14K32"}}; //etc.. String[][] tmp; JButton addBtn, searchBtn, confirmBtn, cancelBtn, listAllBtn; boolean show = false; int counterInteger = 0; int plainWrapInteger [] = new int [3]; String plainWrapString, brandAString, brandCString, brandXString; public void showGui(){ getContentPane().setLayout(null); pWrapLbl = new JLabel("Choose plain wrap: "); pWrapLbl.setBounds(10,0,150,20); pInfo = new JLabel("Parts:"); pInfo.setBounds(170,0,100,20); pWrapList = new JList(listElements); pWrapList.addListSelectionListener(this); scrollPane = new JScrollPane(pWrapList); scrollPane.setBounds(10,20,150,150); brands = new JTextArea("Brand A Brand B Brand C " + "none none none"); brands.setEditable(false); brands.setBorder(BorderFactory.createLineBorder(Color.black, 1)); brands.setBounds(170,20,280,40); addBtn = new JButton("Add new"); addBtn.addActionListener(this); addBtn.setBounds(460,20,100,20); searchBtn = new JButton("Search"); searchBtn.setEnabled(false); searchBtn.addActionListener(this); searchBtn.setBounds(460,40,100,20); listAllBtn= new JButton("List all"); listAllBtn.setEnabled(false); listAllBtn.addActionListener(this); listAllBtn.setBounds(460,60,100,20); pWrapInputLbl = new JLabel("Wrap:"); pWrapInputLbl.setBounds(170,70,100,20); brandAInputLbl = new JLabel("Brand A:"); brandAInputLbl.setBounds(170,90,100,20); brandBInputLbl = new JLabel("Brand B:"); brandBInputLbl.setBounds(170,110,100,20); brandCInputLbl = new JLabel("Brand C:"); brandCInputLbl.setBounds(170,130,100,20); pWrapInputTxt = new JTextField(); pWrapInputTxt.setBounds(250,70,200,20); brandAInputTxt = new JTextField(); brandAInputTxt.setBounds(250,90,200,20); brandBInputTxt = new JTextField(); brandBInputTxt.setBounds(250,110,200,20); brandCInputTxt = new JTextField(); brandCInputTxt.setBounds(250,130,200,20); confirmBtn = new JButton("Ok"); confirmBtn.addActionListener(this); confirmBtn.setBounds(250,150,100,20); cancelBtn = new JButton("Cancel"); cancelBtn.addActionListener(this); cancelBtn.setBounds(350,150,100,20); add(pWrapLbl); add(scrollPane); add(brands); add(addBtn); add(cancelBtn); add(pInfo); // not needed, dropped. add(searchBtn); add(listAllBtn); add(pWrapInputLbl); add(brandAInputLbl); add(brandBInputLbl); add(brandCInputLbl); add(pWrapInputTxt); add(brandAInputTxt); add(brandBInputTxt); add(brandCInputTxt); add(confirmBtn); showForm(show); setSize(600,200); setTitle("By: HappyFace - Engineeringserver.com"); setResizable(false); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); } public static void main(String[] args) { Ch10Assignment partNumber = new Ch10Assignment(); partNumber.setInitialState(); partNumber.showGui(); } public void addNew(){ boolean duplicate = false; tmp = new String[partNumberString.length+1][4]; for( int i = 0; i