Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

FACULTY OF ENGINEERING, SCIENCES AND TECHNOLOGY

Name Waqas
Registration ID 51203
Course Formal Method in Software
Instructor Atiya Masood

ASSIGNMENT # 02
Question # 01[5]
Read the attached paper with this assignment on Z specification and write a brief introduction
(200-300 words) about Z, highlighting its key features and benefits for creating schemas.

Named after the mathematical underpinning of Zermelo-Fraenkel set theory, Z is an official


language used in software development for the description and modeling of computer-based
systems. The language was created by the University of Oxford's programming research
department and provides accurate and clear system attributes by utilizing set theory and first-
order predicate logic. The fact that Z uses schemas to define both data structures and
operations—schemas are modular units that can specify a system's state space and permitted
state transitions—is one of its most significant characteristics. Z makes ensuring states and
actions are clear and modular by enclosing them in schemas, which aids in managing large,
complicated systems.

Z's formality allows one to explicitly specify and reason about the behavior of a system. This
helps developers find inconsistencies, ambiguities, or incompleteness early on, which
minimizes errors in the final product. It's also important to keep in mind that formal
techniques, such validation processes, can be used for verification due to its accuracy and
ensure that the system conforms with the specifications.

Abstraction is another important benefit of using Z. Z lets engineers talk about high-level
aspects of the system without getting into implementation details. Stakeholder
communication has improved as a result, and there is a solid foundation for the development
and testing phases to follow.

Page 1 of 3
FACULTY OF ENGINEERING, SCIENCES AND TECHNOLOGY
Question # 02[5]

Write Java code that corresponds to an example from a Z schema given in a research paper.

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class StudentSystem {


private Set<String> students;
private Map<String, String> rollNumbers;

// Constructor to initialize the system


public StudentSystem() {
this.students = new HashSet<>();
this.rollNumbers = new HashMap<>();
}

// Method to add a student


public boolean addStudent(String newStudent, String newRollNumber) {
if (students.contains(newStudent) || rollNumbers.containsValue(newRollNumber)) {
return false; // Cannot add the student if they already exist or the roll number is taken
}
students.add(newStudent);
rollNumbers.put(newStudent, newRollNumber);
return true;
}

// Method to remove a student


public boolean removeStudent(String student) {
if (!students.contains(student)) {
return false; // Cannot remove a student that does not exist
}
students.remove(student);
rollNumbers.remove(student);
return true;
}

// Method to get the roll number of a student


public String getRollNumber(String student) {
return rollNumbers.get(student);
}

// Method to check if a student exists


public boolean studentExists(String student) {
return students.contains(student);
}

Page 2 of 3
FACULTY OF ENGINEERING, SCIENCES AND TECHNOLOGY

public static void main(String[] args) {


StudentSystem system = new StudentSystem();

// Adding students
System.out.println(system.addStudent("Alice", "R001")); // true
System.out.println(system.addStudent("Bob", "R002")); // true
System.out.println(system.addStudent("Alice", "R003")); // false, Alice already exists
System.out.println(system.addStudent("Charlie", "R001")); // false, R001 is already
taken

// Removing students
System.out.println(system.removeStudent("Alice")); // true
System.out.println(system.removeStudent("Alice")); // false, Alice does not exist
anymore

// Checking student existence


System.out.println(system.studentExists("Bob")); // true
System.out.println(system.studentExists("Alice")); // false

// Getting roll number


System.out.println(system.getRollNumber("Bob")); // R002
}
}

Page 3 of 3

You might also like