Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

develop a taxicar and taxidriver classes

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
Marshal
Posts: 68899
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

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.
 
Sheriff
Posts: 7051
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again to the Ranch, Sumaira Imtiaz!

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
 
Sheriff
Posts: 7602
521
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sumaira, welcome to the Ranch yet again.

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.

 
Marshal
Posts: 25436
65
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Liutauras Vilda
Sheriff
Posts: 7602
521
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see. Agree, it is an overcomplicated implementation.

@OP

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.
 
Campbell Ritchie
Marshal
Posts: 68899
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it's a contraction of increment in kilometres.
 
Liutauras Vilda
Sheriff
Posts: 7602
521
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Paul Clapham
Marshal
Posts: 25436
65
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:



Or to put it more simply:

 
Bartender
Posts: 7065
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I interpreted the requirements this way
 
Paul Clapham
Marshal
Posts: 25436
65
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The instructions certainly do allow for a lot of different interpretations.
 
Liutauras Vilda
Sheriff
Posts: 7602
521
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:


In which case I'd probably prefer:
Because addKilometers reads quite mechanical in my head.
 
Liutauras Vilda
Sheriff
Posts: 7602
521
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@OP

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?
 
Campbell Ritchie
Marshal
Posts: 68899
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic