0% found this document useful (0 votes)
0 views

Mvc Program

Uploaded by

Monika Kumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Mvc Program

Uploaded by

Monika Kumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

CODE:

// Main class

public class Main {

public static void main(String[] args) {

// Fetching the employee record based on the employee_id from the


database

Employee model = retrieveEmployeeFromDatabase();

// Creating a view to display Employee details on the console

EmployeeView view = new EmployeeView();

// Creating the controller with the model and view

EmployeeController controller = new EmployeeController(model,


view);

// Displaying the initial employee details

System.out.println("Employee Details before updating:");

controller.updateView();

// Updating the model data

controller.setEmployeeName("Bhopal");

System.out.println("\nEmployee Details after updating:");

controller.updateView();

private static Employee retrieveEmployeeFromDatabase() {

Employee employee = new Employee();

employee.setName("VIT");

employee.setId("112");

employee.setDepartment("SCSE");
return employee;

// Model Class

class Employee {

private String name;

private String id;

private String department;

public String getName() {

return name;

public void setName(String name) {

this.name = name;

public String getId() {

return id;

public void setId(String id) {

this.id = id;

public String getDepartment() {

return department;

}
public void setDepartment(String department) {

this.department = department;

// View Class

class EmployeeView {

public void printEmployeeDetails(String employeeName, String


employeeId, String department) {

System.out.println("Employee Details:");

System.out.println("Name: " + employeeName);

System.out.println("ID: " + employeeId);

System.out.println("Department: " + department);

// Controller Class

class EmployeeController {

private Employee model;

private EmployeeView view;

public EmployeeController(Employee model, EmployeeView view) {

this.model = model;

this.view = view;

public void setEmployeeName(String name) {

model.setName(name);
}

public String getEmployeeName() {

return model.getName();

public void setEmployeeId(String id) {

model.setId(id);

public String getEmployeeId() {

return model.getId();

public void setEmployeeDepartment(String department) {

model.setDepartment(department);

public String getEmployeeDepartment() {

return model.getDepartment();

public void updateView() {

view.printEmployeeDetails(model.getName(), model.getId(),
model.getDepartment());

OUTPUT:

You might also like