Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming in C# Define an application to include classes for Student, Graduate

ID: 3780011 • Letter: P

Question

Programming in C#

Define an application to include classes for Student, GraduateStudent, and UndergraduateStudent. Create .DLL files for the three classes. Include characteristics in the Student class that are common to GraduateStudent and UndergraduateStudent students. All three classes should override the ToString() method. GraduateStudent should include a data field for the type of undergraduate degree awarded, such as B.A. or B.S., and the location of the institution that awarded the degree. UndergraduateStudent should include classification (for example, freshman, sophomore), and parent or guardian name and address. Create a presentation class that instantiates student objects and enables details to be displayed on the form about individual students to test your design.

Explanation / Answer

Form1.cs


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using StudentNamespace;
using GraduateStudentNamespace;
using UndergraduateStudentNamespace;

namespace StudentDisplayForm
{
    public partial class studentDisplayForm : Form
    {
        Student student;
        GraduateStudent graduateStudent;
        UndergraduateStudent undergraduateStudent;

        public Student Student
        {
            get { return student; }
            set { student = value; }
        }

        public GraduateStudent GraduateStudent
        {
            get { return graduateStudent; }
            set { graduateStudent = value; }
        }

        public UndergraduateStudent UndergraduateStudent
        {
            get { return undergraduateStudent; }
            set { undergraduateStudent = value; }
        }

        public studentDisplayForm()
        {
            InitializeComponent();
            student = new Student("Billy", "Blue", 20, 2);
            graduateStudent = new GraduateStudent("John", "Jenkins", 34, 8, GraduateStudent.DegreeType.BA , "University of Waterloo" );
            undergraduateStudent = new UndergraduateStudent("Sam", "Smith", 45, 4, UndergraduateStudent.Classification.Freshman, "Morris", "Morlock", "123 Elm Street");

        }


        private void resetButton_Click(object sender, EventArgs e)
        {
            displayBox.Clear();
        }

        private void displayStudentButton_Click(object sender, EventArgs e)
        {
            displayBox.Text = student.ToString();
        }

        private void displayGraduateButton_Click(object sender, EventArgs e)
        {
            displayBox.Text = graduateStudent.ToString();
        }

        private void displayUndergraduateButton_Click(object sender, EventArgs e)
        {
            displayBox.Text = undergraduateStudent.ToString();
        }
    }
}


Form1.Designer.cs

namespace StudentDisplayForm
{
    partial class studentDisplayForm
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.displayBox = new System.Windows.Forms.RichTextBox();
            this.displayStudentButton = new System.Windows.Forms.Button();
            this.resetButton = new System.Windows.Forms.Button();
            this.displayGraduateButton = new System.Windows.Forms.Button();
            this.displayUndergraduateButton = new System.Windows.Forms.Button();
            this.SuspendLayout();
            //
            // displayBox
            //
            this.displayBox.Location = new System.Drawing.Point(12, 12);
            this.displayBox.Name = "displayBox";
            this.displayBox.ReadOnly = true;
            this.displayBox.Size = new System.Drawing.Size(721, 127);
            this.displayBox.TabIndex = 0;
            this.displayBox.Text = "";
            //
            // displayStudentButton
            //
            this.displayStudentButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.displayStudentButton.Location = new System.Drawing.Point(12, 145);
            this.displayStudentButton.Name = "displayStudentButton";
            this.displayStudentButton.Size = new System.Drawing.Size(145, 32);
            this.displayStudentButton.TabIndex = 1;
            this.displayStudentButton.Text = "Display Student";
            this.displayStudentButton.UseVisualStyleBackColor = true;
            this.displayStudentButton.Click += new System.EventHandler(this.displayStudentButton_Click);
            //
            // resetButton
            //
            this.resetButton.Location = new System.Drawing.Point(616, 227);
            this.resetButton.Name = "resetButton";
            this.resetButton.Size = new System.Drawing.Size(98, 23);
            this.resetButton.TabIndex = 2;
            this.resetButton.Text = "Reset Display";
            this.resetButton.UseVisualStyleBackColor = true;
            this.resetButton.Click += new System.EventHandler(this.resetButton_Click);
            //
            // displayGraduateButton
            //
            this.displayGraduateButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.displayGraduateButton.Location = new System.Drawing.Point(199, 145);
            this.displayGraduateButton.Name = "displayGraduateButton";
            this.displayGraduateButton.Size = new System.Drawing.Size(228, 32);
            this.displayGraduateButton.TabIndex = 3;
            this.displayGraduateButton.Text = "Display Graduate Student";
            this.displayGraduateButton.UseVisualStyleBackColor = true;
            this.displayGraduateButton.Click += new System.EventHandler(this.displayGraduateButton_Click);
            //
            // displayUndergraduateButton
            //
            this.displayUndergraduateButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.displayUndergraduateButton.Location = new System.Drawing.Point(463, 145);
            this.displayUndergraduateButton.Name = "displayUndergraduateButton";
            this.displayUndergraduateButton.Size = new System.Drawing.Size(270, 32);
            this.displayUndergraduateButton.TabIndex = 4;
            this.displayUndergraduateButton.Text = "Display Undergraduate Student";
            this.displayUndergraduateButton.UseVisualStyleBackColor = true;
            this.displayUndergraduateButton.Click += new System.EventHandler(this.displayUndergraduateButton_Click);
            //
            // studentDisplayForm
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(745, 262);
            this.Controls.Add(this.displayUndergraduateButton);
            this.Controls.Add(this.displayGraduateButton);
            this.Controls.Add(this.resetButton);
            this.Controls.Add(this.displayStudentButton);
            this.Controls.Add(this.displayBox);
            this.Name = "studentDisplayForm";
            this.Text = "Student Display Form";
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.RichTextBox displayBox;
        private System.Windows.Forms.Button displayStudentButton;
        private System.Windows.Forms.Button resetButton;
        private System.Windows.Forms.Button displayGraduateButton;
        private System.Windows.Forms.Button displayUndergraduateButton;
    }
}

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StudentDisplayForm
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new studentDisplayForm());
        }
    }
}

