edw1nzhao / cs2340_group16

CS2340 Group 16 Crowd-Sourced Water Reporting App
2 stars 1 forks source link

M3 - Individual Android Exercise (Benjamin Faught) #16

Closed edw1nzhao closed 7 years ago

edw1nzhao commented 7 years ago

Purpose

Make sure you can build and execute an Android application on computer. Will add functionality across the application stack to solidify understanding on Model-View-Controller.

Guidelines:

Model

View

Controller

================================================ Running the App

  1. Download M3.zip file. Extract into IDE project directory (Or just import code files)
  2. If run the project, should build and execute normally. Should be able to add a student and see list update.

New Feature

================================================ Model Changes Focus on student class.

  1. To support the class standing, we will first need to create a new class named ClassStanding which is an enum with the values FRESHMAN, SOPHOMORE, JUNIOR, and SENIOR. Give each class a two character representation "FR", "SO", "JR" and "SR".
  2. Now add an attribute to Student which holds the ClassStanding enum.
  3. Add getter and setter for the ClassStanding
  4. Make a new 3 param constructor which includes name, major and class standing. Keep the old two param constructor for backwards compatibility and use constructor chaining to give a default class standing of Freshman.
  5. Change the toString method to contain the class standing also.

At this point the model should be runnable and we should see the changes reflected in the list. Go ahead and run the app at this point. You should see all the students listed as before except with their classes shown. If you don't see the classes, be sure your constructor chaining is passing the freshman value to the 3 param version. Also be sure you added the class standing to the toString method.

================================================ View Changes Now you will need to add some widgets to the view so that when adding a new student, you can get the class standing from the user. Open the content_edit_student.xml file.

You will see that the dialog is laid out in a grid layout with labels and input fields. You will need to add to the grid some way to input the class standing. I used a combobox, but 4 radio buttons would work. You could use a text field and type in the standing, but that is error prone and you would need to validate that an incorrect entry was not made.

Once you have made the changes to the screen be sure and save the .fxml file.

Now you should be able to run the app again, just to make sure everything is ok. You should be able to hit the add student button and your dialog should pop up with your new UI features showing. It wont actually do anything yet, and if you used a combobox like me, it won't have any values in it. To make the display actually work, we have to edit one more class, the controller.

================================================ Controller Changes We must add items to the StudentEditController class (since this is the controller for our view).

  1. Add an @FXML reference to the widgets you added for class standing. This is how you will pull data out of the widget to pass to the model. Be sure the spelling for the fxid matches what is in the .fxml file exactly.
  2. Edit the initialize method to handle any start up code you need. If you used a combobox like me, this is where you will populate the box with the different classes (Freshman, etc). Remember that calling values() on an enum will give you an array. You will need to wrap this in an ObservableList. I made a static helper function that did that for me in the model.
  3. Edit the setStudent method to set your widget to a default value
  4. Edit the OK button press to pull the information out of your new widget and put into the student instance.
  5. If you used a free text entry field, you will need to edit the isInputValid method to check that a valid class was entered. If you used a constrained widget like radio buttons or combo box where it is impossible to enter a bad value, then you do not have to do any validation.

Now run the app. You should be able to enter new students and their standing and see it reflected in the UI. if not, then check your code through the complete stack. Are you calling the setters in the model to update the information? Are you pulling the information out of the widget correctly?

================================================ Submission

Zip up your complete project directory and submit to the assignment.

================================================ Grading

ss 2017-01-17 at 07 33 19