Help with added constructor in subclass in array

I am writing a program that needs to have a subclass that adds a new constructor and adds in a 5% restocking fee. I have everything working except the new constructor. My new constructor should add the manufacturer name. My question is, now when I sort my array alphabetically by product name (folders, glue, markers, etc.) the newly added manufacturer name (Bic, Mead, Stanley, etc.) does not coincide with the right product. How do I get the newly added constructor in my subclass to stay with the right product?

Here is my first set of output with correct information:

Product name : pens

Manufacturer : Bic

Item number : 1

Piece's in stock : 346.0

Unit price : $1.59

Product name : pencils

Manufacturer : Mead

Item number : 2

Piece's in stock : 487.0

Unit price : $0.59

Product name : markers

Manufacturer : Sharpie

Item number : 3

Piece's in stock : 168.0

Unit price : $1.29

Product name : paperclips

Manufacturer : Dennison

Item number : 4

Piece's in stock : 136.0

Unit price : $1.19

Product name : glue

Manufacturer : Elmer's

Item number : 5

Piece's in stock : 72.0

Unit price : $0.79

Product name : tape

Manufacturer : 3m

Item number : 6

Piece's in stock : 127.0

Unit price : $0.49

Product name : paper

Manufacturer : Mead

Item number : 7

Piece's in stock : 203.0

Unit price : $1.79

Product name : staples

Manufacturer : Pentech

Item number : 8

Piece's in stock : 164.0

Unit price : $1.19

Product name : folders

Manufacturer : Mead

Item number : 9

Piece's in stock : 238.0

Unit price : $0.49

Product name : rulers

Manufacturer : Stanley

Item number : 10

Piece's in stock : 123.0

Unit price : $0.17

_

Here is my output after sorting by product name:

Product name : folders

Manufacturer : Bic

Item number : 9

Unit price : $0.49

The value of folders left in the inventory, plus a 5% restocking fee is: $122.45

Product name : glue

Manufacturer : Mead

Item number : 5

Unit price : $0.79

The value of glue left in the inventory, plus a 5% restocking fee is: $59.72

Product name : markers

Manufacturer : Sharpie

Item number : 3

Unit price : $1.29

The value of markers left in the inventory, plus a 5% restocking fee is: $227.56

Product name : paper

Manufacturer : Dennison

Item number : 7

Unit price : $1.79

The value of paper left in the inventory, plus a 5% restocking fee is: $381.54

Product name : paperclips

Manufacturer : Elmer's

Item number : 4

Unit price : $1.19

The value of paperclips left in the inventory, plus a 5% restocking fee is: $169.93

Product name : pencils

Manufacturer : 3m

Item number : 2

Unit price : $0.59

The value of pencils left in the inventory, plus a 5% restocking fee is: $301.70

Product name : pens

Manufacturer : Mead

Item number : 1

Unit price : $1.59

The value of pens left in the inventory, plus a 5% restocking fee is: $577.65

Product name : rulers

Manufacturer : Pentech

Item number : 10

Unit price : $0.17

The value of rulers left in the inventory, plus a 5% restocking fee is: $21.96

Product name : staples

Manufacturer : Mead

Item number : 8

Unit price : $1.19

The value of staples left in the inventory, plus a 5% restocking fee is: $204.92

Product name : tape

Manufacturer : Stanley

Item number : 6

Unit price : $0.49

The value of tape left in the inventory, plus a 5% restocking fee is: $65.34

The value of all merchandise in inventory is: $1,166.20

Here is my program:

InventoryMain.java

package inventorymain;

import java.text.NumberFormat;// used to format currency

import inventorymain.Maker;

publicclass InventoryMain

{

// main method begins execution of java application

publicstaticvoid main(String[] args)

{

//variable for formatting currency

NumberFormat nf = NumberFormat.getCurrencyInstance(java.util.Locale.US);

//create array for products in inventory

Maker []proMaker =new Maker[10];//initializes product array

//enter elements into array

proMaker[0] =new Maker( 1,"pens",1.59,346,"Bic");

proMaker[1] =new Maker( 2,"pencils", .59, 487,"Mead");

proMaker[2] =new Maker( 3,"markers", 1.29, 168,"Sharpie");

proMaker[3] =new Maker( 4,"paperclips", 1.19, 136,"Dennison");

proMaker[4] =new Maker( 5,"glue", .79, 72,"Elmer's");

proMaker[5] =new Maker( 6,"tape", .49, 127,"3m");

proMaker[6] =new Maker( 7,"paper", 1.79, 203,"Mead");

proMaker[7] =new Maker( 8,"staples", 1.19, 164,"Pentech");

proMaker[8] =new Maker( 9,"folders", .49, 238,"Mead");

proMaker[9] =new Maker( 10,"rulers", .17, 123,"Stanley");

for (int i = 0; i < proMaker.length; i++)// for loop displays array elements

{

System.out.println("Product name: " + proMaker[i].getName());//displays product name

System.out.println("Manufacturer: " + proMaker[i].getManufact());//displays product manufacturer

System.out.println("Item number: " + proMaker[i].getNumberCode());//displays product number

System.out.println("Piece's in stock: " + proMaker[i].getUnits());

System.out.println("Unit price : " + nf.format(proMaker[i].getPrice()));//displays price per unit

System.out.println();//enters blank line

}// end for loop

//Sort elements in array in alphabetical order by product name

proMaker[0].sortItems(proMaker);

System.out.println();//inserts blank line

System.out.println();//inserts blank line

System.out.println("**********Alphabetical by product name**********");

System.out.println();//inserts blank line

System.out.println();//inserts blank line

for (int c = 0; c < proMaker.length; c++)

{

System.out.println("Product name: " + proMaker[c].getName());//displays product name

System.out.println("Manufacturer: " + proMaker[c].getManufact());//displays product manufacturer

System.out.println("Item number: " + proMaker[c].getNumberCode());//displays item number

System.out.println("Unit price: " + nf.format (proMaker[c].getPrice()));//displays price per unit

System.out.println("The value of " + proMaker[c].getName() +" left in the inventory, plus a 5% restocking fee is: "+nf.format (proMaker[c].getSum()));//displays inventory product value

System.out.println();//inserts blank line

}//end for loop

System.out.println();//enters blank line

System.out.println("The value of all merchandise in inventory is: " + nf.format (proMaker[0].totalAllInventory(proMaker)));

}//end Main

}//end class InventoryMain

