cannot find symbol error

I need help identifing the proper object/parameters needed to make thi

Page 1 of 1

1 Replies - 1904 Views - Last Post: 26 September 2009 - 06:35 PM Rate Topic: -----

#1 trillian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 25-August 09

cannot find symbol error

Post icon  Posted 26 September 2009 - 03:23 PM

I need help, I am getting the following error: I think that it is the same problem that I was having before when I was using the wrong parent/child objects and parameter constructors.

Error 1: cannot find symbol Testing4Edit.java 75

   /*added*/
	  tfResFee = new JTextField (p[i].getResFee());
   /*added*/



I think that I am having a difficult time with this I think perhaps because of the way that following code in class CdValue returns the value?:

//method to get restock fee
	 public double getResFee()
	 {
	 return super.getTotalValue() * .05;   
   }



my code:

/ *
  * Purpose: To modify Inventory program to use a GUI
  *
  */

import java.util.*; //imports needed classes
import javax.swing.*; 
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.*;

public class Testing4Edit extends JFrame //uses JFrame for GUI
{
   private JTextField tfTitle, tfGenre, tfPnum, tfQuantity, tfPrice, tfRating; //define variables
   private JLabel lblTitle, lblGenre, lblPnum, lblQuantity, lblPrice, lblRating, lblNext, lblClose;
   private JButton btnNext, btnClose;
   private int i = 0;
   
/*
 *added
 */
   private JTextField tfResFee;
   private JLabel lblResFee;
/*
 *added
 */

   CdValue[] p = new CdValue[1];
   
   public Testing4Edit() //constructor, GUI and classes
   {
	  //Empty placeholder for array of objects

	  p[0] = new CdValue("","",0,0,0.00,""); 
	
	  setTitle("Inventory"); //sets title of JFrame
	  JPanel panel = new JPanel(); //adds JPanel to JFrame

	  panel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
	  panel.setLayout(new GridLayout(4, 2, 2, 2));
	
	  //create JLabels
	  lblTitle = new JLabel ("Title: "); //create label for title
	  lblGenre = new JLabel ("Genre: "); //create label for genre
	  lblPnum = new JLabel ("Product Number: "); //create label for product number
	  lblQuantity = new JLabel ("Product Quantity: "); //create label for quantity
	  lblPrice = new JLabel ("Product Price: "); //create label for price
	  lblRating = new JLabel ("Product Rating: "); //create label for rating
	  
/*
 *added
 */   
	  lblResFee = new JLabel ("Product Restocking Fee: ");//create label for restocking fee
/*
 *added
 */
   
		   lblNext = new JLabel ("Click here to view the next record  ===>"); //create label for rating
	  lblClose = new JLabel ("Click here to close the program  ===> "); //create label for rating
		
	  //create JTextFields for data with constructor data
	  tfTitle = new JTextField(p[i].getTitle());
	  tfGenre = new JTextField(p[i].getGenre());
	  tfPnum = new JFormattedTextField(p[i].getPnum());
	  tfQuantity = new JFormattedTextField(p[i].getQuantity());
	  tfPrice = new JFormattedTextField (p[i].getPrice());
	  tfRating = new JTextField (p[i].getRating());
	  
 /*
 *added
 */
	  tfResFee = new JTextField (p[i].getResFee());
/*
 *added
 */
   
	  //create JButtons
	  btnNext = new JButton("Next"); //create button for selecting next
	  btnClose = new JButton("Close"); //create button for closing program

	  panel.add(lblTitle);//add title label to panel
	  panel.add(tfTitle);//add title textfield to panel

	  panel.add(lblGenre); //Add genre Label To Panel
	  panel.add(tfGenre); //Add genre TextField to Panel

	  panel.add(lblPnum); //Add product number Label To Panel		   
	  panel.add(tfPnum); //Add product number TextField to Panel

	  panel.add(lblQuantity); //Add quantity Label To Panel		   
	  panel.add(tfQuantity); //Add quantity TextField to Panel

	  panel.add(lblPrice); //Add price Label To Panel		   
	  panel.add(tfPrice); //Add price TextField to Panel

	  panel.add(lblRating); //Add rating Label To Panel		   
	  panel.add(tfRating); //Add rating TextField to Panel
	  
/*
 *added
 */
	  panel.add(lblResFee);
	  panel.add(tfResFee);
/*
 *added
 */

	  panel.add(lblNext); //Add next label to Panel
	  panel.add(btnNext); //Add next button to Panel

	  panel.add(lblClose); //Add close label to Panel
	  panel.add(btnClose); //Add close button to Panel

	  add(panel); //Add panel to JFrame

	  ButtonHandler handler = new ButtonHandler(); //instantiate nested class
	  btnNext.addActionListener(handler); // for button click
	  btnClose.addActionListener(handler);//for button click

	  setSize(450, 200); //set JFrame Size

	  setDefaultCloseOperation(EXIT_ON_CLOSE); //default operation on close
	  setLocationRelativeTo(null); //centers on desktop
	  setVisible(true); //allows JFrame to be seen
   } //end constructor
	
   //Method to refresh text feilds
   public void refresh()
   {

	  tfTitle.setText(p[i].getTitle());
	  tfGenre.setText(p[i].getGenre());
	  tfPnum.setText(String.format("%d",p[i].getPnum()));
	  tfQuantity.setText(String.format("%d",p[i].getQuantity()));
	  tfPrice.setText(String.format("$%.2f",p[i].getPrice()));
	  tfRating.setText(p[i].getRating());

/*
 *added
 */
	  tfResFee.setText(String.format("$%.2f",p[i].getResFee()));
/*
 *added
 */
   }
	
