Welcome to Dream.In.Code
Getting Java Help is Easy!

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




need help debugging programs for final Project

 
Reply to this topicStart new topic

need help debugging programs for final Project

sistanettie
post 10 Oct, 2008 - 07:38 PM
Post #1


New D.I.C Head

*
Joined: 1 Jul, 2008
Posts: 10

I working on my InventoryPart6 final project and I need to get my other programs working correctly. here are the one I submitted for Part5 each of them had errors.

java

//Annette Turner
//InventoryPart5
//Displays GUI

import java.awt.Graphics;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Icon;
import javax.swing.ImageIcon;
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 Inventory4 {

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

{
int i;//variable for looping
double total=0;//variable for total inventory
final int dispProd=0;//variable for actionEvents

//Array Declartion
finalProductAdd[] nwProduct = new ProductAdd[3];

//Instantiate objects for the array
for(i=0;i<3;i++)
{

nwProduct[0]= new ProductAdd("cd","275252j",100,20.60);
nwProduct[1]= new ProductAdd("dvd","9945h",200,10.77);
nwProduct[2]= new ProductAdd("tape","45454k",220,129.95);
}

//Perform Calculations
for(i=0;i<3;i++)
total += nwProduct.length;//calculate total inventory cost

final JButton firstBtn = new JButton("First");
final JButton prevBtn = new JButton("previous");
final JButton nextBtn = new JButton("next");
final JButton lastBtn = new JButton("last");
final JLabel label;//logo
final JTextArea textArea;//area for productlist
final JPanel buttonJPanel;//panel holds buttons

//JLabel constructor for logo
Icon logo = new ImageIcon("C:/logo.jpg");//load logo
label = new JLabel(logo);//create label logo
label.setToolTipText("Company Logo");//create tooltip

buttonJPanel = new MyJPanel();//set up panel
buttonJPanel.setLayout(new GridLayout(1,4));//set layout
//add buttons to buttonPanel
buttonJPanel.add(firstBtn);
buttonJPanel.add(prevBtn);
buttonJPanel.add(nextBtn);
buttonJPanel.add(lastBtn);

textArea = new JTextArea(nwProduct[3]+"\n");//create textArea for product display

//add total inventory value to GUI
textArea.append("/nTotalvalue of Inventory "+new
java.text.DecimalFormat("$0.00").format(total)+"\n\n");
textArea.setEditable(false);
JFrame invFrame = new JFrame();
invFrame.setLayout(new BorderLayout());
invFrame.getContentPane().add(new JScrollPane(textArea),BorderLayout.CENTER);//add textArea to JFrame
invFrame.getContentPane().add(buttonJPanel,BorderLayout.SOUTH);//add buttons to JFrame
invFrame.getContentPane().add(label,BorderLayout.NORTH);
invFrame.setTitle("CD,DVD & Tape inventory");//set JFrame title
invFrame.setDefaultCloseOperations(JFrame.EXIT_ON_CLOSE);//termination command
//invFrame.pack();
invFrame.setSize(600,600);//set size of JPanel
invFrame.setLocationRelativeTo(null);//set screen location
invFrame.setVisible(true);//display window

//assign actionListner and actionEvent for each button
firstBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
textArea.setText(nwProduct[0]+"\n");
}//end firstBtn actionEvent

});//end firstBtn actionListner
textArea.setText(nw Product[3]+"n");
prevBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
textArea.setText(nwProduct[3]+"\n");

}//end prevBtn actionEvent


});//end prevBtn actionListener

textArea.setText(nwProduct[3]+"n");

nextBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
textArea.setText(nwProduct[3]+"\n");
}//end lastBtn actionEvent

});//end lastBtn actionListener
textArea.setText(nwProduct[3]+"n");

//prevBtn.addActionListener(new ActionListener()

