C #: Poor class design (first OOP)

This is homework !!! Please do not interpret this as I am asking someone to code me.

My program: http://pastebin.com/SZP2dS8D

This is my first OOP. The program works fine, without user input (UI), but its implementation makes my project partially ineffective. I do not use the List collection due to assignment restrictions. My main goal is to get everything working from the Transcript class. Here are some issues that I am facing:

  • Allows the user to add a new course without creating a new instance of Transcript
    everytime
  • Linking courses added to a specific quarter

Here is some kind of pseudo code to show what I'm trying to execute. I experimented with him, but have not had time.

Please enter the quarter: (user input) Would you like to add a course? while (true) Enter Course/Credits/Grade //new Course information populated with user input transcript.AddCourse.to specific Quarter((Fall 2013) new Course("Math 238", 5, 3.9)); transcript.AddCourse.to specific Quarter((Fall 2013) new Course("Phys 223", 5, 3.8)); transcript.AddCourse.to specific Quarter((Fall 2013) new Course("Chem 162", 5, 3.8)); 

MY QUESTION [S]: Should I keep the Transcript class or drop it? With the existing functionality for creating a new course, is it possible to save this when using the user interface, or do I need to go back to the board and reconfigure it?

Hope this is consistent and not too broad. If clarification is necessary, please ask and I will be more than happy to provide more detailed information.

+6
source share
3 answers

I would consider the following composite

 public class Transcript { public Quarter[] Quarters{get;set;} } public class Quarter { public Course[] Courses{get;set;} } 

You only need one instance of the transcription class. This will allow you to simulate n quarters (several years) with n courses per quarter.

In your input loop, you can add new courses / quarters in response to user input

+6
source

There are many ways to model this problem, and I think you are right to have a transcription class, but instead of thinking that there is a set of courses in the quarter, I would suggest that a course property course be offered in that quarter. For instance:

 public class Transcript { private List<Course> courses_ = new List<Course>(); public IEnumerable<Course> Courses {get { return courses_; } public IEnumerable<Course> GetCoursesFor(int year, int quarter) { return courses_.Where(course => course.Year == year && course.Quarter == quarter); } public void AddCourse(Course course) { courses_.Add(course); } } public class Course { public int Year {get; private set;} public int Quarter {get; private set;} // ... other members } 
+3
source

you can try this

 public enum Quarters { First, Second, Third, Fourth } class Courses { private Quarters ThisQuarter { get; private set; } private List<Tuple<Quarters, List<Courses>>> SchoolProgram = new List<Tuple<Quarters, List<Courses>>>(); public int year { get; private set; } public string name { get; private set; } private Courses() { //load list from database or xml //each tuple has one quarters and a list // of associated courses //SchoolProgram.Add(new Tuple<Quarters, List<Courses>>(Quarters.First, new List<Courses>(){new Courses(2010,"Math",Quarters.First), // new Courses(2010,"English",Quarters.First), // new Courses(2010,"Physics",Quarters.First)})); } public Courses(int year,string name,Quarters q) { this.year = year; this.name = name; ThisQuarter = q; } public Courses GetCourse() { return SchoolProgram.Find(q => q.Item1 == ThisQuarter).Item2.Single(c => (c.year == this.year && c.name == this.name)); } } public class Transcript { private List<Courses> SchoolProgram = new List<Courses>(); public Transcript() { //maybe aditional logic here } public void AddCourse(int year,string name,Quarters q) { Courses c = new Courses(year, name, q); SchoolProgram.Add(c.GetCourse()); } } 

you can add additional logic about grades and other things .... best wishes

+2
source

Source: https://habr.com/ru/post/946876/


All Articles