Lab Activity - MVC v1 - Feedback PDF

Title Lab Activity - MVC v1 - Feedback
Course Software Engineering
Institution Coventry University
Pages 6
File Size 219 KB
File Type PDF
Total Downloads 80
Total Views 131

Summary

MVC IMPLEMENTATION FEEDBACK...


Description

UML Modelling: Case Study – Priory Dental Surgery Appointment Booking System (PDS) Lab Activity: Model View Control (MVC) Implementation in Java - Feedback In this session, the task is to implement the class diagram (shown below) based on the MVC pattern. The following classes have been partly implemented for which you are required to complete the remaining code.

© Coventry University

YL Hedley



Create Model

Patient.java public class Patient { private int refNo; private String name;

//enter get and set methods for the attributes }

Patient.java (Solutions) public class Patient { private int refNo; private String name;

public int getRefNo() { return refNo; }

public void setRefNo(int no) { this.refNo = no; }

public String getName() { return name; }

public void setName(String aName) { this.name = aName; } }

© Coventry University

YL Hedley



Create View

PatientView.java public class PatientView { public void displayPatientDetails(String name, int ref){ System.out.println("Patient: "); System.out.println("Name: " + name); System.out.println("Ref No: " + ref); } }



Create Controller

PatientController.java public class PatientController { //add attributes required – pat for a Patient Object and view for a PatientView object //enter you code here

public PatientController(Patient aPat, PatientView aView){ //enter your code here

} public void setPatientName(String name){ pat.setName(name); } public String getPatientName(){ return pat.getName(); } public void setPatientNo(int no){ pat.setRefNo(no); } public int getPatientNo(){ return pat.getRefNo(); } public void updateView(){ view.displayPatientDetails(pat.getName(),pat.getRefNo()); } }

© Coventry University

YL Hedley

PatientController.java (Solutions) public class PatientController { //add attributes required – pat for a Patient Object and view for a PatientView object private Patient pat; private PatientView view;

public PatientController(Patient aPat, PatientView aView){ this.pat = aPat; this.view = aView; } public void setPatientName(String name){ pat.setName(name); } public String getPatientName(){ return pat.getName(); } public void setPatientNo(int no){ pat.setRefNo(no); } public int getPatientNo(){ return pat.getRefNo(); } public void updateView(){ view.displayPatientDetails(pat.getName(),pat.getRefNo()); } }

© Coventry University

YL Hedley

MVCPatternDemo.java public class MVCPatternDemo { public static void main(String[] args) {

//retrieve record (e.g. from the database) Patient pat = retrieveData();

//Create a view: to write patient details on console //enter you code here

// update model data to change the patient’s name to John and update the view //enter your code here }

private static Patient retrieveData(){ Patient patient1 = new Patient();

//SQL queries are omitted here patient1.setName("Robert"); patient1.setRefNo(10); return patient1; } }

© Coventry University

YL Hedley

MVCPatternDemo.java (Solutions) public class MVCPatternDemo {

public static void main(String[] args) {

//retrieve record (e.g. from the database) Patient pat = retrieveData();

//Create a view: to write patient details on console PatientView view = new PatientView();

PatientController controller = new PatientController(pat, view);

controller.updateView();

//update model data to change the patient’s name to John and update the view controller.setPatientName("John");

controller.updateView(); }

private static Patient retrieveData(){ Patient patient1 = new Patient();

//SQL queries are omitted here patient1.setName("Robert"); patient1.setRefNo(10); return patient1; } }

© Coventry University

YL Hedley...


Similar Free PDFs