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();
> 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.
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.
This IS the error...symbol : constructor CarRental()location: class CarRentalCarRental cr1 = new CarRental();
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.
> This IS the error...No, there's more to it than that.
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;
}
> 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?
I dont understand...im sorry im new to java
oooh okay...so it would look something like...CarRental cr = new CarRental(customerName, location, carSize, daysRented)?
> 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
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.
do I have to initialize each variable too?
> 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.
Now I am getting an error saying that it "cannot find symbol" and then points to all the arguments in the class
God i hate java and this class.....its too confusing and whatever...i guess ill fail this practical test im doing
Then curse the man who invented the language: curse James Gosling, vice-president of Sun Microsystems Inc. of Santa Clara, California!