//{
// public void actionPerformed(ActionEvent ae)
//{
// dispProd= (nwProduct.length+dispProd-1)% nwProduct.length;
// textArea.setText(nwProduct.display(dispProd+"\n");
//}//end prevBtn actionEvent
//});//end prevBtn actionListener

}//end main
}//end class inventory4



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 GUI{


//main method begins execution of javaApplication
public static void main(final String args[])
{
// create a new GUI object that will display the inventory on the screen
InventoryGUI theGUI = new InventoryGUI();

int i;//variable for looping
double total=0;//variable for total inventory

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

// Instantiate objects for the array
for(i=0;i<3;++)
{

nwProduct[0]= new ProductAdd("cd","275252j",100,20.60);
nwProduct[1]= new ProductAdd("dvd","9945h",200,10.77);
nwProduct[2]= new ProductAdd("tape","45454k",220,129.

//Perform Calculations
for(i=0;i<3;i++)
total += nwProduct.length;//calculate total inventory cost

finalJTextArea textArea;

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

for(i=1;i<3;i++)
{
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


java

//Annette Turner
//Inventory Program


class ProductAdd extends Product
{
private String feature;// variable for added feature

Public ProductAdd(productName,double itemNumber,double itemStock, double ItemPrice,String addFeat)
{
//call to superclass Product constructor
super(name,number,stock,price);

feature = addFeat;

}//end constructor

public void setFeature)String addFeat)//method to add feature
{
feature = addFeat;
}
public double calcValueRstk()//method to set value and restock fee
{
return units * price * 0.10;
}
public String to String()
{

return String.format("Product:%s\nItem Number:%.2f\nRestock Cost:$%.2f\n\n",
getProductName(),getItemNumbers(),getitemStock(),getItemPrice(),getFeature(),cal
c Value(),calc ValueRstk();
}

}//end class productAdd


class MyJPanel extends JPanel
{
//private static Random generator = new Random();
private ImageIcon picture;//image to be displayed

//load image
public MyJPanel()
{
picture = new ImageIcon("mypicture.png");//set icon

}//end MyJPanel constructor

//display imageIcon on panel
public void paintComponent(Graphics g)
{
super.paintComponent(g);
picture.paintIcon(this, g, 0,0);//display icon

}//end method paintComponent

//return image dimensions
//public Dimension getPreferredSize()
{
//return new Dimension (picture.getIconWidth(),
//picture.getIconHeight());

//end method getPreferedSize
//end class MyJPanel



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)

{
ProductName = Name;
ItemNumber = itemNumber;
ItemStock = itemStock;
ItemPrice= itemPrice;
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:");

ProductName = input.next();

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

}
}//End menthod

public void setProductName(String Name)
{
ProductName = Name;
}

public String getName()
{
return ProductName;
}

public void setItemNumber(double Number)
{
ItemNumber= Number;
}

public void getItemNumber()
{
return ItemNumber;
}

public void getItemStock()
{
return ItemStock;
}

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

//get ItemPrice
public double getItemPrice()
{
return ItemPrice;
}

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(ItemStock <= 0)
{

System.out.println("\nPlease enter a positive number.\n");
System.out.println("Number of items in stock");//prompt
ItemStock = 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:");
ItemPrice = input.nextDouble();

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

System.out.println("\nPlease enter a positive number.\n");
System.out.println("Enter price of item:");//prompt
ItemPrice= 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 number:");
ItemNumber = input.nextInt();

}//End method


//perform calculations
public static double ValueOfInventory(double price,itemstock);

{
return price*stock;

}//End method

/*public Sting toString()

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

}*/

}//End class Product


Mod Edit: Please use code tags when posting your code. Code tags are used like so => code.gif

Thanks,
PsychoCoder smile.gif
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 10 Oct, 2008 - 09:29 PM
Post #2


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,914



Thanked 117 times

Dream Kudos: 8475

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


I'm going to move this to the Java forum, where it belongs and can get the proper attention of our Java experts. For future reference, please put programming question in the appropriate language forum, this forum is for Introductions only smile.gif
User is offlineProfile CardPM

Go to the top of the page

pbl
post 11 Oct, 2008 - 02:12 PM
Post #3


D.I.C Lover

Group Icon
Joined: 6 Mar, 2008
Posts: 2,946



Thanked 186 times

Dream Kudos: 75
My Contributions


I can't beleive you went so far in your code without even having the first basic one to work:

By the way.. the variable names in Java are case sensitive

CODE

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)  
  
    {  
     // no parameter Name
     ProductName = Name;           // you probably mean:  productName = productName;
     ItemNumber = itemNumber;  
     ItemStock = itemStock;          // probably itemstock = ItemStock
     ItemPrice= itemPrice;  
     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:");  
  
    ProductName = input.next();      // probably: productName = inputNext();
  
  //Loop terminator for the "stop" check is in the main loop.  
   if(itemName.equalsIgnoreCase("stop"))    // you have an itemNumber that is a double but not any itemName
   {  
       boolflag=true;  
  
   }  
}//End menthod  
  
public void setProductName(String Name)  
{  
  ProductName = Name;       // productName with a small p
}  
  
public String getName()  
{  
  return ProductName;          // productName with a small p
}  
  
public void  setItemNumber(double Number)  
{  
ItemNumber= Number;       // itemNumber with a small i
}  
  
public void getItemNumber()  
{  
  return ItemNumber;           // itemNumber with a small i
}  
  
public void getItemStock()  
{  
  return ItemStock;              // itemstock without I or S
}  
  
public void setItemStock(Double Stock)    
{  
   return ItemStock = Stock;  // itemstock without I or S
}  
  
//get ItemPrice  
public double getItemPrice()  
{  
  return ItemPrice;                 // itemPrice without a I
}  
  
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(ItemStock <= 0)  
{  
  
System.out.println("\nPlease enter a positive number.\n");  
System.out.println("Number of items in stock");//prompt  
ItemStock = 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:");  
   ItemPrice = input.nextDouble();  
  
//set hourly rate  
  while(ItemPrice <= 0)  
  {  
  
  System.out.println("\nPlease enter a positive number.\n");  
  System.out.println("Enter price of item:");//prompt  
  ItemPrice= 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 number:");  
  ItemNumber = input.nextInt();  
  
}//End method  
  
  
//perform calculations  
public static double ValueOfInventory(double price,itemstock);  
  
{  
  return price*stock;  
  
}//End method  
  
/*public Sting toString()

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

}*/  
  
}//End class Product  



How can you think making a ProductAdd class thhat extends Product if Product alone does not compile...

MyPanel is OK


CODE

//main method begins execution of javaApplication  
   public static void main(final String args[])  
   {  
// create a new GUI object that will display the inventory on the screen  
     InventoryGUI theGUI = new InventoryGUI();  


The class InventoryGUI is not defined anywhere

CODE

// Instantiate objects for the array  
    for(i=0;i<3;++)        // it is not ++ but i++
  {  
   // nwProduct is not defined/declared anywhere
   nwProduct[0]= new ProductAdd("cd","275252j",100,20.60);  
   nwProduct[1]= new ProductAdd("dvd","9945h",200,10.77);  
   nwProduct[2]= new ProductAdd("tape","45454k",220,129.   // missing closing ) and;


User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/21/08 09:07AM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month