   //method accepts array of Product objects into GUI and replaces
   //temporary array of 3 objects with passes (parameter) array

   public void addProd(CdValue[] prod)
   {
	  //assign object array memory location to passed object array
	  //memory location
	  this.p = prod;
	  refresh(); //refresh view
   }
   	
   //class handler for button clicks
   private class ButtonHandler implements ActionListener
   {
	  //private void actionPerformed(ActionEvent event) //check action
	  /*
	   * actionPerformed NEEDS TO BE public 
	   */
	  public void actionPerformed(ActionEvent event) //check action
	  {
		 //buton logic
		 if(event.getSource() == btnClose)//verify Close Button clicked
		 System.exit(0); //exit

		 if(event.getSource() == btnNext)
		 {
			//apply logic for next button clicks
			if(i==0)
			{
			   ++i;
			}
			else if(i==p.length-1)
			{
			   i = p.length-1;
			}
			else
			{
			   ++i;
			}
		 }//end if

		 refresh();  //refresh data view
	  }//end method
   }//end class
	
   public static void main(String[] args)
   {
	  //create testing object which calls constructor creating GUI
	  Testing4Edit gui = new Testing4Edit();

	  //create array product class objects	  
	  CdValue[] cd = new CdValue[3];
	  cd[0] = new CdValue("Elvis", "Country", 1, 10, 9.99, "PG");
	  cd[1] = new CdValue("Stanley", "Country", 2, 50, 19.99, "PG13");
	  cd[2] = new CdValue("Jane", "Rock", 3, 15, 15.99, "PG13");
	  
	  //*** PASS cd ARRAY INTO METHOD
	  gui.addProd(cd);
	} //end main
	
} //end class

class Product implements Comparable
{
	private String title; //Define variables
	private String genre;
	private int pnum;
	private int quantity;
	private double price;
	private double totalValue;

	public Product(){}
	
	/** 
	 * CREATED CONSTRUCTOR TO ACCEPT 5 PARAMETERS
	 */
	public Product(String title,String genre, int pnum, int quantity, double price)
	{
		this.title = title;
		this.genre = genre;
		this.pnum = pnum;
		this.quantity=quantity;
		this.price = price;
	 }
	
	public String getTitle()
	{
		return title;
	}
	public void setTitle(String title)
	{
		this.title = title;
	}
	public String getGenre()
	{
		return genre;
	}
	public void setGenre(String genre)
	{
		this.genre = genre;
	}
	public int getPnum()
	{
		return pnum;
	}
	public void setPnum(int pnum)
	{
		this.pnum = pnum;
	}
	public int getQuantity()
	{
		return quantity;
	}
	public void setQuantity(int quantity)
	{
		this.quantity = quantity;
	}
	public double getPrice()
	{
		return price;
	}
	public void setPrice(double price)
	{
		this.price = price;
	}
	
	public double getTotalValue()
	{
	 return totalValue = price * quantity;
	}
	
	//*** METHOD ACCEPTS ARRAY OF Product OBJECTS AS PARAMETER 
	public static double totalInventory(Product[] p)
	{	
		double combined=0; //initialize
		
		for(int i=0; i < p.length;++i){ //loop to combine object values
			combined += p[i].getTotalValue();} 
		
		return combined;	   //return combined 
	}
	
	public int compareTo(Object product)throws ClassCastException
	{
			String title1 = ((Product)this).getTitle().toUpperCase();
		  String title2 = ((Product)product).getTitle().toUpperCase();

		return this.title.compareTo(title2);			
	}
	
}

//A subclass of the product class that uses one additional feature.
//Returns the value of the restocking fee.
class CdValue extends Product
{
	 private String rating;	
	 
	 //*** public double productValue;
	private double resFee; 

	public CdValue()
	 {
		super();

	 } //no parameter constructor
	 
	/** 
	 * CREATED CONSTRUCTOR TO ACCEPT 6 PARAMETERS
	 */
	public CdValue(String title,String genre, int pnum, int quantity, double price, String rating)
	{
		super(title,genre,pnum,quantity,price); //PASS TO CREATE 5 PARAM PARENT 
		this.rating = rating;
	}
	
	 
	 //method to set Rating
	 public void setRating(String rating)
	 {
		 this.rating = rating; 
	 }
	 
	 //method to get Rating
	 public String getRating()
	 {
		 return rating;
	 }
	 
	 //method to get restock fee
	 public double getResFee()
	 {
			  return super.getTotalValue() * .05;   
	  }
	  
	  //method overriding product class method
	  // to calc value with 5% restocking fee added
	  public double getTotalValue()
	 {
			  return super.getTotalValue() * 1.05;   
	  }	

} //end class



Is This A Good Question/Topic? 0
  • +

Replies To: cannot find symbol error

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: cannot find symbol error

Posted 26 September 2009 - 06:35 PM

Here are the constructors for JTextField

JTextField()
Constructs a new TextField.
JTextField(Document doc, String text, int columns)
Constructs a new JTextField that uses the given text storage model and the given number of columns.
JTextField(int columns)
Constructs a new empty TextField with the specified number of columns.
JTextField(String text)
Constructs a new TextField initialized with the specified text.
JTextField(String text, int columns)
Constructs a new TextField initialized with the specified text and columns.

as you can see none of them expect a double as parameter
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1