Many of you asked me to write a simple “homework” for beginners. Now it’s time to write it down here, so anybody who’s now learning C# and don’t have idea what to code can do this one.
Let’s create a simple vehicle inventory winform application.
The main form should have a ListBox (ListView or GridView for advanced programmers) that will show us the vehicles stored in an kind of database. This database can be SQL, or a simple XML file, CSV file, Local DB, whatever you like. We also need 4 buttons: Add, View, Modify and Remove. Something like this:
Another form will have the details of the selected vehicle when addig, viewing or modifing.
The class structure should be the following:
- create a class of Vehicle. No further programmers could create any instance of this class! (hint: abstraction)
- this Vehicle class should have 5 default properties that will be present in all derived classes:
- Id (int)
- CreateUser (string)
- CreateDate (DateTime)
- ModifyUser (string)
- ModifyDate (DateTime)
- these 5 properties should come from and interface of IVehicle
- create 2 subclasses of Vehicle: Air and Ground. These classes shouldn’t be instantiated too!
- create 2 subclasses of Air: Plane and Helicopter.
- create an abstract method in Air class: TotalIncome with returning value of decimal
- the Plane class should have the following properties:
- plane type (use enum! Values should be Airbus, Boeing, Antonov or anything you like)
- max number of passangers (int)
- ticket price (let’s assume that all tickets have the same price for every passangers) (decimal)
- total distance (double)
- the Helicopter should have the following properties:
- max number of passangers (int)
- ticket price (decimal)
- total distance (double)
- military or public usage
- can land on water?
- implement the TotalIncome method that will always return a decimal of (max passangers * ticket price) * (total distance / 10). Of course the result should be shown on the vehicle property form.
- create 2 subclasses of Ground: Car and Bus
- create an abstract method in Ground class: CurrentValue with returning value of decimal
- the Car class should have the following properties:
- manufacturer (Audi, BMW, Bentley or anything you like. Use enum!)
- color (use enum)
- has airconditioner?
- total distance (double)
- buying price (decimal)
- the Bus class should have these properties:
- max number of passangers (int)
- number of doors (int)
- total distance (double)
- buying price (decimal)
- implement the CurrentValue method that equals (buying price – ((total distance / 100) *4))
- create an interface with a method called IncomePerTrip, returns with decimal
- implement this interface in Bus class. Returning value should be (number of passangers * 40.5)
- use only 2 forms! The main form and a property form that would appear anytime a user is doing something in the application (add, view, modify, remove).
- user should add plane, helicopter, car or bus to the database with ONLY relevant properties!
- use confirmation dialog when adding, modifing or removing a vehicle
If this is easy for you, I can extend this homework with some more extra stuff, just let me know! 🙂
Good job!