Hi,
I need a method that takes an array of Printer type and returns this array sorted by product name. What I have sorts the string names but the thing is it outputs only one product canon. I have been looking at the tutorials and have done much research but I need some guidance as to the error of my ways.
Thank you,
lynnajoe
import java.util.*;
import java.text.*;
import java.io.*;
/**
*
* @author Lynn
*/
public class InventoryPart2 {
public InventoryPart2(String string) {
}
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
public InventoryPart2() {
}
public static void main(String[] args) {
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
Printer epson = new Printer("Epson", 1, 2, 99.99);
Printer hp = new Printer("HP", 2, 2, 149.99);
Printer kodak = new Printer("Kodak", 3, 2, 199.99);
Printer brother = new Printer("Brother", 4, 2, 249.99);
Printer canon = new Printer("Canon", 5, 3, 89.99);
String[] names = {"Epson", "HP", "Kodak", "Brother", "Canon"};
System.out.println("The original order of the names array:\n");
for (String productName : names) {
System.out.println(productName);
}
System.out.print("\nThese are the names after being sorted:\n\n");
Arrays.sort(names);
for (String productName : names) {
System.out.println(productName);
}
Printer[] myPrinter = new Printer[5];
for (int i = 0; i < myPrinter.length; i++) {
names[i] = myPrinter[i].getProductName();
}
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
System.out.printf("\nName of Product: " + Printer.getProductName()
+ "\nItem number: " + Printer.getItemNumber() +
"\nUnits in stock: " + Printer.getUnitsInStock()
+ "\nPrice per unit: " + nf.format(Printer.getPricePerUnit()));
System.out.print("\n");
System.out.printf("\nTotal product value: " + nf.format
(Printer.getCalculateInventory()));
System.out.print("\n");
}
}
}
}