array development

which info should be in the array?

Page 1 of 1

2 Replies - 1978 Views - Last Post: 10 April 2007 - 07:25 PM Rate Topic: -----

#1 cainxx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-April 07

array development

Posted 10 April 2007 - 06:14 AM

Below is what I submitted for an assignment that required the following:
creat a product class that holds item#, name, units, and price.
display all info as well as the total value of the item inventory.

THEN I had to modify it to:
use an array to store multpile items
display one product's info at a time
and display total full value of inventory.

THEN i had to modify it again to:
create a subclass for one additional feature
create a method to calculate the value of the inventory of a product
with the same name as the method previously created for the
product class.
add a 5% restocking fee to the value of the invetory of that project.

THEN i had to modify it to:
use a GUI to display the info (my instructor commented that I could use a swing JTextField for my text display.)

I look at it and it looks confusing but my instructor said it was ok. I need to know how I can organize my code so that it is more readable, more practical and less cumbersome. I also need help with constructing my arrays; should all the doll names belong to the same array just as the item numbers, etc. OR should all the info for one doll (name, item number, units, etc.) belong to the same array OR am I missing the concept of arrays altogether? (also, my jdk won't download correctly, so I can't really test it.)

// Doll.java
// Doll class represents toy item

public class Doll
{
	private String Name; // doll name
	private double Sku; // sku number
	private double Unit; //quantity in stock
	private double Price; // price per doll
	private double Value; // item inventory value

	// create and output two-dimensional arrays
	public static void main( String agrs[] )
	{
		// five-argument constructor
		public Doll( Name, Sku, Unit, Price, Value );
		{

			//initializes Doll info		
			String Name[] = { "Sara", "Lily", "Hana", "Matt", "Luke", "Seth" }; // array of doll names	
			double Sku [] = { 4000, 4001, 4002, 4003, 4004, 4005 }; // array of sku numbers
			double Unit [] = { 7, 8, 12, 7, 4, 1 }; // array of quantities in stock
			double Price [] = { 150, 150, 275, 150, 250, 125 }; // array of price per doll
			double Value [] = { Unit[0] * Price[0], Unit[1] * Price[1], Unit[2] * Price[2], Unit[3] * Price[3], Unit[4] * 					Price[4], 	Unit[5] * Price[5] }; // array of total value per doll
		
		} // end five-argument constructor
		
		
		// set doll name
		public void setName( String Name )
		{
			Name = Name;
		} // end method setName

		// return doll name
		public String getName()
		{
			return Name;
		} // end method getName

		// set doll sku
		public void setSku( double Sku )
		{
			Sku = Sku;
		} // end method setSku

		// return doll sku
		public double getSku()
		{
			return Sku;
		} // end method getSku

		// set doll unit
		public void setUnit( double Unit )
		{
			Unit = Instock;
		} // end method setUnit

		// return doll unit
		public double getUnit()
		{
			return Unit;
		} // end method getUnit

		// set doll Price
		public void setPrice( double Price )
		{
			Price = Price;
		} // end method setPrice

		// return doll price
		public double getPrice()
		{
			return Price;
		} // end method getPrice

		// calculate inventory value
		public double Value
		{
			return Unit * Price;
		} // end method inventory value

		System.out.prdoublef( "%s%8s%8s%8s\n", "Sku", "Name", "Instock", "Price", "Value" ) // column headings
	
		// return String representation of Doll object
		public String toString ()
		{
			return String.format( "%s: %s\n%s: %s\n%s: %s\n%s: %.2f",
			"Name", Name,
			"Sku", Sku,
			"Instock", Units,
			"Price", Price,
			"Total Item Value", Value );
			
			System.out.prdoubleln();
		} //end method toString
		
		// calculate total inventory value
		for ( double InvValue = 0; InvValue < Value.length; InvValue++ ) total += Value[ InvValue ];

		System.out.prdoubleln( "Total Inventory Value: ", InvValue )

} // end class Doll

// ===================================================================================================
// ===================================================================================================

// EasterOutfitDoll.java
// EasterOutfitDoll inherits from class Doll.

public class EasterOutfitDoll extends Doll
{
	private String outfitColor; // color of outfit
	private double RestockingFee; // restocking fee

	// seven-argument EasterOutfitDoll constructor
	public EaasterOutfitDoll( String Name, double Sku, double Unit, double Price, double Value, String Color, double Restock )

