Question
Main IN C# Make a main program that creates a list and an array, of objects defined below. The objects should be Mobile objects (Base
Main
IN C#
Make a main program that creates a list and an array, of objects defined below. The objects should be Mobile objects (Base class) of type NPC (SubClass), and of type Vehicles(Another subclass), see next section for specification. You will need to randomly generate many of the properties of these objects.
You can use existing list implementations in C# for now, (next week Ill make you write your own).
Random numbers can be generated using the code in Lab 1.
Classes Specification
Base Class:
MobileObject
Name
ID
Position (x, y, z), where x, y and z are floating point values.
ID should be unique, but it should be assigned to the object when it is created, your main program should have a list (or array) of Mobile Objects, and the IDs should be created in sequence. Names can be random or hard coded, and positions should be random.
First Sub class of type NPC.
And NPC should have the following properties that must be present when the object is created:
leg length
torso height
head height
(private) total height
Objects of type NPCs should calculate their total height as the sum of leg length, torso height and head height. The method which generates this should be private.
Second Subclass of Type Vehicle
Length
Height
Width
(private) Bounding Volume (= Length*height*width)
Object creation should fail if values entered are invalid, (e.g. a negative value for heights, or widths, positions can be negative).
Generate a number (~5 - 10) of objects type NPC and Vehicle and put them in a list and array of mobile objects.
Encapsulation (part of programming question).
Public:
It should be possible to print the status of an object, which either returns a string or prints to the console all of the properties of the object, meaning you need a method print for each object type.
An object should have a series of setters and getters which allow you to set and return the various properties. Setters and getters are controversial in object oriented programming for the obvious reason that some of them do nothing but set a variable equal to some input value, on the other hand, used well, they prevent invalid or unworkable values being set (e.g. torso height = 10 000 is a perfectly valid integer but not so sensible if the other values are in the range 1-10).
Private: as mentioned above, total height and vehicle bounding volume should be calculated as a private method.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started