Modify the Inventory Program:


Create a new method that calculates the value of the entire inventory.

Create another method that sorts all of the array items alphabetically (ascending order) by the product name.

o The application should declare and use an array to store 5 items. This array will represent your product’s inventory. Use the constructor in your Supplier class to create 3 new objects. Use the constructor in your Printer class to create 2 new objects. Note: You will provide the values for the constructor yourself. You will not prompt the user to enter this data. Add the objects created in step 2 to your array. Call your sortArray method to sort the array.

Display the following information for EACH item in your array:
o the product number;
o the name of the product,
o the number of units in stock,
o the price of each unit;
o and the value of the inventory (the number of units in stock multiplied by the price of each unit)
o Supplier Name *
o Restock Fee *


o Create a subclass of the selected inventory item. Recall that the extends keyword is used to create an inheritance relationship.

 The subclass and existing class must past the is-a test.

 The subclass must declare one applicable attribute along with the appropriate get and set methods.

 The subclass must declare a method to calculate the restocking fee. The restocking fee should be calculated as 5% of the item’s price.

o The application’s output should display all of the items in the inventory sorted (use the new sort method) and include the item number, the name of the product, the number of units in stock, the price of each unit, the new attribute, the restock fee and the value of the inventory of that product. In addition, the output should display the value of the entire inventory (use the new method to achieve this). All dollar values should be displayed as currency (i.e. $D,DDD.CC). Note: You must use an Array to store your inventory items, the use of any other data structure will result in a significant point deduction.


I think the code I have written for the object is correct, Monitors.java, since it compiles, but I will include it as well. I am having trouble with the main programming to include the array and then it has to print the values and calculations and as such it is unfinished. If someone would be so kind as to point me in the right direction or offer advice, I'd be very much obliged. Thanks in advance.

// Monitors.java
// Inventories monitors by the item number, the name of the product,
// the number of units in stock, and the price of each unit for the
// selected product
// Stephanie Masech
// 3/4/2012

public class Monitors
	{
	private int idNumber;
	private String productName;
	private int productCount;
	private double productPrice;
	public String storeName;

		public Monitors (int number, String name, int count, double price)
			{
			this.idNumber = number;
			this.productName = name;
			this.setProductCount(count);
			this.setProductPrice(price);
			}


public double calculateValue()
		{
		    return productCount * productPrice;
     	}

public void setIdNumber (int number)
		{
			this.idNumber = idNumber;
		}

public double getIdNumber()
		{
			return idNumber;
		}

public void setProductName (String name)
		{
			this.productName = productName;
		}

public String getProductName()
		{
			return productName;
		}

public void setProductCount (int count)
		{
			this.productCount = count;
		}

public double getProductCount()
		{
			return productCount;
		}

public void setProductPrice (double price)
		{
			this.productPrice = price;
		}

public double getProductPrice()
		{
			return productPrice;
		}

}

class Store extends Monitors{

private String storeName;

		public Store(int number, String name, int count, double price, String storeName)
		{
			super(number, name, count, price);
			this.storeName = storeName;
			Monitors example4 = new Monitors(8946, "Acer 19'' Plasma Flatpanel", 3, 124.79, "Walmart");
			Monitors example5 = new Monitors(9406, "Samsung 20'' LCD Flatpanel", 8, 191.99, "Best Buy");
		}

}
// InventoryPart1.java
// Inventories monitors by the item number, the name of the product,
// the number of units in stock, and the price of each unit for the
// selected product
// Stephanie Masech
// 3/4/2012

import java.util.Arrays;

public class InventoryPart2
{

double total;

	public static void main( String[] args )
	     {

			Monitors[] example = new Monitors[5];

			Monitors example1 = new Monitors(8701, "Dell 22'' LCD Flatpanel", 6, 156.99);
			Monitors example2 = new Monitors(9049, "HP 19'' CRT", 2, 120.99);
			Monitors example3 = new Monitors(3952, "LG 21'' LED Superflat", 9, 225.99);
		}


			System.out.println( "Information on monitors." );
			System.out.println();
			System.out.printf( "%s %.0f\n", "Product ID number:	",
				inventory.getIdNumber() );
			System.out.printf( "%s %s\n", "Product name:		",
			    inventory[].getProductName() );
			System.out.printf( "%s %.0f\n", "Total in stock:		",
			    inventory[].getProductCount() );
			System.out.printf( "%s %$.2f\n", "Price per unit:		",
			 	inventory[].getProductPrice() );
			System.out.printf( "%s %$.2f\n", "Total price of stock:	",
				inventory[].getTotalPrice() );
            System.out.println();



						}

Edited 4 Years Ago by Zennie2005: Tweak

I am having trouble with the main programming

Please explain your problems.
Copy any error messages and paste them here.
If the program's output is not what you want, copy the output here and add comments describing what is wrong with it.

Hi NormR1, I am having issues with implimenting an array from both class files and then sorting it. I stated I do not have a finished Inventory code. I wanted to see if I might have been on the right track with an array for it.

