Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 4 (25 marks) Program 4.1 below shows the use of a single code do Everything.jsp to handle both the request and response, to handle

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Question 4 (25 marks) Program 4.1 below shows the use of a single code do Everything.jsp to handle both the request and response, to handle database access and to perform the business logic processing. 2 3 4
    6 Patient List: Ward 2021"); 20 out.print("
    "); 21 while (rs.next()) 3 22 out.print("
  1. Patient Detail "); 23 out.println(" Patient ID: 24 "+rs.getString("id")); 25 out.println(" Name : "+rs.getString("name")); 26 out.println(" Address: 27 "+rs.getString("address")); 28 out.print("
  2. "); 29 } 30 out.print("
"); 31 32 } catch (Exception ex) 33 ex.printStackTrace(); 34 35 36 %> 37 38 39 a) Analyse and argue why Program 4.1 above is considered as a bad design practice. (2 marks) b) Explain how Model View Controller (MVC) design pattern is better than the design applied in Program 4.1. (2 marks) 4 c) Illustrate suitable diagram to depict MVC design pattern and how the program entities in Program 4.1 interacts with each other to accomplish tasks. (4 marks) d) Based on your answer in (c), use the MVC design principle to divide tasks performed by doEverything.jsp into several program entities. Identify the program entities that belong to different packages, together with suitable package stereotypes (e.g package Model, View, Controller etc). Note: Name the program entities with suitable file name. (4 marks) Given a Program 4.2 below: Patient.java, a partial code of Program 4.3: PatientControllerServlet.java, Program 4.4: viewPatient.jsp and Program 4.5: viewMenu.jsp //Program 4.2 - Patient.java package Model; public class Patient implements Serializable ! private String id, name, email; 10 11 12 13 14 15 public Patient() { //default constructor ) public Patient (String id, String name, String email) //parameterized constructor this.id = id; this.name name; this.email email; 1 //other beans code omitted for brevity 16 7/Program 4.3 - partial code in Patient Controller Servlet 17 18 protected void processRequest(HttpServletRequest request, 19 HttpServletResponse response) throws ServletException, 20 IOException 21 22//create object menu_today and add to session 23 String() menu_today = ("Nasi Ayam", "Satay", "Wantan 24 Noodle", "Double Burger"); 25 26//create 3 Patient objects, pl, p2 & p3 27 Patient pl - new Patient ("AC101","p1 Ali","ali@gmail.com"); 28 Patient p2 - new Patient ("BE202","p2 Bala", 29"bala@fc.utm.my"); 30 Patient p3 - new Patient ("CC303", "p3 Chua", 31 "chua@yahoo.com"); 32 33 35 34// ---complete your code for 0.4(e) here--- 36//write a code to add pl as an application scope object with 37 name 'patient! 381/write the code to add p2 as a request scope object with 39 same name 'patient' 40//write the code to add p3 as a session scope object with 41 same name 'patient' 42//write code to add menu_today into session 43 44 request.getRequestDispatcher ("viewMenu.jsp"). forward (request 45 response); } 47 48 49 // Program 4.4: partial code in viewPatient.jsp 50 51 52 |

Patient List: Ward 2021

53 54

Current temperature: $135* 9/5 + 32) Fahrenheit

Result is : $(10 4 2 - 0 ? "poor":"lucky" }

Sales is:

if> ----- END OF QUESTIONS ----- 7 Question 4 (25 marks) Program 4.1 below shows the use of a single code do Everything.jsp to handle both the request and response, to handle database access and to perform the business logic processing. 2 3 4

    6 Patient List: Ward 2021"); 20 out.print("
    "); 21 while (rs.next()) 3 22 out.print("
  1. Patient Detail "); 23 out.println(" Patient ID: 24 "+rs.getString("id")); 25 out.println(" Name : "+rs.getString("name")); 26 out.println(" Address: 27 "+rs.getString("address")); 28 out.print("
  2. "); 29 } 30 out.print("
"); 31 32 } catch (Exception ex) 33 ex.printStackTrace(); 34 35 36 %> 37 38 39 a) Analyse and argue why Program 4.1 above is considered as a bad design practice. (2 marks) b) Explain how Model View Controller (MVC) design pattern is better than the design applied in Program 4.1. (2 marks) 4 c) Illustrate suitable diagram to depict MVC design pattern and how the program entities in Program 4.1 interacts with each other to accomplish tasks. (4 marks) d) Based on your answer in (c), use the MVC design principle to divide tasks performed by doEverything.jsp into several program entities. Identify the program entities that belong to different packages, together with suitable package stereotypes (e.g package Model, View, Controller etc). Note: Name the program entities with suitable file name. (4 marks) Given a Program 4.2 below: Patient.java, a partial code of Program 4.3: PatientControllerServlet.java, Program 4.4: viewPatient.jsp and Program 4.5: viewMenu.jsp //Program 4.2 - Patient.java package Model; public class Patient implements Serializable ! private String id, name, email; 10 11 12 13 14 15 public Patient() { //default constructor ) public Patient (String id, String name, String email) //parameterized constructor this.id = id; this.name name; this.email email; 1 //other beans code omitted for brevity 16 7/Program 4.3 - partial code in Patient Controller Servlet 17 18 protected void processRequest(HttpServletRequest request, 19 HttpServletResponse response) throws ServletException, 20 IOException 21 22//create object menu_today and add to session 23 String() menu_today = ("Nasi Ayam", "Satay", "Wantan 24 Noodle", "Double Burger"); 25 26//create 3 Patient objects, pl, p2 & p3 27 Patient pl - new Patient ("AC101","p1 Ali","ali@gmail.com"); 28 Patient p2 - new Patient ("BE202","p2 Bala", 29"bala@fc.utm.my"); 30 Patient p3 - new Patient ("CC303", "p3 Chua", 31 "chua@yahoo.com"); 32 33 35 34// ---complete your code for 0.4(e) here--- 36//write a code to add pl as an application scope object with 37 name 'patient! 381/write the code to add p2 as a request scope object with 39 same name 'patient' 40//write the code to add p3 as a session scope object with 41 same name 'patient' 42//write code to add menu_today into session 43 44 request.getRequestDispatcher ("viewMenu.jsp"). forward (request 45 response); } 47 48 49 // Program 4.4: partial code in viewPatient.jsp 50 51 52 |

Patient List: Ward 2021

53 54

Current temperature: $135* 9/5 + 32) Fahrenheit

Result is : $(10 4 2 - 0 ? "poor":"lucky" }

Sales is:

if> ----- END OF QUESTIONS ----- 7

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mysql Examples Explanations Explain Examples

Authors: Harry Baker ,Ray Yao

1st Edition

B0CQK9RN2J, 979-8872176237

More Books

Students also viewed these Databases questions