Write a class to represent a car used as a taxi. The attributes are: the make/manufacturer, the
model, the registration licence plate, total kilometres driven, and a flag indicating whether it
is currently being driven out on the streets. Include accessors, a mutator to change the flag,
and a method to increase the number of kilometres driven.
2. Write a class to represent the employees of the taxi company (drivers) who will drive in the
taxis. The attributes are: name, licence number. Think about how you will keep track of
which car they are currently driving out on the street. Include accessors, and other methods
that seem appropriate.
Thank you for using the code button, but you didn't quite get it right; the [/code] part goes after the code block. Don't worry; just this time because you are new, I'll correct the tags and you'll see how much better it looks
Unfortunately you have inconsistent indentation: look at lines 36‑41. Don't try to squeeze the whole of a method into one line.
Don't have a variable called flag. It said, “a flag,” so give it a real name.
I don't think your method to increase distance travelled will work. Nor will the setFlag() method. Both those methods look as if you had guessed something, rather than working out what you actually want.
Why have you written two constructors? Why would you want two constructors? I like to use as few constructors as possible.
There are some important conventions in naming getters and setters. If you have the field then the getter and setter would be
Notice that the field's first letter is capitalized. The one exception is that a boolean getter is
All things are lawful, but not all things are profitable.
Sumaira Imtiaz wrote:Write a class to represent a car used as a taxi. The attributes are: the make/manufacturer, the model, the registration licence plate, total kilometres driven...
1. I'm wondering why have you defined model as an int data type? When you made so, you migh had a particular car model in your mind which would have worked, I don't know, maybe Mazda 5..., but how about: Toyota (make) Prius (model)? How would you represent Prius as an integer?
2. licence variable name maybe would read better as licencePlate or registrationPlate or numberPlate? Potentially that would minimize the ambiguity, because if the talk is about taxi, licence might be assumed to be a taxi driver as a business licence...
3. Why do you have this parameterless constructor? That adds nothing really as a functionality to your class user. Quite opposite, it allows to create car objects which are incomplete in some sense.
4. What variable name inckilos represents? Couldn't quite get to be honest. Well, I could understand probably by looking to the class as a whole, but not the variable itself, which I wouldn't like as a code maintainer.
Liutauras Vilda wrote:4. What variable name inckilos represents? Couldn't quite get to be honest. Well, I could understand probably by looking to the class as a whole, but not the variable itself, which I wouldn't like as a code maintainer.
I think it's supposed to mean "In Kilos" -- probably not the weight of the vehicle either. I expect the "cardriven" method is supposed to be the one which increases the number of kilometers driven, but that name really doesn't suggest that's what it does. (Why can't it increase the number of kilometers driven from zero to one?)
And the inckilos variable is unnecessary in that method anyway. You can just return kilometer (which should really be called kilometers). In fact I don't see where the requirements say you should return the new number of kilometers from that method -- I wouldn't have done that.
I see. Agree, it is an overcomplicated implementation.
Sumaira Imtiaz wrote:
As you see I improved an indentation of this code snippet, it is much better now. However, what are your thoughts about that IF condition inside. Looking to what kilometer variable represents, is really the distance the car was driven (in total we could say).
So knowing this, that means the brand new car couldn't be driven? Meaning if it has 0 km on its odometer to begin with.
posted 4 weeks ago
No, it's a contraction of increment in kilometres.
Campbell Ritchie wrote:No, it's a contraction of increment in kilometres.
Oh.. That just yet another example, which demonstrates that really there is no advantage in trimming variable names to their shorter versions, which makes them harder to interpret, at worst - makes them easy misinterpret.
@OP stick to spelling and writing variable names in full, once you get a better sense where and when you can shorten them - by that time you'll know it.
I very rarely shorten the names. Unless they become really long, but that's very rarely happen.
If what Carey showed is indeed what you are looking for, think what kind of input value to add to an existing kilomteres would be wrong in terms of logic?
posted 4 weeks ago
Paul Clapham wrote:The instructions certainly do allow for a lot of different interpretations.
I think that is the correct way to write instructions. The examiner is requesting a functionality, and it is up to the student to provide it. The more different interpretations there are, the more freedom for expression there is the more work the student has to do, and also the less risk there is of inadvertently specifying something which is poor practice.
I like Liutauras' solution, but maybe I woiuld enhance it like this:-
What a stench! Central nervous system shutting down. Save yourself tiny ad!
Two software engineers solve most of the world's problems in one K&R sized book