2

Let me start by saying this is a homework assignment, I don't need any coding help though -- I just feel lost when I try to make sense of how to implement MVC with what the instructions say... I have read many many examples from forums and different websites (even my two books for this data structures class) and I have a great understanding of what MVC is. I just get so confused when it comes to implement it with code...

So this is what the teacher gave us to work with:

The class Driver (VIEW), class List (MODEL), and class Tests (CONTROLLER) such that an object of this class can store a student’s first name, last name, five test scores, average tests score, and grade. Add constructors and methods to manipulate data stored in an object. Among other things, your classes must contain methods to calculate test averages, return test averages, calculate grades, return grades, and modify individual test scores. The method toString() must return test data (including student’s name, five test scores, average, and grade) as a String plus the class average.

I do realize she labled what classes should be what, and I have already made those classes... My confusion is what class to give what methods/functions/variables etc.

The model should hold information its like a database .... so should I make another class Student that has variables first/last name and test averages? But then which class will get the getter and sett methods?

Again, I have searched and searched and searched, I have seen many examples but its just not clicking for me :(

Thanks to anyone that can dumb this down enough based off what the teacher has presented....

7
  • Student will have its own getter and setter methods (if need be). If some fields will only be set in the constructor (write only), then they should only have getter methods. Please try to clarify your points of confusion as much as possible. The more specific your questions, usually the more helpful are answers may be. Commented Jun 10, 2012 at 23:03
  • Note also that the model will contain a list of Students, perhaps an ArrayList (up to you), and will likely need its own addStudent(Student s), calculateAverage() and whatnot methods. Commented Jun 10, 2012 at 23:08
  • my confusion is that I have no idea which class to give what methods and variables to when applying MVC style coding. With this being said I believe that List(Model) will hold instances of Class students But then what should I be putting into view and controller? Who gets the getters and setters? Commented Jun 10, 2012 at 23:11
  • What getters and setters specifically do you mean? Again, the more specific your question, the more specific and helpful the answer. Commented Jun 10, 2012 at 23:14
  • Currently I stand with 4 classes in my Project(named and labled accordingly): class ListMODEL, class TestsCONTROLLER, class DriverVIEW, and Class Student. as of right now student just contains 2 strings and 6 floats, and a Setter method that sets first/last names. Everything else sits empty. Since this is a class she is making us make our own datastructures from the ground up, so our own add and remove methods too) (we are not permitted to use JCL stuff for array List) your previous post was helpful about the add and calculate for the Model. But then what methods do view and Controller get?? Commented Jun 10, 2012 at 23:29

1 Answer 1

3

So, if List is the MODEL, then List has methods to access, modify, remove and add elements. Just like a database. (hint: those are getters and setters). If Driver is the VIEW, then it should have methods to display whatever it needs to. This should mainly be formatting. If Tests is a CONTROLLER then it should have methods that provide information to the VIEW. These are usually methods that perform calculations such as the ones you've specified.

Usually a CONTROLLER glues the VIEW and the MODEL.

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect :D... great explanation. I went back and looked at other examples the teacher posted a million times and it finally clicked!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.