Results 1 to 2 of 2
Thread: error with super.xxxxx
- 08-05-2007, 09:34 PM #1
Member
- Join Date
- Aug 2007
- Posts
- 20
- Rep Power
- 0
error with super.xxxxx
i'm attempting to create a child class that passes data to the parent class's method or constructor. I get the following error when compiling:
G:\Chair.java:54: cannot find symbol
symbol : method Item(int,float,java.lang.String)
location: class Item
super.Item(passchair, passchair_cost, passname);
^
1 error
Tool completed with exit code 1
this is the chair.java file:
Java Code:import javax.swing.*; public class Chair extends Item{ private int chair1; private float chair1_cost; private String name; public Chair(){ } public Chair(int chair1, float chair1_cost, String name){ this.chair1 = chair1; this.chair1_cost = chair1_cost; this.name = name; this.passdata(chair1, chair1_cost, name); this.setchair1(super.getItemNum()); this.setchair1_cost(super.getCost()); this.setname(super.getManufacturersName()); } public void setchair1(int newchair1){ chair1 = newchair1; } public int getchair1(){ return chair1; } public void setchair1_cost(float newchair1_cost){ chair1_cost = newchair1_cost; } public float getchair1_cost(){ return chair1_cost; } public void setname(String newname){ name = newname; } public String getname(){ return name; } public void passdata(int passchair, float passchair_cost, String passname){ super.Item(passchair, passchair_cost, passname); } } and this is the Item.java file: import javax.swing.*; public class Item{ protected int item_number; protected float item_cost; protected String manufacturers_name; public boolean TF; public boolean TF1; /* default constructor */ Item(){ } Item(int item_number, float item_cost, String manufacturers_name){ this.item_number = item_number; this.item_cost = item_cost; this.manufacturers_name = manufacturers_name; this.setItemNum(item_number); this.setItemCost(item_cost); this.setManufacturersName(manufacturers_name); } public boolean isItemnum1(){ return TF; } public boolean isCost1(){ return TF1; } public int getItemNum(){ return item_number; } public float getCost(){ return item_cost; } public String getManufacturersName(){ return manufacturers_name; } public void setItemNum(int newitem_number){ if (newitem_number < 0){ TF = false; item_number = 0; } else { TF = true; item_number = newitem_number; } } public void setItemCost(float newitem_cost){ if (newitem_cost < 0){ TF1 = false; item_cost = 0; } else { TF1 = true; item_cost = newitem_cost; } } public void setManufacturersName(String newmanufacturers_name){ manufacturers_name = newmanufacturers_name; } }Last edited by levent; 08-05-2007 at 09:51 PM.
- 08-06-2007, 08:13 AM #2
Java Code:public class ChairRx extends Item{ // Let the superclass keep these items. // Keep things here that pertain more // specifically to Chair and less to Item, ie, // member variables not shared by Item. // private int chair1; // private float chair1_cost; // private String name; public ChairRx(){ } public ChairRx(int chair1, float chair1_cost, String name){ // Send these values to the superclass. super(chair1, chair1_cost, name); } public String toString() { return "ChairRx[item_number:" + item_number + ", item_cost:" + item_cost + ", manufacturers_name:" + manufacturers_name + "]"; } public static void main(String[] args) { ChairRx chair1 = new ChairRx(1, 10.00f, "Allen"); System.out.println("chair1 = " + chair1); ChairRx chair2 = new ChairRx(2, 25f, "Thomas"); System.out.println("chair2 = " + chair2); System.out.println("chair1.getItemNum = " + chair1.getItemNum()); System.out.println("chair1.getCost = " + chair1.getCost()); System.out.println("chair1.getManufacturersName = " + chair1.getManufacturersName()); } } class Item{ protected int item_number; protected float item_cost; protected String manufacturers_name; public boolean TF; public boolean TF1; /* default constructor */ Item(){ } Item(int item_number, float item_cost, String manufacturers_name){ // Use this way of initializing member variables this.item_number = item_number; this.item_cost = item_cost; this.manufacturers_name = manufacturers_name; // or use this way. No need to use both. // this.setItemNum(item_number); // this.setItemCost(item_cost); // this.setManufacturersName(manufacturers_name); } //////// These methods are inherited by subclasses //////// public boolean isItemnum1(){ return TF; } public boolean isCost1(){ return TF1; } public int getItemNum(){ return item_number; } public float getCost(){ return item_cost; } public String getManufacturersName(){ return manufacturers_name; } public void setItemNum(int newitem_number){ if (newitem_number < 0){ TF = false; item_number = 0; } else { TF = true; item_number = newitem_number; } } public void setItemCost(float newitem_cost){ if (newitem_cost < 0){ TF1 = false; item_cost = 0; } else { TF1 = true; item_cost = newitem_cost; } } public void setManufacturersName(String newmanufacturers_name){ manufacturers_name = newmanufacturers_name; } }
Similar Threads
-
Super CSV 1.20
By JavaBean in forum Java SoftwareReplies: 0Last Post: 11-27-2007, 08:22 PM -
Super CSV 1.15
By JavaBean in forum Java SoftwareReplies: 0Last Post: 10-16-2007, 06:37 PM -
Use super. or this.
By Marcus in forum New To JavaReplies: 1Last Post: 07-05-2007, 06:52 AM -
difference between this and super
By mrark in forum New To JavaReplies: 1Last Post: 06-27-2007, 05:23 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks