Reputation: 551
How can i model foollwing problem statatement into java classe?
I have a class vehincle.
Upvotes: 1
Views: 1318
Reputation: 354496
This sounds very much like a beginner OOP task. In this case you're going to model each class of things in the real world as classes in your class model. That is, there will be a class Vehicle
, Engine
, SparkPlug
, etc.
Then those classes have certain relationships, such as DieselEngine
being a kind of Engine
. You should have learned that inheritance can be used to model such a relationship.
Furthermore, some things are composed of other things, such as PetrolEngine
having a SparkPlug
. Classes can have attributes as you probably know already. Use them accordingly.
In UML the two things you need here for a class diagram would be generalization and composition.
Also, I'm sure if you ask your fellow students you can together come up with a solution. That's usually easier than dumping the task description into a forum or Q&A site and waiting for ready-made solutions.
Upvotes: 4