C# Lab03
C# Lab03
Session Objectives
In this session, you will be practicing with
Classes and Methods
Inheritance and Polymorphism
Scan the code first, type the code, compile, run and observe the result.
1. Create class Car
using System;
class Car
{
// declare the fields
public string make;
public string model;
public string color;
public int yearBuilt;
// define the methods
public void Start()
{
System.Console.WriteLine(model + " started");
}
public void Stop()
{
System.Console.WriteLine(model + " stopped");
}
}
2. Create class Program
class Program
{
public static void Main()
{
// declare a Car object reference named myCar
Car myCar;
// create a Car object, and assign its address to myCar
System.Console.WriteLine("Creating a Car object and assigning "
+ "its memory location to myCar");
myCar = new Car();
This application create 3 class: Window, ListBox, Button and Polimorphism. ListBox and Button are
subclasses of Window. Class Window has method DrawWindow and its two subclases override it. Class
Polimorphism will create some their objects and use its methods to test the polimorphism.
Write an Employee class to record the following attributes and behaviors for an Employee
Declare the following instance variables
o string firstName
o string lastName
o string address
o long sin;
o double salary
Implement a constructor to initialize all the member variables from given
parameters
Override the ToString method to print the employee info in a good presentable
format
Define a method to calculate the bonus ( salary * percentage where
percentage is given as parameter)
Write a Test program to test all the behaviors of above Employee class