Thursday, September 3, 2020

Modelling an Electric Vehicle Class Like Tesla Using Java

 The concept of Java and Java programming is that everything is a Class within the Java Environment.

It means any program you develop using the Java programming language is really and nothing but a class of some sort.
How does this make more sense to you?
Well it is a medeling concept from the real world, and the real world is really but analogue in nature. While in  computers everything is digital and only the 1s and 0s make sense to any computing system.

Take for instance we want to model a car, in this case we are going to be modelling and Electric Car ie car without any combustion systems but has electric system.
An Electric Vehicle will also have states, the states include:
Engine Off
Engine On
Navigation On
The states could overlap, for instance an Electric Vehicle Parked and Discharging at the same time or Parked and is Charging.
 An Electric car does not have a combustion engine but it has a battery system meaning there is the concept of Voltage, Amperage and Wattage characteristics of the battery which is also part of the car Class or model.
The car will have an electric motor which converts the Electrical Energy from the Battery to a rotational motion, which is a mechanical energy for the tires.
The car will have say two seats, in our example. Obviously our car is going to have Tires too and in our case four tires.
A steering is another thing our car should have because it's not a Self-Driving model that may not require a steering.
The Electric Car will also have a body or frame or Chassis that houses everything about the car. Of course our car model is going to have two headlights.
Let me pause for a while here and return to the software engineering aspect again using Java.
To develop a Java application you need three basic things. First is a Text Editor to write the code, and Secondly a Java Compiler and thirdly the Java Runtime Environment or the Java Virtual Machine (JVM).
I will come to that later, now let us focus on the car modelling.
Software Engineering is really an abstraction of the real world, in our a case an Electric Vehicle.
If a car is to be manufactured, normally it has to be in the factory  where cars are manufactured but wait a minute there are Open Source cars,  yes Open Source car models you actually can build at home within two hours. We are not going to talk about the physical car production yet just the modelling.
Good now let's come back to Java,
There is a keyword in Java programming that let's you start a class declaration and that keyword is "Class"
So we can say in our Source file which can be generated using any text Editor like the below statement

   Class ElectricVehicle
{ //Codes for Electric Vehicle class
  //Goes Here

In the example above we are just declaring a class but Just wait we are just starting to Learn Java the crazy way this is not the actual implementation of the Java programming but a wayo to let you Joe Joe things work in the programming world.
The Name of the Class is 'ElectricVehicle' then followed by an opening and closing Curly Brackets.
This is modelling don't forget and we have an empty class with a name ElectricVehicle.
We just declared a class but without any definitions yet about that class.
This is just a Software Defined Model of a car class.
We could continue again with the addition of Objects to the class like this example bellow

    Class ElectricVehicle
Steering S1;
Motor M1;
Tire T1;
Tire T2;
Battery B1;
Using our ElectricVehicle class above
it has class fields the fields are: one Steering field, one Motor field, Two Tire fields and One Battery field.
But we are not limited to any number of fields as we might need to have more fields added to our class in the future life of the Class.
Using this analogy you may want to build say a GUI  app using Java specifically for Android which has just one Button.

In Software Engineering you will have to understand the concept of building the application programme process.
In our example we are just modelling just to understand the concept of Set theory.

No comments:

Post a Comment