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

A26-24 imtahan

The document outlines various programming tasks including creating flowcharts for algorithms, designing database tables for user registration and roles, and writing Java classes with constructors, methods, and inheritance. It also includes SQL procedures for managing database entries and connection functions for MySQL databases. Additionally, it covers concepts like encapsulation, method overloading, and abstract classes in Java.

Uploaded by

Nurlane Yaqubova
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)
3 views

A26-24 imtahan

The document outlines various programming tasks including creating flowcharts for algorithms, designing database tables for user registration and roles, and writing Java classes with constructors, methods, and inheritance. It also includes SQL procedures for managing database entries and connection functions for MySQL databases. Additionally, it covers concepts like encapsulation, method overloading, and abstract classes in Java.

Uploaded by

Nurlane Yaqubova
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/ 20

1. Diaqramlar (Flowchart) ilə Giriş əməliyyatının alqoritmasını hazırlayın.

(
https://app.diagrams.net/)
2. Diaqramlar (Flowchart) ilə kvadrat tənliyin nəticəsinin tapilması əməliyyatinin
alqoritmasinj hazırlayın.( https://app.diagrams.net/)
3. Məlumat bazasında istifadəçilərin qeydiyyatı,vəzifə və icazələrin verilmə proqramı üçün
lazım olan cədvəlləri hazırlayın.

CREATE TABLE Users (


UserID INT AUTO_INCREMENT PRIMARY KEY,
Username VARCHAR(50) NOT NULL UNIQUE,
PasswordHash VARCHAR(255) NOT NULL,
Email VARCHAR(100) UNIQUE,
FullName VARCHAR(100),
CreatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE Roles (


RoleID INT AUTO_INCREMENT PRIMARY KEY,
RoleName VARCHAR(50) NOT NULL UNIQUE,
Description TEXT
);

CREATE TABLE Permissions (


PermissionID INT AUTO_INCREMENT PRIMARY KEY,
PermissionName VARCHAR(50) NOT NULL UNIQUE,
Description TEXT
);

CREATE TABLE UserRoles (


UserRoleID INT AUTO_INCREMENT PRIMARY KEY,
UserID INT NOT NULL,
RoleID INT NOT NULL,
AssignedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (UserID) REFERENCES Users(UserID) ON DELETE CASCADE,
FOREIGN KEY (RoleID) REFERENCES Roles(RoleID) ON DELETE CASCADE
);

CREATE TABLE RolePermissions (


RolePermissionID INT AUTO_INCREMENT PRIMARY KEY,
RoleID INT NOT NULL,
PermissionID INT NOT NULL,
FOREIGN KEY (RoleID) REFERENCES Roles(RoleID) ON DELETE CASCADE,
FOREIGN KEY (PermissionID) REFERENCES Permissions(PermissionID) ON
DELETE CASCADE
);
CREATE TABLE AuditLogs (
LogID INT AUTO_INCREMENT PRIMARY KEY,
UserID INT,
Action VARCHAR(255),
ActionTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (UserID) REFERENCES Users(UserID) ON DELETE SET NULL
);
4. MySQL məlumat bazasında “Deletelessons” adlı bir Lessons(id, Lessonname, type,
description) cədvəlinin bütün məlumatlarını silən procedure (və ya funksiya) hazırla.

DELIMITER //

CREATE PROCEDURE DeleteAllLessons()


BEGIN
DELETE FROM Lessons;
END //

DELIMITER ;

CALL DeleteAllLessons();

5. MySQL məlumat bazasında House(id, name, description) cədvəlinə məlumat əlavə etmək
üçün funksiya (və ya procedure) hazırla.

DELIMITER //

CREATE PROCEDURE AddHouse(


IN p_name VARCHAR(255),
IN p_description TEXT
)
BEGIN
INSERT INTO House(name, description)
VALUES (p_name, p_description);
END //

DELIMITER ;

-- Procedure-u icra etmək üçün nümunə:


CALL AddHouse('Beautiful Villa', 'A large villa with a garden and pool.');
6. MySQL məlumat bazasında Users(id, name, surname, username, password, token, active)
və Roles(id, name, desc) cədvəlləri hazırla və UsersRoles cədvəli ilə əlaqələndir.

CREATE TABLE Users (


id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
surname VARCHAR(50) NOT NULL,
username VARCHAR(50) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
token VARCHAR(255),
active BOOLEAN NOT NULL DEFAULT TRUE
);

CREATE TABLE Roles (


id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
`desc` TEXT
);

CREATE TABLE UsersRoles (


id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
role_id INT NOT NULL,
FOREIGN KEY (user_id) REFERENCES Users(id) ON DELETE CASCADE,
FOREIGN KEY (role_id) REFERENCES Roles(id) ON DELETE CASCADE
);
7. Java proqramlaşdırma dilində “City” sinifinin daxilində constructor düzəlt.

public class City {


// Sinifin özəllikləri (fields)
private String name;
private String country;
private int population;

public City(String name, String country, int population) {


this.name = name;
this.country = country;
this.population = population;
}

public String getName() {


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

public String getCountry() {


return country;
}

public void setCountry(String country) {


this.country = country;
}

public int getPopulation() {


return population;
}

public void setPopulation(int population) {


this.population = population;
}

@Override
public String toString() {
return "City{name='" + name + "', country='" + country + "', population=" +
population + '}';
}

public static void main(String[] args) {


City city = new City("Baku", "Azerbaijan", 2200000);
System.out.println(city);
}
}
8. Java proqramlasdirma dilinde "SmartHome" sinifinin daxilinde constructor duzelt.

public class SmartHome {


private String homeName;
private String location;
private boolean isSecurityEnabled;

public SmartHome(String homeName, String location, boolean isSecurityEnabled) {


this.homeName = homeName;
this.location = location;
this.isSecurityEnabled = isSecurityEnabled;
}

public String getHomeName() {


return homeName;
}

public void setHomeName(String homeName) {


this.homeName = homeName;
}

public String getLocation() {


return location;
}

public void setLocation(String location) {


this.location = location;
}

public boolean isSecurityEnabled() {


return isSecurityEnabled;
}

public void setSecurityEnabled(boolean securityEnabled) {


isSecurityEnabled = securityEnabled;
}

public static void main(String[] args) {


SmartHome smartHome = new SmartHome("Smart Villa", "Baku", true);
System.out.println("Home Name: " + smartHome.getHomeName());
System.out.println("Location: " + smartHome.getLocation());
System.out.println("Security Enabled: " + smartHome.isSecurityEnabled());
}
}
9. Java proqramlaşdırma dilində “Parent” və “Child” sinifi tərtib edin və “Child” sinifini
“Parent” sinifinə extend edin.

class Parent {
private String name;

public Parent(String name) {


this.name = name;
}

public String getName() {


return name;
}

public void displayInfo() {


System.out.println("Parent Name: " + name);
}
}

class Child extends Parent {


private int age;

public Child(String name, int age) {


super(name);
this.age = age;
}

public int getAge() {


return age;
}

@Override
public void displayInfo() {
super.displayInfo();
System.out.println("Child Age: " + age);
}

public static void main(String[] args) {


Child child = new Child("John", 10);
child.displayInfo();
}
}
10. Java proqramlaşdırma dilində Access Modifiers-in növlərini “simple” adlı sinifin
daxilində metodsuz hazırla.

public class Simple {

public String publicField;

protected String protectedField;

String defaultField;

private String privateField;

}
11. Java proqramlaşdırma dilində adı “DevFunction” və inputu (girişi) olmayan Recursive
funksiya hazırla.

public class DevFunction {

public static void devFunction(int count) {


if (count == 0) {
return;
}
System.out.println("This is recursion call number: " + count);
devFunction(count - 1);
}

public static void main(String[] args) {


devFunction(5);
}
}
12. Project (id,name, about, startdate, enddate, active) cedvelini Java proqramlasdirma
dilinde inkapsulyasiyasini (encapsulation) hazirla.

public class Project {


private int id;
private String name;
private String about;
private String startDate;
private String endDate;
private boolean active;

// Constructor
public Project(int id, String name, String about, String startDate, String endDate,
boolean active) {
this.id = id;
this.name = name;
this.about = about;
this.startDate = startDate;
this.endDate = endDate;
this.active = active;
}

// Getter və Setter metodları


public int getId() {
return id;
}

public void setId(int id) {


this.id = id;
}

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}

public String getAbout() {


return about;
}

public void setAbout(String about) {


this.about = about;
}

public String getStartDate() {


return startDate;
}

public void setStartDate(String startDate) {


this.startDate = startDate;
}

public String getEndDate() {


return endDate;
}

public void setEndDate(String endDate) {


this.endDate = endDate;
}

public boolean isActive() {


return active;
}

public void setActive(boolean active) {


this.active = active;
}

// Məlumatları çap etmək üçün metod


@Override
public String toString() {
return "Project [id=" + id + ", name=" + name + ", about=" + about + ", startDate="
+ startDate
+ ", endDate=" + endDate + ", active=" + active + "]";
}

public static void main(String[] args) {


Project project = new Project(1, "Java Project", "A sample Java project", "2025-01-
01", "2025-12-31", true);
System.out.println(project);
}
}
13. Role (id, rolename, description) cedvelinin inkapsulasiyasini (encapsulation) Java
proqramlasdirma dilinde hazirla.

public class Role {


private int id;
private String roleName;
private String description;

public Role(int id, String roleName, String description) {


this.id = id;
this.roleName = roleName;
this.description = description;
}

public int getId() {


return id;
}
public void setId(int id) {
this.id = id;
}

public String getRoleName() {


return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}

public String getDescription() {


return description;
}
public void setDescription(String description) {
this.description = description;
}

@Override
public String toString() {
return "Role [id=" + id + ", roleName=" + roleName + ", description=" + description
+ "]";
}

public static void main(String[] args) {


Role role = new Role(1, "Admin", "Administrator role with full access");
System.out.println(role);
}
}
14. Java proqramlaşdırma dilində “Masters” sinifi adı ilə və daxilində void AddStudent()
(System.out.println("Lessons");) metodu olan sinif hazırla və “Students” sinifində
AddStudent() metodunun Override-ını hazırla.

class Masters {
public void AddStudent() {
System.out.println("Lessons");
}
}

class Students extends Masters {


@Override
public void AddStudent() {
System.out.println("Students");
}

public static void main(String[] args) {


Masters master = new Masters();
master.AddStudent();

Students student = new Students();


student.AddStudent();
}
}
15. Java proqramlasdirma dilinde "University" sinifi adı ile ve daxilinde void UpdateSubject
( ) {System.out.println("Fenler");] metodu olan sinif hazirla ve "Subject sinifinde
"UpdateSubject ( )" metodunun Override-ini hazirla.

class University {
public void UpdateSubject() {
System.out.println("Fenler");
}
}

class Subject extends University {


@Override
public void UpdateSubject() {
System.out.println("Subject Updated");
}

public static void main(String[] args) {


University university = new University();
university.UpdateSubject();

Subject subject = new Subject();


subject.UpdateSubject();
}
}
16. Java proqramlasdirma dilinde Aritmetic sinifin daxilinde abstrack class-i duzeldin,
daxilinde "int calculateSum (int a, int b);" metodunu yazin ve Calculator class-ina extend
edib Override olan funksiyalari yazin.

abstract class Arithmetic {


public abstract int calculateSum(int a, int b);
}

class Calculator extends Arithmetic {


@Override
public int calculateSum(int a, int b) {
return a + b;
}

public static void main(String[] args) {


Calculator calculator = new Calculator();
int result = calculator.calculateSum(5, 3);
System.out.println("Sum: " + result);
}
}
17. void Checking (String a ) {System.out.println("Test");} funksiyasinin Overloading-ini
Java proqramlasdirma dilinde "Register" adi ile olan sinifde hazirla.

class Register {
public void Checking(String a) {
System.out.println("Test");
}

public void Checking(int a) {


System.out.println("Test with integer: " + a);
}

public static void main(String[] args) {


Register register = new Register();
register.Checking("Test String");
register.Checking(123);
}
}
18. portu 3321nolan MySQL Melumat bazasina elaqe (Connection) funksiyasini Java
proqramlasdirma dilinde "OurDbConfig" adi ile funksiyasini yazin.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class OurDbConfig {

public static Connection connectToDatabase() {


String url = "jdbc:mysql://localhost:3321/elnur_database ";
String username = "elnur";
String password = "elnur";

try {
Connection connection = DriverManager.getConnection(url, username,
password);
System.out.println("Connection successful!");
return connection;
} catch (SQLException e) {
System.out.println("Connection failed: " + e.getMessage());
return null;
}
}

public static void main(String[] args) {


connectToDatabase();
}
}
19. Portu 3307 olan MySQL Məlumat bazasına əlaqə (Connection) funksiyasını Java
proqramlaşdırma dilində “ServicesDbConnect” adı ilə funskiyasını yazın.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ServicesDbConnect {

public static Connection connectToDatabase() {


String url = "jdbc:mysql://localhost:3307/elnur_database ";
String username = "elnur ";
String password = "elnur ";

try {
Connection connection = DriverManager.getConnection(url, username,
password);
System.out.println("Connection successful!");
return connection;
} catch (SQLException e) {
System.out.println("Connection failed: " + e.getMessage());
return null;
}
}

public static void main(String[] args) {


connectToDatabase();
}
}
20. Məlumat bazasında olan Operation (id,operationname,description,active) cədvəli üçün
insert(əlavə etmək) əməliyyatını yerinə yetirən funksiyanı və proqramlaşdırma dilində
“AddOperation”adı ilə funksiyasını hazırla.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class AddOperation {

public static void insertOperation(String operationName, String description, boolean


active) {
String url = "jdbc:mysql://localhost:3307/elnur_database ";
String username = "elnur ";
String password = "elnur ";
String sql = "INSERT INTO Operation (operationname, description, active)
VALUES (?, ?, ?)";

try (Connection connection = DriverManager.getConnection(url, username,


password);
PreparedStatement preparedStatement = connection.prepareStatement(sql)) {

preparedStatement.setString(1, operationName);
preparedStatement.setString(2, description);
preparedStatement.setBoolean(3, active);

int rowsAffected = preparedStatement.executeUpdate();


if (rowsAffected > 0) {
System.out.println("Operation added successfully!");
}

} catch (SQLException e) {
System.out.println("Error inserting operation: " + e.getMessage());
}
}

public static void main(String[] args) {


insertOperation("Sample Operation", "This is a sample operation description", true);
}
}

You might also like