Welcome to Dream.In.Code
Become a Java Expert!

Join 150,186 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,073 people online right now. Registration is fast and FREE... Join Now!




Help with InventoryPart4

 
Reply to this topicStart new topic

Help with InventoryPart4, Totally confused

sistanettie
30 Sep, 2008 - 07:59 PM
Post #1

New D.I.C Head
*

Joined: 1 Jul, 2008
Posts: 10

I have posted Inventory 3 , 3a and 4 . I really need help . I'm getting l error message for Inventory 3 both parts. and 9 errors of Inventory 4. and I can't figure out how to get rid of them. Below are the programs

java

//Annette Turner
//Product.java


import java.util.Scanner;

public class Product
{
// declare variable
private String productName;
private double itemNumber;
public double itemstock;
private double totalinStock;
private double itemPrice;
private double value;
public static Int intCounter=0;
public boolean boolflag;


//Instantiate the Scanner for STDIN input.
Scanner input = new Scanner(System.in);

public Product(String ProductName, double ItemNumber, double ItemStock, double ItemPrice)

{
StringProductName = StringName;
ItemNumber = ItemNumber;
ItemStock = ItemStock;
double ItemPrice= doubleItemPrice;
intCounter++;

}//end constructor

//Product inventory[] = new Product[3];
//public to ensure other components or classes can utilize this method.
public void GetNameVal()

{

System.out.println("\nPlease enter product name:");

StringProductName = input.next();

//Loop terminator for the "stop" check is in the main loop.
if(StringItemName.equalsIgnoreCase("stop"))
{
boolFlag=true;

}
}//End menthod

public void SetProductName(String Name)
{
StringProductName = Name;
}

public String GetName()
{
return StringProductName;
}

public void Double SetItemNumber(double Number);
{
intItemNumber= Number;
}

public int GetItemNumber()
{
return intItemNumber;
}

// Get ItemStock
public void GetItemStock()
{

return ItemStock;
}

public void SetItemStock(Double Stock)
{
return ItemStock = Stock;
}

//Get ItemPrice
public double GetItemPrice()
{
return doubleItemPrice;
}

public void SetPrice(Double Price);
{
ItemPrice = Price;

}
//public to ensure other components or classes can utilize this method.
public void GetItemStockVal()

{

System.out.println("Please enter amount in stock:");
ItemStock= input.nextInt();

//Set hourly rate
while(intItemStock <= o)
{

System.out.println("\nPlease enter a positive number.\n");
System.out.println("Number of items in stock");//prompt
intItemStock = input.nextint();//read hourly rate

}//End while


}//End method


//public to ensure other components or classes can utilize this method.
public void GetItemPriceval()
{

System.out.println("Please enter item price:");
doubleItemPrice = input.nextDouble();

//set hourly rate
while(doubleItemPrice <= 0)
{

System.out.println("\nPlease enter a positive number.\n");
System.out.println("Enter price of item:");//prompt
doubleItemPrice= input.nextDouble();//read hourly rate

}//End while

}//End Method

//public to ensure othe components or classes can utilize this method.
public void GetItemNumberVal()
{

System.out.println("Please enter item product number:");
intItemNumber = input.nextInt();

}//End method


//perform calculations
public static double valueOfInventory(double price,int stock)

{
return price*stock;

}//End method

/*public Sting toString()

{
return new StringBuffer().append("Price:" + GetItemPrice()00.toString();

}*/

}//End class


java

//Annette Turner
//InventoryPart3a subclass


public class Inventory extends Product {

// This class extends Product and adds its own value
// In our case its a restocking fee
private double dblStockingFee;
private double dblItemPrice;

//Instantiate the Scanner
Scanner input= new Scanner(System.in);

//five-argument constructor
public void inventory(intItemNumber, String strProductName,int intItemStock,double dblItemPrice,double dblStockingFee);
{

//calling parent class
super(intItemNumber,StringProductName,intItemStock, doubleItemPrice);

//set restocking fee
this.dblStockingFee = dblStockingFee;
}

//return CD price

// Calculate price
public double getItemPrice()
{
double dblCheckfee;

doubleCheckfee=super.GetItemPrice()*dblStockingFee;

System.out.printf("This inventory item hasis caculated with a restocking fee of: %.2f\n",doubleStockingFee);
return (super.GetItemPrice()+ doubleCheckFee);
}


public String ShowInventory(){

return new StringBuffer().append("Price:"+ super.GetUnitPrice()).append("With RestockingFee:"+ GetItemPrice()).toString();

}
}


java

//Annette Turner
//InventoryPart4
//Program displays GUI

import java.util.Arrays;
import java.awt.FlowLayout;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JtextArea;

