Create a program in C# 1. Create an abstract class “Student.cs”. o 3 public stri
ID: 3809970 • Letter: C
Question
Create a program in C#
1. Create an abstract class “Student.cs”.
o 3 public string data members: firstName, lastName, studentID.
o Create a constructor to initialize each data member value.
o Create read-only property for each data member.
o Create an abstract method “ImportantThing()”, returns string.
2. Create an Interface “IMathClass.cs”. Declare a method “Math()”, returns string.
3. Create classes “ElementarySchoolStudent.cs”, “MiddleSchoolStudent.cs”,
“HighSchoolStudent.cs”, “CollegeStudent.cs”, inherit “Student.cs” and “IMathClass.cs” to each
of them.
ElementarySchoolStudent.cs
o Constructor with three parameters for firstName, lastName, studentID.
o ImportantThing() returns "Farm field trip!".
o Math() returns "Basic Math."
o Override toString().
MiddleSchoolStudent.cs
o Constructor with three parameters for firstName, lastName, studentID.
o ImportantThing() returns "Summer Camp!".
o Math() returns "Geometry."
o Override toString().
HighSchoolStudent.cs
o Constructor with three parameters for firstName, lastName, studentID.
o ImportantThing() returns "SAT exam.".
o Math() returns "Basic Algebra."
o Override toString().
CollegeStudent.cs
o Constructor with three parameters for firstName, lastName, studentID.
o ImportantThing() returns "Major.".
o Math() returns "Advanced Algebra.".
o Override toString().
4. In “Program.cs”, in method “main()”, create an “Student” type array with size of 4.
o First element is ElementarySchoolStudent object with any first name, last name, student
ID for constructor.
o Second element is MiddleSchoolStudent object with any first name, last name, student
ID for constructor.
o Third element is HighSchoolStudent object with any first name, last name, student ID for
constructor.
o Fourth element is CollegeStudent object with any first name, last name, student ID for
constructor.
o for loop to go through array, call .toString for each object
OUTPUT
Ny name is Sanuel Clark, an an Elenentary school student, Will have an exciting Farm field trip!, Iwill learn Basic Math name is David Hunt, I am a niddle school student. vill have aSunner Carp!, I will learn Geometry, My name is Mary Anderson, I an high school student. I will take SAT exam,, I learn Basic Algebra, My name is Tim Russell, I am a college student, I have a Major,, I learn Advanced Algebra, Press any key to continue Student FirstName IMath Class Last Name String Math() StudentID abstract importantThing0 Middle SchoolStudent High SchoolStudent CollegeStudent Elementary SchoolStudent FirstName FirstName FirstName FirstName LastName Last Name Last Name LastName StudentID StudentID StudentID StudentID ImportantThing0 ImportantThing0 ImportantThing0 ImportantThing0 Math() Math() Math() Math()Explanation / Answer
Solution:
Executable Code:
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Student[] s = new Student[4];
s[0] = new CollegeStudent("dris","ann","M11");
Console.WriteLine (s[0].ToString());
s[1] = new ElementarySchoolStudent("aaa", "bbb", "M11");
Console.WriteLine(s[1].ToString());
s[2] = new HighSchoolStudent("ccc", "ddd", "M11");
Console.WriteLine(s[2].ToString());
s[3] = new MiddleSchoolStudent("eee", "fff", "M11");
Console.WriteLine(s[3].ToString());
Console.ReadLine();
}
}
}
Student.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public abstract class Student
{
public string firstName;
public string lastName;
public string studentID;
public Student(string first,string last, string ID)
{
firstName = first;
lastName = last;
studentID = ID;
}
public string FirstName
{
get { return firstName; }
}
public string LastName
{
get { return lastName; }
}
public string StudentID
{
get { return studentID; }
}
public abstract string ImportantThing( );
}
}
CollegeStudent.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class CollegeStudent: Student,IMathClass
{
public CollegeStudent(string first, string last, string ID):base( first,last, ID)
{
}
public override string ImportantThing() { return " Major.."; }
public string Math() { return "Basic Algebra"; }
public override string ToString()
{
return "My name is "+firstName+lastName+", I am a college student. I have a "+ImportantThing()+". I learn "+Math();
}
}
}
HighSchoolStudent.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class HighSchoolStudent : Student, IMathClass
{
public HighSchoolStudent(string first, string last, string ID)
: base(first, last, ID)
{
}
public override string ImportantThing() { return " SAT exam!"; }
public string Math() { return "Basic Algebra"; }
public override string ToString()
{
return "My name is "+firstName+lastName+", I am a high school student. I have a "+ImportantThing()+". I learn "+Math();
}
}
}
ElementarySchoolStudent.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class ElementarySchoolStudent: Student, IMathClass
{
public ElementarySchoolStudent(string first, string last, string ID)
: base(first, last, ID)
{
}
public override string ImportantThing() { return " Farm field trip!"; }
public string Math() { return "Basic Math"; }
public override string ToString()
{
return "My name is "+firstName+lastName+", I am a elemntary school student. I have a "+ImportantThing()+". I learn "+Math();
}
}
}
MiddleSchoolStudent.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class MiddleSchoolStudent : Student, IMathClass
{
public MiddleSchoolStudent(string first, string last, string ID): base(first, last, ID)
{
}
public override string ImportantThing() { return " Summer Camp!"; }
public string Math() { return "Geometry"; }
public override string ToString()
{
return "My name is "+firstName+lastName+", I am a middle school student. I have a "+ImportantThing()+". I learn "+Math();
}
}
}
IMathClass.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public interface IMathClass
{
string Math();
}
}
Output:
My name is drisann, I am a college student. I have a Major... I learn Basic Alg
ebra
My name is aaabbb, I am a elemntary school student. I have a Farm field trip!.
I learn Basic Math
My name is cccddd, I am a high school student. I have a SAT exam!. I learn Basi
c Algebra
My name is eeefff, I am a middle school student. I have a Summer Camp!. I learn
Geometry
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.