help with constructors 2
This is the line of code that I have errors in
Maker r =new Maker(txtfield1[1].getText(),txtfield1[4].getText(), 0.05, Integer.parseInt(txtfield1[2].getText()), txtfield1[3].getText(), Integer.parseInt(txtfield1[5].getText()),
Double.parseDouble(txtfield1[6].getText()));
Here is where I have set constructors for Inventory()
public Inventory(int _itemNum, String _name,double _price,int _units)
Here is where I added more constructors:
public Maker(int Item_Number, String Item_Name,double Item_Price,int Items_in_Stock, String manufact,double restockingFee)// Constructor for varibles
{
super(Item_Number, Item_Name, Item_Price, Items_in_Stock);
this.manufact[i] = manufact;
this.restockingFee[i] = restockingFee;
i = i + 1;
}
Here is my compiling error:
symbol : constructor Maker(java.lang.String,java.lang.String,double,int,java.lang.String,int,double)
location: class inventorymain.Maker
Maker r = new Maker(txtfield1[1].getText(),txtfield1[4].getText(), 0.05, Integer.parseInt(txtfield1[2].getText()), txtfield1[3].getText(), Integer.parseInt(txtfield1[5].getText()),
1 error
BUILD FAILED (total time: 0 seconds)
I know it is the order of my constructors, but when I changed them to match my constructors for Inventory() it still does not work. What am I doing wrong?
The ordering of constructor arguments don't have to match between a class and its subclass. For example, this is legal:
class A {
A(int a, int b, int c) {}
}
class B extends A {
B(int x, int y, int z) {
super(y, z, x);
}
}
The order doesn't matter. You're trying to use a constructor that doesn't exist.
jverda at 2007-7-28 18:26:38 >

Do you understand the problem here? you're passing a string as first parameter when instantiating the class Maker but the first parameter in the constructor is an int.
Manuel Leiria
What I am trying to do is to allow a user to input these constructors (per se) through a gui modify button.
Yes I know that is the problem, but when I changed around my constructors for maker r, to match (int,s tring, double, int, string, double) I still would receive errors.
> Yes I know that is the problem, but when I changed
> around my constructors for maker r, to match (int,s
> tring, double, int, string, double) I still would
> receive errors.
I don't quite understand what kind of confusion is going on in your head but this is very simple: The first parameter of the constructor is an int and you're passing a string. Changer the constructor for receive a string as first parameter or change the call to pass an int as first parameter
Manuel;
Yes I am confused or I would not be asking for help.....
You are currently calling a c'tor that takes
String, String, double, int, String, int, double
There is no such c'tor.
You have two choices:
1) Create that c'tor.
2) Call an existing c'tor.
What part don't you get?
jverda at 2007-7-28 18:26:38 >

No offence intended !
The Maker constructor is
public Maker(int Item_Number, String Item_Name, double Item_Price, int Items_in_Stock, String manufact, double restockingFee)
that is, it accepts (you know you can't swap the parameters in the constructor, don't you?)
int, String, double, int, String, double
but you are instantiating like this:
new Maker(
txtfield1[1].getText(),
txtfield1[4].getText(),
0.05,
Integer.parseInt(txtfield1[2].getText()),
txtfield1[3].getText(),
Integer.parseInt(txtfield1[5].getText()),
Double.parseDouble(txtfield1[6].getText()));
that is,
String, String, double, int, String, int, double
you see! They don't match! The parameters must be of the same type and in the same order
I thought I was changing it to call a constructor that I had set up before.
Is this correct?
Maker r = new Maker(txtfield1[0].getText(), Integer.parseInt(txtfield1[2].getText()), Double.parseDouble(txtfield1[4].getText())), Integer.parseInt(txtfield1[3].getText()), txtfield1[1].getText();
> Is this correct?
Does it compile, run, and produce the results you expect?
jverda at 2007-7-28 18:26:38 >

> I thought I was changing it to call a constructor
> that I had set up before.
>
> Is this correct?
>
> > Maker r = new Maker(txtfield1[0].getText(),
> Integer.parseInt(txtfield1[2].getText()),
> Double.parseDouble(txtfield1[4].getText())),
> Integer.parseInt(txtfield1[3].getText()),
> txtfield1[1].getText();
>
In this case, your constructor must be something like this
public Maker(String a, int b, double c, int d, String e){
//do stuff
}
now I get an error that says ; expected.
> now I get an error that says ; expected.
Then you're missing a semicolon, or you have an extra closing parenthesis or brace or something.
jverda at 2007-7-28 18:26:38 >

