i have an error can someone please help me with this......
C:\Java Test>javac InventoryPart6.java
InventoryPart6.java:370: error: constructor Supplier in class Supplier cannot be
applied to given types;
Supplier supplier = new Supplier();
^
required: int,String,int,double,String
found: no arguments
reason: actual and formal argument lists differ in length
1 error
C:\Java Test>
Code:import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
@SuppressWarnings("serial")
public class InventoryPart6 extends JFrame implements ActionListener {
private static DecimalFormat currency = new DecimalFormat("$#,##0.00");
private Logo logo;
private JTextArea itemData;
private JButton firstItem;
private JButton previousItem;
private JButton nextItem;
private JButton lastItem;
private JButton addItem;
private JButton removeItem;
private JButton modifyItem;
private JButton saveItems;
private JButton searchItem;
private ArrayList<Supplier> products;
private int current = 0;
public static void main(String[] args) {
new InventoryPart6();
}
public InventoryPart6() {
products = new ArrayList<Supplier>();
products.add(new Supplier(500, "Latitude", 10, 800, "Dell"));
products.add(new Supplier(200, "Vostro", 20, 650, "Dell"));
products.add(new Supplier(300, "Pavilion", 15, 890, "HP"));
products.add(new Supplier(350, "Vaio", 10, 1200, "Sony"));
products.add(new Supplier(400, "MacBook", 80, 1500, "Apple"));
sortArray();
configureGUI();
}
private void configureGUI() {
setTitle("InventoryPart 6");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(700, 360);
setLocationRelativeTo(null);
logo = new Logo();
logo.setPreferredSize(new Dimension(getWidth(), 60));
logo.setFont(new Font("Courier New", Font.BOLD, 28));
itemData = new JTextArea(12, 40);
firstItem = new JButton("First");
firstItem.addActionListener(this);
previousItem = new JButton("Previous");
previousItem.addActionListener(this);
nextItem = new JButton("Next");
nextItem.addActionListener(this);
lastItem = new JButton("Last");
lastItem.addActionListener(this);
addItem = new JButton("Add");
addItem.addActionListener(this);
removeItem = new JButton("Remove");
removeItem.addActionListener(this);
modifyItem = new JButton("Modify");
modifyItem.addActionListener(this);
saveItems = new JButton("Save");
saveItems.addActionListener(this);
searchItem = new JButton("Search");
searchItem.addActionListener(this);
setLayout(new BorderLayout());
JPanel south = new JPanel(new FlowLayout());
south.add(firstItem);
south.add(previousItem);
south.add(nextItem);
south.add(lastItem);
south.add(addItem);
south.add(modifyItem);
south.add(removeItem);
south.add(searchItem);
south.add(saveItems);
add(logo, BorderLayout.NORTH);
add(new JScrollPane(itemData), BorderLayout.CENTER);
add(south, BorderLayout.SOUTH);
setVisible(true);
displayItem();
}
public double calculateInventory() {
double value = 0;
for (int i = 0; i < products.size(); i++) {
value += products.get(i).calculateInventory();
}
return value;
}
public void sortArray() {
int n = products.size();
boolean swapped;
do {
swapped = false;
for (int i = 0; i < n - 1; i++) {
Supplier p1 = products.get(i);
String name1 = p1.getProductName();
Supplier p2 = products.get(i + 1);
String name2 = p2.getProductName();
if (name1.compareToIgnoreCase(name2) > 0) {
Supplier temp = p1;
products.set(i, p2);
products.set(i + 1, temp);
swapped = true;
}
}
n = n - 1;
} while (swapped);
}
@Override
public void actionPerformed(ActionEvent e) {
if (firstItem.equals(e.getSource())) {
displayFirstItem();
} else if (previousItem.equals(e.getSource())) {
displayPreviousItem();
} else if (nextItem.equals(e.getSource())) {
displayNextItem();
} else if (lastItem.equals(e.getSource())) {
displayLastItem();
} else if (addItem.equals(e.getSource())) {
addItem();
} else if (removeItem.equals(e.getSource())) {
removeItem();
} else if (modifyItem.equals(e.getSource())) {
modifyItem();
} else if (searchItem.equals(e.getSource())) {
seachItem();
} else if (saveItems.equals(e.getSource())) {
saveItems();
}
}
private void saveItems() {
File file;
file = new File("c:\\data");
if (!file.exists()) {
file.mkdir();
}
file = new File("c:\\data\\inventory.dat");
if (file.exists()) {
file.delete();
}
try {
file.createNewFile();
} catch (IOException ioe) {
JOptionPane.showMessageDialog(null,
"Failed to create the Inventory file.");
return;
}
BufferedWriter writer;
try {
writer = new BufferedWriter(new FileWriter(file));
} catch (IOException e) {
JOptionPane.showMessageDialog(null,
"Could not create the inventory file.");
return;
}
String line;
for (int i = 0; i < products.size(); i++) {
Supplier product = products.get(i);
line = product.getProductName() + "\t";
line += product.getItemNumber() + "\t";
line += product.getPrice() + "\t";
line += product.getUnitsInStock() + "\t";
line += product.getSupplierName() + "\n";
try {
writer.write(line);
} catch (IOException e) {
JOptionPane.showMessageDialog(null,
"Could not write in the inventory file.");
}
}
try {
writer.close();
} catch (IOException e) {
JOptionPane.showMessageDialog(null,
"Could not close the inventory file.");
}
JOptionPane.showMessageDialog(null, "File Saved.");
}
private int findByProductName(String name) {
int index = -1;
for (int i = 0; i < products.size(); i++) {
Supplier product = products.get(i);
if (product.getProductName().equalsIgnoreCase(name)) {
index = i;
break;
}
}
return index;
}
private void seachItem() {
String productName = JOptionPane
.showInputDialog("Enter the product name");
if (productName != null) {
int index = findByProductName(productName);
if (index != -1) {
current = index;
displayItem();
} else {
JOptionPane.showMessageDialog(null, "Product: " + productName
+ " does not exist.");
}
}
}
private void modifyItem() {
if (current != -1) {
String name = promptString("Enter the product name");
int units = promptInteger("Enter the number of units");
double price = promptDouble("Enter product price");
String supplierName = promptString("Enter the supplier name");
Supplier supplier = products.get(current);
supplier.setName(name);
supplier.setUnitsInStock(units);
supplier.setPrice(price);
supplier.setSupplierName(supplierName);
displayItem();
}
}
private void displayLastItem() {
current = products.size() - 1;
displayItem();
}
private void displayNextItem() {
current++;
if (current > products.size() - 1) {
current = 0;
}
displayItem();
}
private void displayPreviousItem() {
current--;
if (current < 0) {
current = products.size() - 1;
}
displayItem();
}
private void displayFirstItem() {
current = 0;
displayItem();
}
private String prompt(String message) {
return JOptionPane.showInputDialog(this, message);
}
private String promptString(String message) {
String data = null;
do {
data = prompt(message);
} while (data == null);
return data;
}
private int promptInteger(String message) {
int data = 0;
boolean isValid = false;
do {
String dataString = prompt(message);
if (dataString != null) {
try {
data = Integer.parseInt(dataString);
isValid = true;
} catch (Exception e) {
isValid = false;
}
}
} while (!isValid);
return data;
}
private double promptDouble(String message) {
double data = 0;
boolean isValid = false;
do {
String dataString = prompt(message);
if (dataString != null) {
try {
data = Double.parseDouble(dataString);
isValid = true;
} catch (Exception e) {
isValid = false;
}
}
} while (!isValid);
return data;
}
private void addItem() {
String name = promptString("Enter the product name");
int units = promptInteger("Enter the number of units");
double price = promptDouble("Enter product price");
String supplierName = promptString("Enter the product supplier");
Supplier supplier = new Supplier();
supplier.setName(name);
if (products.size() > 0) {
Supplier lastProduct = products.get(products.size() - 1);
supplier.setItemNumber(lastProduct.getItemNumber() + 1);
} else {
supplier.setItemNumber(1);
}
supplier.setPrice(price);
supplier.setUnitsInStock(units);
supplier.setSupplierName(supplierName);
products.add(supplier);
displayLastItem();
}
private void removeItem() {
if (products.size() > 0) {
products.remove(current);
displayLastItem();
}
}
private void displayItem() {
if (current >= 0) {
Supplier supplier = products.get(current);
StringBuilder sb = new StringBuilder();
sb.append("Item Number: " + supplier.getItemNumber() + "\n");
sb.append("Product Name: " + supplier.getProductName() + "\n");
sb.append("Units In Stock: " + supplier.getUnitsInStock() + "\n");
sb.append("Unit Price: " + currency.format(supplier.getPrice())
+ "\n");
sb.append("Supplier Name: " + supplier.getSupplierName() + "\n");
sb.append("Inventory Value: "
+ currency.format(supplier.calculateInventory()) + "\n");
sb.append("Restock Fee: "
+ currency.format(supplier.calculateRestockFee()) + "\n");
sb.append("\n\nValue of the entire inventory: "
+ currency.format(calculateInventory()));
itemData.setText(sb.toString());
} else {
itemData.setText(null);
}
}
}

