Here's problem # 1: My program has multiple arrays respectively containing int, double, and String variables. I was able to sort the String array that contained the names of the product; however, I do not know of a method that allows the other arrays to follow the same sort. Because of my problem, when the name array is sorted, the inventory information becomes missed mismatched. I want to know if it is possible to have the other arrays follow the same sort. I read a little about multi-dimensional arrays; however, I do not think that will help my situation because I think that the arrays cannot have more than one variable type.
Here's problem # 2: I have no idea what a subclass is or how to make it perform what my assignment requires. The wording for the assignment is confusing and I hope someone can give me an idea of what it's about. I do know how to create a way to add 5% to the restocking fee; by multiplying 0.05 to the value, then adding that product to the value. However, I do not think that's what the assignment wants.
My program is in two classes. TransformersInventory2 is the main class, TransformersProduct is the product class.
Please someone help! This assignment is due tomorrow and I no one experienced in Java. What's worst is that I am learning online. I cannot go to my teacher for help or get help from my classmates (I mean you can post to them like how I am doing here; however, it doesn't appear they want to help or they probably lost as well.
Below are the codes:
import java.util.Arrays;
// class declaration for TransformersInventory
public class TransformersInventory2
{
// main method begins program execution
public static void main( String args[] )
{
// declare array name autobotNameArray
String autobotNameArray[] = { "Hidden Autobot", "Optimus Prime", "BumbleBee",
"Ironhide", "Ratchet", "Jazz" };
Arrays.sort( autobotNameArray, String.CASE_INSENSITIVE_ORDER );
int autobotProductArray[] = { 0, 7, 16, 25, 34, 43 }, // product # array
//autobotUnitArray[] = { 0, 52, 61, 106, 115, 124 }; // array of autobot toy units
double autobotPriceArray[] = { 0.00, 160.99, 97.99, 88.99, 79.99,70.99 }, // array of autobot toy prices
autobotStockArray[] = { autobotUnitArray[0] * autobotPriceArray[0],
autobotUnitArray[1] * autobotPriceArray[1],
autobotUnitArray[2] * autobotPriceArray[2],
autobotUnitArray[3] * autobotPriceArray[3],
autobotUnitArray[4] * autobotPriceArray[4],
autobotUnitArray[5] * autobotPriceArray[5] }; // array of autobot stock values
TransformersProduct myTransformers = new TransformersProduct( "Transformers Autobot Toy Inventory" ,
autobotNameArray, autobotProductArray,
autobotUnitArray, autobotPriceArray,
autobotStockArray );
myTransformers.displayMessage();
myTransformers.processInventory();
} //end main
} // end class TransformersInventory2
import static java.lang.System.out;
// class declaration for TransformersProduct
public class TransformersProduct
{
private String inventoryName; // name of inventory
private String autobotName[]; // array of autobot toy names
private int product[]; // product # array
private int unit[]; // array of autobot toy units
private double price[]; // array of autobot prices
private double stock[]; // array of autobot stock values
/* six-argument constructor initializes name inventoryName,
*autobotName, product unit, price and stock arrays. */
public TransformersProduct ( String name, String autobotNameArray[],
int autobotProductArray[], int autobotUnitArray[],
double autobotPriceArray[], double autobotStockArray[] )
{
inventoryName = name; // initialize inventoryName
autobotName = autobotNameArray; // initialize autobotName
product = autobotProductArray; // initialize product
unit = autobotUnitArray; // initialize unit
price = autobotPriceArray; // initialize price
stock = autobotStockArray; // initialize stock
} // end six-argument TransformersProduct constructor
// method to set the inventory name
public void setInventoryName ( String name )
{
inventoryName = name; // store inventory name
} // end method setInventoryName
// method to retrieve the inventory name
public String getInventoryName()
{
return inventoryName; //
} // end method getInventoryName
// display a welcome message to the TransformersInventory2 user
public void displayMessage()
{
// getInventoryName gets the name of the inventory
out.printf( "Welcome to the\n%s!\n\n",
getInventoryName() );
} // end method displayMessage
//method to display the invertory arrays output
public void processInventory()
{
// output inventory arrays
outputInventory();
} // end method processInventory
// output inventory arrays
public void outputInventory()
{
// displays available inventory message
out.println( "Below is the available inventory:\n" );
// create column headings
out.print( "Index\tProduct #\t\t\tName\t\tUnits\t\tPrice\t\t" );
out.println( "Stock Value" ); // create Stock Value column
// output each arrays' elements' value
for ( int toyCounter = 0; toyCounter < autobotName.length; toyCounter++)
out.printf( "\n%5d%12d%27s%17d $%7.2f $%10.2f\n",
toyCounter, product[ toyCounter ], autobotName[ toyCounter ],
unit[ toyCounter ], price[ toyCounter ], stock[ toyCounter ] );
// calculate entire inventory value
double totalStockValue = stock[1] + stock[2] + stock[3] + stock[4] + stock[5];
out.printf( "\nThe value of the entire inventory is $ %.2f\n", totalStockValue );
} // end outputInventory
} // end class TransformersProduct
~edit code tags PB
This post has been edited by PennyBoki: 28 October 2007 - 05:02 AM

New Topic/Question
Reply




MultiQuote






|