Tutorial 11 (March 22): A4, MVC, GUI layout videos, packages
Assignment 4
Downloads: MVC notes (.PDF) || Sample Code (.zip)
Covers: MVC pattern, Grid/Border layout, JPanel, JTextField, JLabel, JButton, JRadioButton, JComboBox
The previous post, Assignment 4: Understanding mortgage calculations, should get you through all the calculations.
For more advanced GUI layout, refer to these Java Tutorials (video links shared by Prof. Dina Said): Part 1 || Part 2
For more information about MVC (Model View Controller), refer to this video.
A third of your grade for assignment 4 is for the UML Class Diagram, HTML Documentation (Javadocs), and regular documentation plus formatting. Because many people are still struggling with these, I will do a recap here:
UML Class Diagram
Drawing individual classes || Linking up your classes in the UML diagram
If you are still having trouble with the concepts of association, aggregation, composition, abstract/concrete classes, inheritance, and interfaces, please either review these or ask me.
HTML Documentation (Javadocs)
Refer to this previous tutorial for how to generate Javadocs.
You need to have javadocs for ALL of your methods and constructors. Make sure you have all the @param and @return fields in your javadocs, and that you are adding descriptions to each one. Your descriptions can be simple, but need to be useful.
//Good Example/** * Given another shape, this method calculates the distance between that shape and this shape itself. * @param otherShape The other shape to calculate the distance to. * @return The distance between this shape and the other shape provided, as a Double. */
//Bad Example/** * distance * @param otherShape other shape * @return the value of the distance */
I look for these things when I check your javadocs:
- Did you do all of them?
- Do all of your javadocs contain @param and @return fields? (If it looks like you're missing a lot, I generate the javadocs and check for warnings and errors.
- Are your descriptions for each method/constructor and each @param/return field decent? "The value of <parameter name>" is not a good enough description, it doesn't tell me anything.
- Finally, did you submit the javadoc files? (ALL of them, not just the HTML files)
MVC (Model View Controller)
This is the same tutorial video linked above for the MVC pattern. MVC separates the Model, View, and Controller.
Model contains your data and the methods used to manipulate the data. In the assignment, you should have a Mortgage class which contains variables/properties regarding principal, interest, payment frequency, etc.
View contains your GUI, and should probably extend JFrame in your assignment. Your View is not limited to one class, but refers to all the classes used in your GUI. For example, your JFrame may make use of several Panels or reuse certain button classes.
Controller is the link between your View and Model. This is where you put all your event handlers for the assignment. Model and View should be independent of each other, and when the user does something, the Controller will handle the event. The Controller then takes in some value from the View (eg. Textbox or dropdown menu), and calls some method from your Model. The Controller can make use of properties in the Model, and after performing some calculations, the value may be stored back to the Model. The result will likely then be displayed back to the user via the View.
Packages
Put all your classes into a package called lab4.
If you are using Eclipse (see below for command line), Packages is very simple. When you create a new Class, you can define a Package at the top of the form. Once you have a Package, you can click "Browse..." for any subsequent classes or interfaces (or anything else for that matter). You will see package yourPackageName; at the top of your code.
If you are using command line:
- Navigate to the folder above your package folder (you can see the examplePackage folder here, which contains all the files in the package)
- javac thePackageFolderName/*.java This will compile all your .java files in the package.
- java thePackageFolderName/Test This will run the main() method in your Test class, inside the package.
