Create a class representing a student. Include characteristics such as first and
ID: 3554812 • Letter: C
Question
Create a class representing a student. Include characteristics such as first and last
name, overall GPA, classification, and major.Write at least two constructors. Include
properties for each of the data items. Create a second class that instantiates the first
class with information about yourself. In the second class, create a class
method that displays your name and GPA.
Explanation / Answer
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SomeNamespace { class student { private string firstName, lastName, classification, major; private double GPA; public student() { firstName = "First"; lastName = "Last"; classification = "Classification"; major = "Major"; GPA = 1.0; } public student(string newfirst, string newlast, string newClass, string newMajor, double newGPA) { firstName = newfirst; lastName = newlast; classification = newClass; major = newMajor; this.setGPA(newGPA); } //mutator public void setFirstName(string newfirst) { firstName = newfirst; } public void setLastName(string newlast) { lastName = newlast; } public void setClassification(string newClass) { classification = newClass; } public void setMajor(string newMajor) { major=newMajor; } public void setGPA(double newGPA) { if (newGPA < 5 && newGPA >= 0) { GPA = newGPA; } else { Console.WriteLine("You have entered an invalid GPA. GPA set to 1.0"); GPA = 1.0; } return; } //accessor public string getFirstName() { return firstName; } public string getLastName() { return lastName; } public string getClassification() { return classification; } public string getMajor() { return major; } public double getGPA() { return GPA; } } class MyInfo { static public void display(student a){ string str = "Name: " + a.getFirstName() + " " + a.getLastName() + " GPA: " + a.getGPA(); Console.WriteLine(str); return; } static void Main(string[] args) { student Myself=new student("BI33D","Gr33n","junior","Computer Science",3.2); display(Myself); Console.ReadKey(); } } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.