public class Iventory
{

//main method begins execution of javaApplication
public static void main(final String args[])
{

int intCounter;
double dblTotalVal=0;

//Array Declartion
Product Inventory[] =new Product[3];

// Instantiate objects for the array
for(intCounter=0;intCounter < Inventory.length; intCounter++)
{

Inventory[0]=new Product("cd", "275252j", 100,20,60);
Inventory[1]=new Product("dvd","9945h",200.10,77);
Inventory[2]=new Product("tape","45454k", 220,129,95);
}

//Perform Calculations
for(intCounter=0;intCounter< Inventory.length;intCounter++)
dblTotalVal += Inventory[intCounter].PerformCalc();

final JTextArea textArea;

textArea = new JTextArea(Inventory[0]+"\n");

for(intCounter=1;intCounter< Inventory.length;intCounter++)
{
textArea.append(Inventory[intCounter]+"\n");
}

//Total Inventory Value
textArea.append("Total Inventory Value"+ new java.text.DecimalFormat("$0.00").format(dblTotalVal)+"\n\n");
textArea.setEditable(false);


//Settings
JFrame winWindow = new JFrame();
winWindow.setLayout(new BorderLayout());
winWindow.setLayout(new FlowLayout());
winWindow.getContentPane().add(new JScrollPane(textArea),BorderLayout.CENTER);
winWindow.setTitle("Inventory");
winWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
winWindow.setSize(800,800);
winWindow.setVisible(true);

}//End main

}//End class Inventory


*edit: Please use code tags in the future, thanks! code.gif

This post has been edited by Martyr2: 30 Sep, 2008 - 08:20 PM
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Help With InventoryPart4
30 Sep, 2008 - 08:34 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
You have lots of issues here. The biggest one is your naming scheme here. Why do you have a class called "inventory" extending from product? Inventory should be the the class that wraps around an array of products. Here is the hierarchy...

1) Define a product class
2) Extend the product as a specific type of product (aka a DVD, movie etc)
3) You have an inventory class that CONTAINS an array of product classes and has methods to accessing those products including "add" and "getInventoryValue" which would return the sum of all product values.
4) Your GUI will then interact with the inventory class so that buttons call the individual methods of the inventory class. An "add" button would collect data and give it to the inventory class' "add" method.

So what I am seeing in the main method here (defining of the product array, calculating of the inventory value etc) should be done inside the inventory class. The main function should contain...

1) Defining a variable of the type "inventory"
2) Creating your GUI (whether it be the controls directly or a GUI class)
3) Events of that GUI being attached to the methods of the inventory class.

So where to start? I would start by checking out my blog at the link below....

Martyr2's Programming Underground - Parts 1-3 of Product/Inventory Project

I would look at part 3 in particular where I create the inventory class and you will notice how I create an array of products called "items" and then I introduce an "add" function which will add products to the array. I also have a function called getTotalInvValue() which gets the total value of all products in the array and returns the sum.

Make sure that your inventory portion is completed before moving onto the GUI because your GUI is going to rely on this class to make sure it works properly. Without it being proper, your GUI is going to face a bunch of problems.

Hope that helps. smile.gif
User is offlineProfile CardPM
+Quote Post

pbl
RE: Help With InventoryPart4
30 Sep, 2008 - 08:49 PM
Post #3

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
Oups... not easy to follow you.... having a class named Iventory and a class name Inventory does not dimplify the problrm...
your are masochist or what ?

OK a few remarks:

public static Int intCounter=0;

you probaly mean

public static int intCounter=0;

StringProductName = StringName;

productName = StringName;

ItemNumber = ItemNumber;
ItemStock = ItemStock;

you probaly mean

itemNumber = ItemNumber;
itemStock = ItemStock;

double ItemPrice= doubleItemPrice;

you probaly mean

itemPrice= ItemPrice;


StringProductName = input.next();

probably wanted to mean


String ProductName = input.next();

public void SetProductName(String Name)
{
StringProductName = Name;
}

should be
public void SetProductName(String Name)
{
String ProductName = Name;
}


public void Double SetItemNumber(double Number);
{
intItemNumber= Number;
}

should be (cannot be void and double at the same time)

public void SetItemNumber(double Number);
{
temNumber= Number;
}



itemNumber is a double can't be returned as a int

public int GetItemNumber()
{
return itemNumber;
}

should be

public double GetItemNumber()
{
return itemNumber;
}


// Get ItemStock
public void GetItemStock()
{

return ItemStock; // the variable name is itemStock not ItemStock Java is case sensitive
}

ouff... that should keep you busy for a while


User is offlineProfile CardPM
+Quote Post

sistanettie
RE: Help With InventoryPart4
9 Oct, 2008 - 07:04 PM
Post #4

New D.I.C Head
*

Joined: 1 Jul, 2008
Posts: 10