	{
		// explicit call to superclass Doll constructor
		super( Name, Sku, Unit, Price, Value );

		setOutfitColor( color ); // set color
		setRestockingFee( rate ); // set fee
	
	} // end seven-argument EasterOutfitDoll constructor

	// set outfit color
	public void setOutfitColor( String Color )
	{
		outfitColor = ( pink, lilac, yellow, sky, white, apricot )
	} // end method setOutfitColor

	// return outfit color
	public String getOutfitColor()
	{
		return outfitColor;
	} // end method getOutfitColor

		// set restocking fee
	public void setRestockingFee( double Restock )
	{
		restockingFee = ( Price * 0.05 )
	} // end method setRestockingFee

	// return restocking fee
	public double getRestockingFee()
	{
		return restockingFee;
	} // end method getRestockingFee
	
	/ return String representation of Doll object
	public String toString ()
	{
		return String.format( "%s: %s\n%s: %s\n%s: %s\n%s: $%.2f\n%s: $%.2f",
		"Name", Name,
		"Sku", Sku,
		"Instock", Units,
		"Price", Price,
		"Total Item Value: ", Value 
		"Restocking Fee", RestockingFee );
			
		System.out.prdoubleln();
	} //end method toString
		
	// calculate total inventory value
	for ( double InvValue = 0; InvValue < Value.length; InvValue++ ) total += Value[ InvValue ];

	System.out.prdoubleln( "Total Inventory Value: ", InvValue )
	// end method calculate total inventory value

} // end EasterOutfitDoll

// ========================================================================================

// DollInvGUI.java
// Create GUI for Doll Inventory
import javax.swing.JOptionPane; // program uses JOptionPane


public class Inventory
{
	public static void main( String args[] )
	(
		// get user input
		String Name = JOptionPane.showInputDialog( "Please enter doll's name" );
		

		if Name = Sara
		then return String.format( "%s: %s\n%s: %s\n%s: %s\n%s: %.2f",
			"Name", Name,
			"Sku", Sku,
			"Instock", Units,
			"Price", Price,
			"Total Item Value: ", Value 
			"Restocking Fee", RestockingFee );
		else
		if Name = Lily
		then return String.format( "%s: %s\n%s: %s\n%s: %s\n%s: %.2f",
			"Name", Name,
			"Sku", Sku,
			"Instock", Units,
			"Price", Price,
			"Total Item Value: ", Value 
			"Restocking Fee", RestockingFee );
		else
		if Name = Hana
		then return String.format( "%s: %s\n%s: %s\n%s: %s\n%s: %.2f",
			"Name", Name,
			"Sku", Sku,
			"Instock", Units,
			"Price", Price,
			"Total Item Value: ", Value 
			"Restocking Fee", RestockingFee );
		else
		if Name = Matt
		then return String.format( "%s: %s\n%s: %s\n%s: %s\n%s: %.2f",
			"Name", Name,
			"Sku", Sku,
			"Instock", Units,
			"Price", Price,
			"Total Item Value: ", Value 
			"Restocking Fee", RestockingFee );
		else
		if Name = Luke
		then return String.format( "%s: %s\n%s: %s\n%s: %s\n%s: %.2f",
			"Name", Name,
			"Sku", Sku,
			"Instock", Units,
			"Price", Price,
			"Total Item Value: ", Value 
			"Restocking Fee", RestockingFee );
		else
		if Name = Seth
		then return String.format( "%s: %s\n%s: %s\n%s: %s\n%s: %.2f",
			"Name", Name,
			"Sku", Sku,
			"Instock", Units,
			"Price", Price,
			"Total Item Value: ", Value 
			"Restocking Fee", RestockingFee );
		else
		JOptionPane.showMessageDialog( "Please enter a valid Name", JOptionPane.Error_Message );
		
		// end if
		
		// display total inventory value
		JOptionPane.showMessageDialog( "Total Inventory Value: ", + InvValue )
		// end method display total inventory value

	} // end method main
} // end DollInvGUI.java	




After this I still need to modify it again to "add," "delete," and "modify" from the GUI and save it to a specific file as be able to search the info by product name. One last thing: what should I change to allow the item number to serve as the index so that when i add a new item it is created with the a sequential item #.

Is This A Good Question/Topic? 0
  • +

Replies To: array development

#2 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: array development

Posted 10 April 2007 - 06:56 AM

Hi, you could follow THESE hints for a more readable coding in JAVA.
Was This Post Helpful? 0
  • +
  • -

#3 cainxx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-April 07

Re: array development

Posted 10 April 2007 - 07:25 PM

Thanx. Any suggestions on the other issues?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1