I am having issues with implimenting an array

Please ask some questions or explain what your problem is?
What does the program currently do?
Does it compile? If not, post the errors.
Does it execute without errors? if not post the errors.
Does it generate the wrong output? Post the output and explain what it should be.

Alright, how about this. With the product class Monitors.java, I am supposed to create two objects which will be used in the array created in the main program. If the other three are created in the main, and the last two in Monitors.java, how would it be written? This is what I have written in an attempt to fold it into the array, and the errors I got trying to compile will follow:

public class Monitors
	{
	private int idNumber;
	private String productName;
	private int productCount;
	private double productPrice;
	public String storeName;

		public Monitors (int number, String name, int count, double price, String storeName)
			{
			this.idNumber = number;
			this.productName = name;
			this.setProductCount(count);
			this.setProductPrice(price);
			}


public double calculateValue()
		{
		    return productCount * productPrice;
     	}

public void setIdNumber (int number)
		{
			this.idNumber = idNumber;
		}

public double getIdNumber()
		{
			return idNumber;
		}

public void setProductName (String name)
		{
			this.productName = productName;
		}

public String getProductName()
		{
			return productName;
		}

public void setProductCount (int count)
		{
			this.productCount = count;
		}

public double getProductCount()
		{
			return productCount;
		}

public void setProductPrice (double price)
		{
			this.productPrice = price;
		}

public double getProductPrice()
		{
			return productPrice;
		}

}

class Store extends Monitors{

private String storeName;

		public Store(int number, String name, int count, double price, String store)
		{
			super(number, name, count, price, store);
			this.storeName = store;
			Monitors example[3] = new Monitors(8946, "Acer 19'' Plasma Flatpanel", 3, 124.79, "Walmart");
			Monitors example[4] = new Monitors(9406, "Samsung 20'' LCD Flatpanel", 8, 191.99, "Best Buy");
		}

}

Errors:

C:\Users\petes\Desktop\IT 215\Monitors.java:80: error: ']' expected
Monitors example[3] = new Monitors(8946, "Acer 19'' Plasma Flatpanel", 3, 124.79, "Walmart");
^
C:\Users\petes\Desktop\IT 215\Monitors.java:80: error: illegal start of expression
Monitors example[3] = new Monitors(8946, "Acer 19'' Plasma Flatpanel", 3, 124.79, "Walmart");
^
C:\Users\petes\Desktop\IT 215\Monitors.java:81: error: ']' expected
Monitors example[4] = new Monitors(9406, "Samsung 20'' LCD Flatpanel", 8, 191.99, "Best Buy");
^
C:\Users\petes\Desktop\IT 215\Monitors.java:81: error: illegal start of expression
Monitors example[4] = new Monitors(9406, "Samsung 20'' LCD Flatpanel", 8, 191.99, "Best Buy");
^
4 errors

Was this response any better? Thanks for taking the time to help.

Edited 4 Years Ago by Zennie2005: n/a

take objects out of two different class files

What does "take objects out" mean? Is this a source file change or is this something you want the program to do when it executes?

Monitors example[3] = new Monitors(..

What are you trying to do here?
The syntax is wrong. It starts out looking like an array definition:

Monitors example[

which would look like this:

Monitors example[] = new Monitors[3];

The compiler was looking for a ] after the [ error: ']' expected

If you mean it to be an assignment statement remove the leading Monitors

Edited 4 Years Ago by NormR1: n/a

NormR1, the Monitors class is supposed to create two of the items in the array that is in the main program. Do I create an array specifically in Monitors that will be called upon in the main program with the array line?

Monitors example[] = new Monitors[3];

You need to define the size of an array before you can assign values to it.
You should define any arrays that you want to exist after the method exits outside of the method. Any variables defined in a method go away when the array exits.
This defines an array: Classname[] varName; // do at class level
this gives it a size: varName = new ClassName[5]; // can do in a method

Its size will be determined by how many objects are you going to put into the array.

Read up in the tutorial:
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

Okay... so I would need to write this, right?

String[] monitorArray

           example[] = new monitorArray[5];

		Monitors example[0] = new Monitors(8701, "Dell 22'' LCD Flatpanel", 6, 156.99);
		Monitors example[1] = new Monitors(9049, "HP 19'' CRT", 2, 120.99);
		Monitors example[2] = new Monitors(3952, "LG 21'' LED Superflat", 9, 225.99);

Past that I am not sure how you would write an array with multiple formats. String is the best I could come up with following the Oracle tutorial, of which I have seen already, thank you.

This code looks like it has the same error that it had before.
It is mixing the syntax for defining a variable with that for assign a value to a variable.
Remove the leading Monitors on line 6-8 to make the statements valid assignment statements.

What error messages does the compiler give you for the code you posted?

Edited 4 Years Ago by NormR1: n/a

Instructor has posted the right way to right the code, so I will take notes from her example. Thank you so much for helping me out, though, I really appreciate it! Have a good day!

This question has already been answered. Start a new discussion instead.