In: Computer Science
Consider a Coffee-shop located at the School University Center, which is managed by student association, and some students work there as a manager, in the kitchen, in customer service etc. You can consider all students workers as a general term “student_employee”.
As a system designer your task is to design a UML class for a “student-employee”, try to code in C# or any OOP language, create two sample objects and show inheritances from student to the student_employee.
Here is the answer for your question in C# Programming Language,
Kindly upvote if you find the answer helpful.
###################################################################3
CODE :
using System; class Student{ //Class private member variables private string firstName; private string lastName; private int id; //Default constructor public Student(){} //Parameterised constructor public Student(string fname,string lname,int student_id){ FirstName = fname; LastName = lname; Id = student_id; } //Properties public string FirstName { get{return firstName;} set{firstName = value;}} public string LastName { get{return lastName;} set{lastName = value;}} public int Id { get{return id;} set{id = value;}} //ToString method public override string ToString(){ return "Student Name : " + FirstName + " " + LastName + "\nStudent ID : " + Id; } } //Stude that inherits Student class class StudentEmployee : Student{ //Class private variables private string typeOfWork; private const string STUDENTIS = "A Student-Employee"; //Default constructor public StudentEmployee() : base() {} //Parameterised constructor public StudentEmployee(string type,string fname,string lname,int student_id) : base(fname,lname,student_id) { TypeOfWork = type; } //Properties public string TypeOfWork { get{return typeOfWork;} set{typeOfWork = value;}} //ToString() method public override string ToString(){ return base.ToString() + "\nIs : " + STUDENTIS + "\nType of Work : " + typeOfWork; } } public class MainClass { public static void Main (string[] args) { //Creating one student and two student employee objects Student student = new Student("James","Willis",2098); Student stdEmp1 = new StudentEmployee("Manager","John","Doe",1908); Student stdEmp2 = new StudentEmployee("Chef","Albert","Thomas",1816); //Printing them Console.WriteLine("============================"); Console.WriteLine(student); Console.WriteLine("============================"); Console.WriteLine(stdEmp1); Console.WriteLine("============================"); Console.WriteLine(stdEmp2); Console.WriteLine("============================"); } } |
##############################################################
SCREENSHOTS :
Please see the screenshots of the code below for the indentations of the code.
##################################################################
OUTPUT :
###################################################################
SAMPLE UML CLASS DIAGRAM :
Any doubts regarding this can be explained with pleasure :)