Create a class representing a student. Include characteristics such as student n
ID: 3669636 • Letter: C
Question
Create a class representing a student. Include characteristics such as student number, first and last name, classification, and major. Write at least two constructors. Include properties for each of the data items. Include an instance method that returns a full name (with a space between first and last name). Create a second class that instantiates the first class with information about yourself. In the second class, create a class (static) method that displays name and major using the instantiated object.
Explanation / Answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentInformation
{
public class StudentInfo
{
private int studentNumber;
private string firstName;
private string lastName;
private string studentClass;
private string studentMajor;
public int StudentNumber
{
get
{
return studentNumber;
}
}
public void setFirstName(String newFirstName)
{
firstName = newFirstName;
}
public string FirstName
{
get
{
return firstName;
}
}
public void setLastName(String newLastName)
{
lastName = newLastName;
}
public string LastName
{
get
{
return lastName;
}
}
public string StudentClass
{
get
{
return studentClass;
}
}
public string StudentMajor
{
get
{
return studentMajor;
}
}
//Default Constructor
public StudentInfo()
{
}
//Constructor 1
public StudentInfo(int number, string first, string last, string classification, string major)
{
studentNumber = number;
firstName = first;
lastName = last;
studentClass = classification;
studentMajor = major;
}
//Constructor 2
public StudentInfo(string first, string last)
{
firstName = first;
lastName = last;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentInformation
{
public class StudentInformation
{
public static void Main()
{
StudentInfo Dustin = new StudentInfo();
Console.WriteLine("Name: " + Dustin.FirstName + " " + Dustin.LastName + " "+ "GPA: ");
Console.ReadKey();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.