public static Printer[] sortArray(Printer[] printers)
{
String[] productName = new String[printers.length];
Printer[] serial = new Printer [printers.length];
for (int i = 0; i < printers.length; i++)
{
productName = printers.getproductName();
}
Arrays.sort(productName);
for (int i = 0; i < printers.length; i++)
{
for (int j = 0; j < productName length; j++)
{
if (printers.getproductName().equalsIgnoreCase(productName[j]))
{
serial[j] = printers;
}
}
}
return serial;
}
public static double totalInventory(Printer[] printers)
{
double total = 0;
for (int i = 0; i < printers.length; i++)
{
total += printers.totalInventory();
}
return total;
}
Unfortunately if I move it from where it is now in my program, I get a tone of error messages. Here is my product class and the Laser class which extends the printer and holds all my info.
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Arrays;
class Printer {
//declare class variables
private String itemNumber;
private String productName;
private int unitsInStock;
private double unitPrice;
private double totalInventory;
private String serialNumber;
private double restockFee;
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
//class constructor
public Printer (String itemNumber, String productName, int unitsInStock, double unitPrice, String serialNumber){
this.itemNumber = itemNumber;
this.productName = productName;
this.unitsInStock = unitsInStock;
this.unitPrice = unitPrice;
this.serialNumber = serialNumber;
this.restockFee = restockFee;
}
//get and set methods
//item number
public String getItemNumber(){
return itemNumber;
}
public void setItemNumber(String itemNumber){
this.itemNumber = itemNumber;
}
//printer name
public String getProductName(){
return productName;
}
public void setProductName(String productName){
this.productName = productName;
}
//available units
public int getUnitsInStock(){
return unitsInStock;
}
public void setUnitsInStock (int unitsInStock){
this.unitsInStock = unitsInStock;
}
//price
public double getUnitPrice(){
return unitPrice;
}
public void setUnitPrice (double unitPrice){
this.unitPrice = unitPrice;
}
//calculate the total inventory
public double totalInventory()
{
return unitPrice * unitsInStock;
}
public double restockFee()
{
return unitPrice * .05;
}
//out put the variables with a toString method
public String toString ()
{
return "Item Number: " + itemNumber + "\nProduct Name: " + productName + "\nUnits In Stock: " + unitsInStock +
"\nPrice : " + nf.format(unitPrice) + "\nTotal Value: " + nf.format(totalInventory()) + "\nSerial Number: " + serialNumber + "\nRestock Fee: " + nf.format(restockFee());
}
}//end Printer class
class Laser extends Printer
{
//class variables
public String serialNumber;
public double restockFee;
public static final double RESTOCK_FEE_PERCENTAGE = .05;
//class constructor
public Laser (String itemNumber, String productName, int unitsInStock, double unitPrice, double totalInventory, String serialNumber)
{
super(itemNumber, productName, unitsInStock, unitPrice, serialNumber);
this.serialNumber = serialNumber;
//calculate the restock fee
restockFee = unitPrice * RESTOCK_FEE_PERCENTAGE;
}
//get and set methods
public String getSerialNumber()
{
return serialNumber;
}
public void setSerialNumber(String serialNumber)
{
this.serialNumber = serialNumber;
}
public double getRestockFee()
{
return restockFee;
}
// output restock fee and serial number
public String toString ()
{
return super.toString() + "\n" + "Serial Number: " + serialNumber + "Restock Fee:" + nf.format(getRestockFee());
}
}
Here is my problem. This is my main class and the class I need to hold my buttons, my logo and info that I need to respond to all my printers inventory as per the navigation of the buttons.import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Arrays;
//Filename: <InventoryPart4.java>
//Description: <program outputs Printer inventory>
// Author Name: <Chrstina Ditzel>
// Date: <June 20, 2011>
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Arrays;
import javax.swing.*;
public class InventoryPart5
{
public static Printer[] sortArray(Printer[] printers)
{
String[] productName = new String[printers.length];
Printer[] serialNumber = new Printer [printers.length];
for (int i = 0; i < printers.length; i++)
{
productName[i] = printers[i].getProductName();
}
Arrays.sort(productName);
for (int i = 0; i < printers.length; i++)
{
for (int j = 0; j < productName.length; j++)
{
if (printers[i].getProductName().equalsIgnoreCase(productName[j]))
{
serialNumber[j] = printers[i];
}
}
}
return serialNumber;
}
public static double totalInventory(Printer[] printers)
{
double total = 0;
for (int i = 0; i < printers.length; i++)
{
total += printers[i].totalInventory();
}
return total;
}
static int printerIndex= 0;
public static JTextArea PrepareDisplay(Printer myPrinter, JTextArea myTextArea)
{
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
myTextArea.setText("");
myTextArea.append(myPrinter.toString());
return myTextArea;
}
public static void main (String args[])
{
Printer brother = new Printer("P1101", "Brother Inkjet Muliti-function Printer", 12, 217.60, "BroLM200");
Printer canon = new Printer("P1102","Canon Bubble Jet Photo Printer", 13, 1249.98, "CanJPH300");
Printer dell = new Printer("P1103", "Dell Multi-Function Laser Printer", 3, 149.99, "DelMFL400");
Printer hp = new Printer("P1104","HP LaserJet Printer" , 5, 149.99, "HPL500");
Printer lexmar = new Printer("P1105","Lexmar CLP Printer", 10, 299.98, "LexCLP600");
//create inventory items in array
final Printer[] printers = new Printer[5];
printers[0] = brother;
printers[1] = canon;
printers[2] = dell;
printers[3] = hp;
printers[4] = lexmar;
//initialize the JTextArea Class and set the parameters
final JTextArea textArea = new JTextArea(10,15);
textArea.setText("");
textArea.setEditable(false);
//create the first and last buttons and add them to the button panel
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(1, 3));
JButton firstButton = new JButton("First");
buttonPanel.add(firstButton);
firstButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
printerIndex = 0; //set index to the first item in the array
}
});
JButton lastButton = new JButton("Last");
buttonPanel.add(lastButton);
lastButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
printerIndex = (printers.length - 3); //set index to the last item in the array
}
});
//create company logo and then add it to the logo panel
JLabel logoLabel = new JLabel (new ImageIcon("Company Logo.jpg"));
JPanel logoPanel = new JPanel();
logoPanel.add(logoLabel);
JPanel centerPanel = new JPanel();
centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));
//prepare the text that will be displayed in the GUI
for (int i = 0; i < printers.length; i++ )
{
textArea.append("\n"+ printers[i] + "\n");
}
//initialize the GUI window and set the parameters
JFrame frame = new JFrame();
frame.getContentPane().add(new JScrollPane(textArea));
frame.setLayout(new BorderLayout());
frame.add(logoPanel, BorderLayout.NORTH);
frame.add(buttonPanel, BorderLayout.SOUTH);
frame.add(centerPanel, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}//end main
}//end Iventory class

New Topic/Question
Reply



MultiQuote



|