Stupid Question...

How do I fix this error?I have compared code int his program to code in other programs and I see no difference between them. What am I missing?symbol : constructor CarRental()location: class CarRentalCarRental cr1 = new CarRental();
[267 byte] By [dooguesgoober4a] at [2007-11-26 21:05:59]
# 1

> How do I fix this error?

>

> I have compared code int his program to code in other

> programs and I see no difference between them. What

> am I missing?

>

> symbol : constructor CarRental()

> location: class CarRental

> CarRental cr1 = new CarRental();

An error might help.

Aknibbsa at 2007-7-10 2:40:06 > top of Java-index,Java Essentials,New To Java...
# 2
The CarRental class obviously has no constructor taking no arguments (also known as a "default constructor").There, I can tell that without even seeing your code, since my crystall ball is once again functioning.
warnerjaa at 2007-7-10 2:40:06 > top of Java-index,Java Essentials,New To Java...
# 3
This IS the error...symbol : constructor CarRental()location: class CarRentalCarRental cr1 = new CarRental();
dooguesgoober4a at 2007-7-10 2:40:07 > top of Java-index,Java Essentials,New To Java...
# 4
It's telling you exactly what's wrong. You're trying to invoke a CarRental constructor that takes no arguments, but CarRental has no such constructor.
jverda at 2007-7-10 2:40:07 > top of Java-index,Java Essentials,New To Java...
# 5
> This IS the error...No, there's more to it than that.
jverda at 2007-7-10 2:40:07 > top of Java-index,Java Essentials,New To Java...
# 6

I thought that this was my constructor?

class CarRental

{

protected String customerName, location, carSize;

protected double costPerDay;

protected byte daysRented;

public CarRental(String custName, String loc, String cSize, byte dRented)

{

custName = customerName;

loc = location;

cSize = carSize;

dRented = daysRented;

}

dooguesgoober4a at 2007-7-10 2:40:07 > top of Java-index,Java Essentials,New To Java...
# 7

> public CarRental(String custName, String loc, String cSize, byte dRented)

I see a constructor there taking four arguments. So don't you think you'd better pass that many arguments when you try to invoke the constructor?

Yet you did this instead:

> CarRental cr1 = new CarRental();

No arguments passed to it. See now?

warnerjaa at 2007-7-10 2:40:07 > top of Java-index,Java Essentials,New To Java...
# 8
I dont understand...im sorry im new to java
dooguesgoober4a at 2007-7-10 2:40:07 > top of Java-index,Java Essentials,New To Java...
# 9
oooh okay...so it would look something like...CarRental cr = new CarRental(customerName, location, carSize, daysRented)?
dooguesgoober4a at 2007-7-10 2:40:07 > top of Java-index,Java Essentials,New To Java...
# 10

> oooh okay...so it would look something like...

>

> CarRental cr = new CarRental(customerName, location,

> carSize, daysRented)

>

> ?

Yes, assuming you have customerName, etc declared as variables and which have the right values to pass, of course.

Whoa, and all these are backwards in the constructor:

custName = customerName;

loc = location;

cSize = carSize;

dRented = daysRented;

You need to do those in the other order:

customerName = custName; // set the customerName member variable equal to the argument

etc.

Message was edited by:

warnerja

warnerjaa at 2007-7-10 2:40:07 > top of Java-index,Java Essentials,New To Java...
# 11
Yes, that is a constructor, but it takes 4 arguments and you are trying to create an object, while passing 0 arguments to the constructor. That wont work.
JoachimSauera at 2007-7-10 2:40:07 > top of Java-index,Java Essentials,New To Java...
# 12
do I have to initialize each variable too?
dooguesgoober4a at 2007-7-10 2:40:07 > top of Java-index,Java Essentials,New To Java...
# 13
> do I have to initialize each variable too?I can see that we're having to guess a little too much about what you mean to pull things out of you for context, so I'm going to have to walk away. Good luck.
warnerjaa at 2007-7-10 2:40:07 > top of Java-index,Java Essentials,New To Java...
# 14
Now I am getting an error saying that it "cannot find symbol" and then points to all the arguments in the class
dooguesgoober4a at 2007-7-10 2:40:07 > top of Java-index,Java Essentials,New To Java...
# 15
God i hate java and this class.....its too confusing and whatever...i guess ill fail this practical test im doing
dooguesgoober4a at 2007-7-21 18:10:46 > top of Java-index,Java Essentials,New To Java...
# 16
Then curse the man who invented the language: curse James Gosling, vice-president of Sun Microsystems Inc. of Santa Clara, California!
DrLaszloJamfa at 2007-7-21 18:10:46 > top of Java-index,Java Essentials,New To Java...