Here is my Inventory.java

package inventorymain;//file assigned to inventorymain package

import java.text.NumberFormat;

import inventorymain.Maker;

publicclass Inventory

{

// set variables

protectedlong numberCode;

protected String productName;

protectedlong productUnits;

protecteddouble unitPrice;

protectedstaticdouble totalAllInventory;

NumberFormat nf = NumberFormat.getCurrencyInstance(java.util.Locale.US);

public Inventory(long itemNum, String name,double price,long units)//varibles for constructor

{

numberCode = itemNum;//variable initialized

productName = name;//variable initialized

productUnits = units;//variable initialized

unitPrice = price;//variable initialized

}

// All setters and getters

public Inventory()

{

numberCode = 0;

}

publicvoid setnumberCode(long itemNum)

{

numberCode = itemNum;

}

publicvoid setName(String name)

{

productName = name;

}

publicvoid setProductUnits(long units)

{

productUnits = units;

}

publicvoid setUnitPrice(double price)

{

unitPrice = price;

}

publiclong getNumberCode()

{

return numberCode;

}

public String getName()

{

return productName;

}

publicdouble getUnits()

{

return productUnits;

}

publicdouble getPrice()

{

return unitPrice;

}

publicdouble totalAllInventory(Inventory []products)

//computes value of all merchandise in inventory

{

double retotal = 0;

for (int i = 0; i < products.length; i++)

{

retotal = retotal + (products[i].getUnits() * products[i].getPrice());

}

return retotal;

}//end method totalAllInventory

publicvoid sortItems(Inventory[] myProducts)

{

int a;

int b;

int sortNames = myProducts.length - 1;

String tempName;

long tempItemNum;

long tempUnits;

double tempPrice;

for (a = 0; a < sortNames; ++a)

for (b = 0; b < sortNames; ++b)

if(myProducts[b].productName.compareTo(myProducts[b + 1].productName) >0)

{

tempName = myProducts[b].productName;

myProducts[b].productName = myProducts[b + 1].productName;

myProducts[b + 1].productName = tempName;

tempItemNum = myProducts[b].numberCode;

myProducts[b].numberCode = myProducts[b + 1].numberCode;

myProducts[b + 1].numberCode = tempItemNum;

tempUnits = myProducts[b].productUnits;

myProducts[b].productUnits = myProducts[b + 1].productUnits;

myProducts[b + 1].productUnits = tempUnits;

tempPrice = myProducts[b].unitPrice;

myProducts[b].unitPrice = myProducts[b + 1].unitPrice;

myProducts[b + 1].unitPrice = tempPrice;

}//end if

}// end class Inventory

}// end class Inventory

_

Here is my subclass Maker.java where the new constructor manufact has been added.

package inventorymain;

publicclass Makerextends Inventory

{

protected String manufact;

public Maker(long itemNum, String name,double price,long units, String manufact)// Constructor for varibles

{

super(itemNum, name, price, units);

this.manufact = manufact;

}

publicvoid setManufact(String manufact)

{

this.manufact = manufact;

}

public String getManufact()

{

return manufact;

}

publicdouble getSum()//method to calculate sum

{

double itemTotal;

double stockFee;

itemTotal = (productUnits * unitPrice);

stockFee = itemTotal + (itemTotal * .05);

return stockFee;

}

}// end of class Maker

__

Hopefully someone can give me some direction. Thank you in advance!

Message was edited by:

javahelp44

Message was edited by:

javahelp44

[17929 byte] By [javahelp44a] at [2007-11-27 8:46:49]
# 1
Sorry all who looked at this post, I thought I had put the code tags in.... Still need advice though!! Thanks
javahelp44a at 2007-7-12 20:50:14 > top of Java-index,Java Essentials,New To Java...
# 2
How is this different than your other thread, and if it isn't, what was wrong with the answers you got there? http://forum.java.sun.com/thread.jspa?threadID=5188352
hunter9000a at 2007-7-12 20:50:14 > top of Java-index,Java Essentials,New To Java...