GraduateStudent.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StudentNamespace;

namespace GraduateStudentNamespace
{
    public class GraduateStudent : Student
    {
        public enum DegreeType { BA, BS }
        private DegreeType awardedDegreeType;
        private string awardedDegreeLocation;

        public GraduateStudent(string firstName, string lastName, int age, int id, DegreeType awardedDegreeType, string awardedDegreeLocation) : base(firstName, lastName, age, id)
        {
            this.awardedDegreeType = awardedDegreeType;
            this.awardedDegreeLocation = awardedDegreeLocation;
        }

        public override string ToString()
        {
            return string.Format("{0}, AwardedDegreeType: {1}, AwardedDegreeLocation: {2}", base.ToString(), awardedDegreeType, awardedDegreeLocation);
        }

        public DegreeType AwardedDegreeType
        {
            get { return awardedDegreeType; }
            set { awardedDegreeType = value; }
        }

        public string AwardedDegreeLocation
        {
            get { return awardedDegreeLocation; }
            set { awardedDegreeLocation = value; }
        }
    }
}

Student.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StudentNamespace
{
    public class Student
    {

        private string firstName;
        private string lastName;
        private int age;
        private int id;

        public Student(string firstName, string lastName, int age, int id)
        {
            this.firstName = firstName;
            this.lastName = lastName;
            this.age = age;
            this.id = id;
        }

        public override string ToString()
        {
            return string.Format("FirstName: {0}, LastName: {1}, Age: {2}, Id: {3}", firstName, lastName, age, id);
        }

        public string FirstName
        {
            get { return firstName; }
            set { firstName = value; }
        }

        public string LastName
        {
            get { return lastName; }
            set { lastName = value; }
        }

        public int Age
        {
            get { return age; }
            set { age = value; }
        }

        public int Id
        {
            get { return id; }
            set { id = value; }
        }


    }


}

UndergraduateStudent.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StudentNamespace;

namespace UndergraduateStudentNamespace
{
    public class UndergraduateStudent : Student
    {
        public enum Classification { Freshman, Sophomore }
        private Classification classification;
        private string guardianFirstName;
        private string guardianLastName;
        private string guardianAddress;

        public UndergraduateStudent(string firstName, string lastName, int age, int id, Classification classification, string guardianFirstName, string guardianLastName, string guardianAddress) : base(firstName, lastName, age, id)
        {
            this.classification = classification;
            this.guardianFirstName = guardianFirstName;
            this.guardianLastName = guardianLastName;
            this.guardianAddress = guardianAddress;
        }

        public override string ToString()
        {
            return string.Format("{0}, Classification: {1}, GuardianFirstName: {2}, GuardianLastName: {3}, GuardianAddress: {4}", base.ToString(), classification, guardianFirstName, guardianLastName, guardianAddress);
        }

        public Classification p_Classification
        {
            get { return classification; }
            set { classification = value; }
        }

        public string GuardianFirstName
        {
            get { return guardianFirstName; }
            set { guardianFirstName = value; }
        }

        public string GuardianLastName
        {
            get { return guardianLastName; }
            set { guardianLastName = value; }
        }

        public string GuardianAddress
        {
            get { return guardianAddress; }
            set { guardianAddress = value; }
        }  
    }
}