Overclock.net banner

1 - 12 of 12 Posts

·
Registered
Joined
·
8 Posts
Discussion Starter · #1 ·
Hi,

I am learning C#. As part of my assignment. We have to create a console and windows form for a student and teacher. I have finished coding and program works well in the console.

When I created a test program for console I have created two switch menus one for student and another for teacher(I have base class as Person, Employee for teacher and so on) and I have two of each add, remove, show, find methods(I have created static private list for student and teacher). One set of methods for student and another set for teacher. The Student class and Teacher class have properties and constructors only.

I am wondering if this is right approach. Should I have only one menu and one add, remove, show, find methods ? If so how would I differentiate between what the user is asking( I will be using a lot of if else statements in that case).

Should have all these methods in their respective classes and create a list there instead of the test program?

Our professor has told us it is bad programming practice to use console.writelines in methods of class rather put them in test class.

I am totally confused and in doubt about my approach as my test class is huge with so many lines of code.

Please help.
redface.gif
 

·
Registered
Joined
·
8 Posts
Discussion Starter · #3 ·
Thank you for your reply.

Yes, we have studied inheritance. We are doing collection now(List, ArrayList, etc)

Student and Employee class inherit the general properties of Person class. Teacher from Employee.
 

·
Registered
Joined
·
555 Posts
One of the main practices that i use is 'Write something once". This makes changing code later easier and easier to find.

Not knowing the full requirements of the program, just what you have in your original post, I see a few classes that can be made.

-A button class. This handles anything associated to a generic button.
-A base menu class. This can handle displaying a list of buttons. It would probably contain a Listand a method to display them to the user.
-A menu class for a student and person to handle specifics about the selections made and create a list of appropriate buttons. This would inherit the base menu class.
-A person class to contain general information about an individual.
-A student and teacher person class that inherits the person class and contains specifics for the type of person.

The trouble is going to be deciding if the person contains the menu, the menu contains the person, or they remain separate.

Another thing I try to do is keep the main function as small as possible. It should only be responsible for starting the program.
 

·
Registered
Joined
·
8 Posts
Discussion Starter · #6 ·
The program specification is to create a college management program to add a student and add a teacher, rest is for us to include or exclude.
 

·
Registered
Joined
·
555 Posts
ah ok. I get it now. Sounds like you can make a class to manage storage of individuals. This would contain a list of students and a list of teachers and some methods for retrieving the one you want and adding new ones in. Something like:

class Manager_Persons
{
private List(Student) Students = new List(Student);
private List(Teacher) Teacher = new List(Teacher);

public void Add(Student StudentData)
public void Add(Teacher TeacherData)

public Student Find_Student(string Name)
public Teacher Find_Teacher(string Name)

//etc
}

hmm it thinks my greater than and less than symbols were html code. put in ( ) in their place on the lists
 

·
Registered
Joined
·
8 Posts
Discussion Starter · #8 ·
I am a bit confused as to what you are saying ?

What I have done so far...

IPerson Interface

Person class - base class - properties like name, dob, etc. which will be extended in Student and Employee class.
Student class-Person class + its own properties. Employee class-Person class + its own properties. This will be extended to Staff and Teacher(Faculty).

College class which is my test class which has the main method.

This class has a menu and where all the methods will be tested.

The menu is :

Enter 1 for Student and 2 for Emp

If 1(if else) then another menu(couple of console.writlines) to check the option for add, remove ,find then switch case(also there is do while loop so that it can add, remove.etc as many records as required) to do the operation as per the choice.

If 2 then a if else to check if staff or teacher and if staff then another menu(couple of console.writlines) to check the option for add, remove ,find then switch case to do the operation as per the choice and similarly for teacher.

This is easier in Windows form but console I don't exactly know to do it easier way. I am sure good programmers wont be doing what I did
biggrin.gif
but I don't know what else to do. Is it bad to have so many loops for the menu ?

Earlier I also had private static student and teacher list in test class but nowI am thinking I should have Student List class to manage the list and have add, remove, etc method. So I will need to have these methods in Person class as well then this will be abstract class.
 

·
Registered
Joined
·
555 Posts
I think your on a good track. Generally I try to split up a program into components and build a class for each component. Its probably a bit excessive for an assignment, but later on you will probably find that the more things are split apart the easier they are to work with and parts can be moved from one program to another with little to no effort. For example, your menu could be used in other assignments if needed. But if its methods are incorporated into the college class there will be a lot of editing to move it to another program.

Don't be afraid of loops. They are what makes console programs work.

I am a little confused by your last paragraph. Are you using the predefined type List, an array, or a linked list? The List type has all the functions you mentioned. The above post assumed the List type was being used. Its better to use what you know though.

Sorry it took so long to get back to you. i didnt get the usual email saying there was a reply.
 

·
Fantastic Mr Fox
Joined
·
5,862 Posts
Can you post the actual code you've got so far? Use something like Pastebin rather than pasting the code into a post here (it will make the thread enormous). It's easier to work out where you're up to by looking at the code than trying to imagine it based on your summarised descriptions.
 

·
Registered
Joined
·
8 Posts
Discussion Starter · #11 ·
Quote:
Originally Posted by PhillyB View Post

I think your on a good track. Generally I try to split up a program into components and build a class for each component. Its probably a bit excessive for an assignment, but later on you will probably find that the more things are split apart the easier they are to work with and parts can be moved from one program to another with little to no effort. For example, your menu could be used in other assignments if needed. But if its methods are incorporated into the college class there will be a lot of editing to move it to another program.

Don't be afraid of loops. They are what makes console programs work.

I am a little confused by your last paragraph. Are you using the predefined type List, an array, or a linked list? The List type has all the functions you mentioned. The above post assumed the List type was being used. Its better to use what you know though.

Sorry it took so long to get back to you. i didnt get the usual email saying there was a reply.
Thank you for the reply. Just needed some assurance
redface.gif


I have spilt up the code in classes. I know I should have the menu in code as well but don't know how to spilt it up so they are in college class as of now.

I am using List collection and methods of List like Add, Find etc but I defined add methods as I am doing an checks like list is empty of if id are same, etc then use the add method of the list.

what I was trying to say in the last para :

What I did earlier is have list declared in test class but now I have class that has list with all the methods so I have class Student List, TeacherList and StaffList

Thanks a lot
 

·
Registered
Joined
·
8 Posts
Discussion Starter · #12 ·
Quote:
Originally Posted by randomizer View Post

Can you post the actual code you've got so far? Use something like Pastebin rather than pasting the code into a post here (it will make the thread enormous). It's easier to work out where you're up to by looking at the code than trying to imagine it based on your summarised descriptions.
http://pastebin.com/yXVcjtUh- This is the code for college class, the test class. The last bit is commented as that was my previous approach. I am using == overload as it is requirement in the assignment.
 
1 - 12 of 12 Posts
Top