QUOTE(Martyr2 @ 30 Sep, 2008 - 09:34 PM) *

You have lots of issues here. The biggest one is your naming scheme here. Why do you have a class called "inventory" extending from product? Inventory should be the the class that wraps around an array of products. Here is the hierarchy...

1) Define a product class
2) Extend the product as a specific type of product (aka a DVD, movie etc)
3) You have an inventory class that CONTAINS an array of product classes and has methods to accessing those products including "add" and "getInventoryValue" which would return the sum of all product values.
4) Your GUI will then interact with the inventory class so that buttons call the individual methods of the inventory class. An "add" button would collect data and give it to the inventory class' "add" method.

So what I am seeing in the main method here (defining of the product array, calculating of the inventory value etc) should be done inside the inventory class. The main function should contain...

1) Defining a variable of the type "inventory"
2) Creating your GUI (whether it be the controls directly or a GUI class)
3) Events of that GUI being attached to the methods of the inventory class.

So where to start? I would start by checking out my blog at the link below....

Martyr2's Programming Underground - Parts 1-3 of Product/Inventory Project

I would look at part 3 in particular where I create the inventory class and you will notice how I create an array of products called "items" and then I introduce an "add" function which will add products to the array. I also have a function called getTotalInvValue() which gets the total value of all products in the array and returns the sum.

Make sure that your inventory portion is completed before moving onto the GUI because your GUI is going to rely on this class to make sure it works properly. Without it being proper, your GUI is going to face a bunch of problems.

Hope that helps. smile.gif



QUOTE(Martyr2 @ 30 Sep, 2008 - 09:34 PM) *

You have lots of issues here. The biggest one is your naming scheme here. Why do you have a class called "inventory" extending from product? Inventory should be the the class that wraps around an array of products. Here is the hierarchy...

1) Define a product class
2) Extend the product as a specific type of product (aka a DVD, movie etc)
3) You have an inventory class that CONTAINS an array of product classes and has methods to accessing those products including "add" and "getInventoryValue" which would return the sum of all product values.
4) Your GUI will then interact with the inventory class so that buttons call the individual methods of the inventory class. An "add" button would collect data and give it to the inventory class' "add" method.

So what I am seeing in the main method here (defining of the product array, calculating of the inventory value etc) should be done inside the inventory class. The main function should contain...

1) Defining a variable of the type "inventory"
2) Creating your GUI (whether it be the controls directly or a GUI class)
3) Events of that GUI being attached to the methods of the inventory class.

So where to start? I would start by checking out my blog at the link below....

Martyr2's Programming Underground - Parts 1-3 of Product/Inventory Project

I would look at part 3 in particular where I create the inventory class and you will notice how I create an array of products called "items" and then I introduce an "add" function which will add products to the array. I also have a function called getTotalInvValue() which gets the total value of all products in the array and returns the sum.

Make sure that your inventory portion is completed before moving onto the GUI because your GUI is going to rely on this class to make sure it works properly. Without it being proper, your GUI is going to face a bunch of problems.

Hope that helps. smile.gif



QUOTE(Martyr2 @ 30 Sep, 2008 - 09:34 PM) *

You have lots of issues here. The biggest one is your naming scheme here. Why do you have a class called "inventory" extending from product? Inventory should be the the class that wraps around an array of products. Here is the hierarchy...

1) Define a product class
2) Extend the product as a specific type of product (aka a DVD, movie etc)
3) You have an inventory class that CONTAINS an array of product classes and has methods to accessing those products including "add" and "getInventoryValue" which would return the sum of all product values.
4) Your GUI will then interact with the inventory class so that buttons call the individual methods of the inventory class. An "add" button would collect data and give it to the inventory class' "add" method.

So what I am seeing in the main method here (defining of the product array, calculating of the inventory value etc) should be done inside the inventory class. The main function should contain...

1) Defining a variable of the type "inventory"
2) Creating your GUI (whether it be the controls directly or a GUI class)
3) Events of that GUI being attached to the methods of the inventory class.

So where to start? I would start by checking out my blog at the link below....

Martyr2's Programming Underground - Parts 1-3 of Product/Inventory Project

I would look at part 3 in particular where I create the inventory class and you will notice how I create an array of products called "items" and then I introduce an "add" function which will add products to the array. I also have a function called getTotalInvValue() which gets the total value of all products in the array and returns the sum.

Make sure that your inventory portion is completed before moving onto the GUI because your GUI is going to rely on this class to make sure it works properly. Without it being proper, your GUI is going to face a bunch of problems.

Hope that helps. smile.gif


User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Help With InventoryPart4
9 Oct, 2008 - 07:06 PM
Post #5

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Yes, that is what I had said.... apparently three times. tongue.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 04:07AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month