L04B: Assignment – Basic Listening with MVC
Do not use the scanner class or any other user input request. You application should be self
contained and run without user input.
Assignment Objectives
- Practice on implementing a MVC project
- Start working with Java Graphics
Deliverables
A zipped Java project according to the How to submit Labs and Assignments guide(attached in the email).
O.O. Requirements (these items will be part of your grade)
- One class, one file. Don’t create multiple classes in the same .java file
- Don’t use static variables and methods
- Encapsulation: make sure you protect your class variables and provide access to them through get and set methods
- all the classes are required to have a constructor that receives all the attributes as parameters and update the attributes accordingly
- Follow Horstmann’s Java Language Coding Guidelines
(http://higheredbcs.wiley.com/legacy/college/horstmann/1118087887/style_guide/styleguide.htm)
- Organized in packages (MVC Model View Controller)
Contents
Regarding the starter Netbeans project you should keep using your project from the last assignment. The Netbeans project that you will use should look like this:
<default package> App.java
Controller
Controller.java
Model
Model.java
MailAddress.java
Student.java
View InitialPanel.java MainFrame.java View.java
Functionality
View is already displaying the students’ information according to the last assignment specification.
Now, the user will be able to click in each button. This action will trigger an update in the text of the button. The new text will bring a new value for credits (obtained using the creditsThisSemester( ) method in student)
Below is a link to a short clip showing the functionality.
A04C_demo.mov (attached in the email)
The number of credits is calculated on the fly in Model and might vary in the output of your assignment. You will need to work on
Controller to implement the inner listeners
Then
- controller will learn that the button was clicked
- asks model for an updated student’s information including a new value for credits
- send the information to be displayed in the button that was clicked
Most likely Model and View have all the functionality that is needed. Most of the work in this assignment is on Controller.
The classes
App
it has the main method which is the method that Java looks for and runs to start any application
it creates 3 objects, one of the Model class, one of the View class and one of the Controller class. When it creates Controller, it passes the two other objects as input parameters so that Controller has access to Model and View.
Model model = new Model(); View view = new View();
Controller controller = new Controller(model, view);
Controller
will implement inner listeners for each button in View
when a button is clicked, Controller will be informed by the listening mechanism and
will retrieve from Model (using the model object) data about the corresponding student (first button, first student; second button, second student; third button, third student)
will pass the data to View, which will display it in the appropiate button
Model
it is already given in the starter project although you will need to add some functionality
it needs a method that returns data about a specific student in the array (you will write this method or a similar one)
it might need a method that returns all the students’ information but packaged as individual elements
public class Model
ArrayList<Student> sts = new ArrayList<>();
public Model()
//creates 3 students
MailAddress addr1 = new mailAddress(“107 W College Avenue”, “State College”, “PA”, 16801); Student st1 = new student(“Emily”, “Smith”, 20, addr1);
MailAddress addr2 = new mailAddress(“200 W College Avenue”, “State College”, “PA”, 16801); Student st2 = new student(“Mary”, “Doe”, 20, addr2);
MailAddress addr3 = new mailAddress(“300 W College Avenue”, “State College”, “PA”, 16801); Student st3 = new student(“John”, “Doe”, 20, addr3);
//add them to the array of students sts.add(st1);
sts.add(st2);
sts.add(st3);
MailAddress
it is used by the Student class and doesn’t need any updates
Student
it is used in Model and doesn’t need any updates.
View
In this assignment, is much more complex than in the previous assignment it has a Frame
It has a Panel
The panel has buttons
it needs a method to receive information to be displayed in its buttons
the method needs to receive as an input parameter the text information and the number (or index) of the button to be used
MainFrame
it is a JFrame used as a container for a JPanel
InitialPanel
it needs a layout
it has 3 buttons (the best place to create them might be the constructor)
a method to display information on its buttons the input parameters should be
the string to be displayed
a number telling in which button it should be displayed
The post L04B: Assignment – Basic Listening with MVC appeared first on My Assignment Online.