> now I get an error that says ; expected.
That's probably because:
Maker r = new Maker(txtfield1[0].getText(), Integer.parseInt(txtfield1[2].getText()), Double.parseDouble(txtfield1[4].getText())), Integer.parseInt(txtfield1[3].getText()), txtfield1[1].getText(); //<-- missing one )
whew I am ready to scream...lol
heres what I have now,
Maker r = new Maker(txtfield1[0].getText(), Integer.parseInt(txtfield1[2].getText()), Double.parseDouble(txtfield1[4].getText()), Integer.parseInt(txtfield1[3].getText()), txtfield1[1].getText()), 0.05;
heres my set constructors:
public Maker(String Item_Name, int Item_Number, double Item_Price, int Items_in_Stock, String manufact, double restockingFee)// Constructor for varibles
{
super(Item_Name, Item_Number, Item_Price, Items_in_Stock);
this.manufact[i] = manufact;
this.restockingFee[i] = restockingFee;
i = i + 1;
}
So now they should match right?
> So now they should match right?
"Should" is irrelevant. The compiler tells you whether they do, and it is correct. It also tells you exactly what is wrong. You just have to look very closely at each arg in the compiler's error message, each arg in the declared c'tor, and each arg in what you're calling.
jverda at 2007-7-28 18:26:43 >

Now they match!
Finally some action!
;)
ok jverd I think I have the arguments correct, except it says I need an identifier for the last argument 0.05, In an example I seen online it did not have anything infront of the 0.05. What do I need to put infront of it? 0.05 is a double for the percent of a restocking fee.
Thanks for being patient with me, as I am a student in my first Java class, so I do not have to much experience...
But as jverd said this is not a "they should". There's only two cases:
One -> The match and everything flows right
Two -> They don't match and it will blow up
Manuel Leiria
> ok jverd I think I have the arguments correct, except
> it says I need an identifier for the last argument
> 0.05,
Paste in your exact code and the exact, complete error message.
jverda at 2007-7-28 18:26:43 >

After the 0.05 you need to put a closing brace
Can you spot the difference between
Maker r = new Maker(txtfield1[0].getText(), Integer.parseInt(txtfield1[2].getText()), Double.parseDouble(txtfield1[4].getText()), Integer.parseInt(txtfield1[3].getText()), txtfield1[1].getText()), 0.05;
and
Maker r = new Maker(txtfield1[0].getText(), Integer.parseInt(txtfield1[2].getText()), Double.parseDouble(txtfield1[4].getText()), Integer.parseInt(txtfield1[3].getText()), txtfield1[1].getText()), 0.05);
Maker r = new Maker(txtfield1[0].getText(), Integer.parseInt(txtfield1[2].getText()), Double.parseDouble(txtfield1[4].getText()), Integer.parseInt(txtfield1[3].getText()), txtfield1[1].getText()), 0.05;
error message:
\Maker.java:738: <identifier> expected
Maker r = new Maker(txtfield1[0].getText(), Integer.parseInt(txtfield1[2].getText()), Double.parseDouble(txtfield1[4].getText()), Integer.parseInt(txtfield1[3].getText()), txtfield1[1].getText()), 0.05;
oh **** Manuel, I got cha. lol, please excuse my ignorance....lol
Thank you you two for your help and patients! It is greatly appreciated!!!! I gave jverd 8 dukes and Manuel 2 dukes for the help....
Have a good evening!!
Just close the ****1ng braces!!!!!
You have 0.05;
and must be 0.05);
[edit] Ok!
Message was edited by:
manuel.leiria
[soapbox]
Sorry for being the big pessimist here, but javahelp, look at how much help you have been requesting in this forum and yet you're still unclear on very basic things, like calling a constructor. I don't think that you are stupid or lazy, but you may be getting too much help. It may be harming you in the long run.
I know that you will not think this response helpful, but I am placing it here with your best interests at heart. Quite frankly, I think that you have to learn how to figure these things out for yourself. Each time you give up and ask for help here, you lose some of that key ability. It's like a muscle: if you don't exercise it, it will atrophy. I urge you to abstain from posting here, and work out your problems on your own. With effort (and it will take a lot, but you can do it), you will succeed; trust me, you will. Else you risk never learning the basics, and more importantly, you forget how to learn.
[/soapbox]