The Plain Wrap Auto Parts Company assignment
232 viewsSomeone asked me to write an application that:
• Use an array to store the data for the different brands.
• Must have 4 additional index positions available for data entry so that I may be able to add
• Must ensure that PR or Plain Wrap is not duplicated in data entry
• Cannot use scanner
• You may choose to use 2 dimensional array (one class needed) or object of array(two classes needed)Output:
• You will need to display the plain wrap number chosen and the corresponding Brands for that particular part.
So here it is:
Code:
JAVA:
-
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;
-
-
JList pWrapList;
-
JLabel pWrapLbl,pInfo, pWrapInputLbl, brandAInputLbl, brandBInputLbl, brandCInputLbl;
-
JTextArea brands;
-
JTextField pWrapInputTxt, brandAInputTxt, brandBInputTxt, brandCInputTxt;
-
JScrollPane scrollPane;
-
{"PR214", "MR43T", "RBL8", "14K22"},
-
{"PR223", "R43", "RJ6 ", "14K24"},
-
{"PR224", "R43N ", "RN4 ", "14K30"},
-
{"PR246", "R46N", "RN8 ", "14K32"}}; //etc..
-
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.setBounds(10,0,150,20);
-
-
pInfo.setBounds(170,0,100,20);
-
-
pWrapList.addListSelectionListener(this);
-
scrollPane.setBounds(10,20,150,150);
-
-
"none none none");
-
brands.setEditable(false);
-
brands.setBounds(170,20,280,40);
-
-
addBtn.addActionListener(this);
-
addBtn.setBounds(460,20,100,20);
-
-
searchBtn.setEnabled(false);
-
searchBtn.addActionListener(this);
-
searchBtn.setBounds(460,40,100,20);
-
-
listAllBtn.setEnabled(false);
-
listAllBtn.addActionListener(this);
-
listAllBtn.setBounds(460,60,100,20);
-
-
pWrapInputLbl.setBounds(170,70,100,20);
-
-
brandAInputLbl.setBounds(170,90,100,20);
-
-
brandBInputLbl.setBounds(170,110,100,20);
-
-
brandCInputLbl.setBounds(170,130,100,20);
-
-
pWrapInputTxt.setBounds(250,70,200,20);
-
-
brandAInputTxt.setBounds(250,90,200,20);
-
-
brandBInputTxt.setBounds(250,110,200,20);
-
-
brandCInputTxt.setBounds(250,130,200,20);
-
-
confirmBtn.addActionListener(this);
-
confirmBtn.setBounds(250,150,100,20);
-
-
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);
-
}
-
-
Ch10Assignment partNumber = new Ch10Assignment();
-
partNumber.setInitialState();
-
partNumber.showGui();
-
}
-
-
public void addNew(){
-
boolean duplicate = false;
-
-
for( int i = 0; i <partNumberString.length; i++ ){
-
tmp[i][0] = partNumberString[i][0];
-
for(int j = 1; j
-
tmp[i][j] = partNumberString[i][j];
-
}
-
}
-
-
//add the new part(s)
-
for(int i = 0; i
-
if(listElements.get(i).equals(pWrapInputTxt.getText().toUpperCase())){
-
duplicate= true;
-
}
-
}
-
-
if( !pWrapInputTxt.getText().equals("") &&
-
!brandAInputTxt.getText().equals("") &&
-
!brandBInputTxt.getText().equals("") &&
-
!brandCInputTxt.getText().equals("") &&
-
!duplicate && pWrapInputTxt.getText().substring(0, 2).equals("PR") )
-
{
-
tmp[partNumberString.length][0] = pWrapInputTxt.getText();
-
tmp[partNumberString.length][1] = brandAInputTxt.getText();
-
tmp[partNumberString.length][2] = brandBInputTxt.getText();
-
tmp[partNumberString.length][3] = brandCInputTxt.getText();
-
-
cleanForm();
-
listElements.addElement(tmp[partNumberString.length][0]);
-
showForm(false);
-
-
//copy the tmp array back to the original array
-
for( int i = 0; i <tmp.length; i++ ){
-
partNumberString[i][0] = tmp[i][0];
-
for(int j = 1; j
-
partNumberString[i][j] = tmp[i][j];
-
}
-
}
-
}
-
else{
-
}
-
}
-
-
public void setInitialState(){
-
for( int i = 0; i <partNumberString.length; i++ ){
-
tmp[i][0] = partNumberString[i][0];
-
listElements.addElement("" + tmp[i][0]);
-
}
-
}
-
-
if(e.getSource() == addBtn){
-
showForm(true);
-
}
-
-
if(e.getSource() == confirmBtn){
-
addNew();
-
}
-
-
if(e.getSource() == cancelBtn){
-
showForm(false);
-
cleanForm();
-
}
-
}
-
-
public void showForm(boolean show){
-
pWrapInputLbl.setVisible(show); brandAInputLbl.setVisible(show);
-
brandBInputLbl.setVisible(show); brandCInputLbl.setVisible(show);
-
pWrapInputTxt.setVisible(show); brandAInputTxt.setVisible(show);
-
brandBInputTxt.setVisible(show); brandCInputTxt.setVisible(show);
-
confirmBtn.setVisible(show); cancelBtn.setVisible(show);
-
}
-
-
public void cleanForm(){
-
pWrapInputTxt.setText(""); brandAInputTxt.setText("");
-
brandBInputTxt.setText("");
-
brandCInputTxt.setText("");
-
}
-
-
int selection = pWrapList.getSelectedIndex();
-
brands.setText("Brand A Brand B Brand C\n" +
-
partNumberString[selection][1] + " " +
-
partNumberString[selection][2] + " " +
-
partNumberString[selection][3]);
-
}
-
}
Screenshot:
Download the java file here


(3 votes, average: 3.67 out of 5)








