Notes, summaries, assignments, exams, and exercises for Computer science for Other courses

Test Cases and Code Review for Order and Hotel Reservation Validation

Computer science3.05 KB

Validation Test Cases

Variables, Rules, Valid and Invalid Classes

Variable / Rule / Valid Class / Invalid Class

order_id / Datatype / ECV1: 32 hex string / ECNV1: not a string

order_id / Content: hexadecimal characters / ECV2: 32 hex string / ECNV2: 32 characters, non-hex

order_id / Size = 32 characters / ECV3: 32 hex string; BVV1: 32 hex string / ECNV3: more than 32 characters; ECNV4: less than 32 characters; BVNV1: 33 hex characters; BVNV2: 31 hex characters

new_order_type / Datatype / ECV4: valid value / ECNV5: datatype not string

new_order_type / Allowed values / ECV5: "REG"; ECV6: "PREM" / ECNV6: other value

- / Outputs / ECV7: valid phone number / ECNV7: Ex: InvalidOrder_idSize; ECNV8: Ex: order_idNotStr; ECNV9: Ex: ord_idNotHexVal; ECNV10: alreadySent;...

Continue reading "Test Cases and Code Review for Order and Hotel Reservation Validation" »

Java Swing and MySQL Registration Form Application

Computer science7.05 KB

Java Swing and MySQL Registration Form Implementation

This project demonstrates how to create a desktop user registration form in Java using the Swing GUI toolkit and MySQL database connectivity (JDBC). It provides input handling, field validation, password confirmation, and persistent storage via prepared statements.

Complete Java Source Code

package javamysqlconnect;

import javax.swing.*;
import java.awt.event.*;
import java.sql.*;

public class RegistrationForm {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(CreateRegistrationForm::new);
    }
}

class CreateRegistrationForm extends JFrame implements ActionListener {
    JTextField userIdInput, nameInput, addressInput, phoneInput, genderInput, emailInput;
...
Continue reading "Java Swing and MySQL Registration Form Application" »

Binary Trees and Graph Traversal: A Complete Data Structures Reference

Computer science366.46 KB

Binary Tree Basics

  • Root node: the node located at the top level of a binary tree, with no parent node.
  • Leaf node: a node with no child nodes, whose two pointers both point to None.
  • Edge: a line segment connecting two nodes, i.e., a node reference (pointer).
  • The level of a node: increases from top to bottom; the root node is at level 1.
  • The degree of a node: the number of its child nodes. In a binary tree, the degree is 0, 1, or 2.
  • The height of a binary tree: the number of edges from the root node to the farthest leaf node.
  • The depth of a node: the number of edges from the root node to that node.
  • The height of a node: the number of edges from the farthest leaf node to that node.

Example of inserting and deleting a node:

TreeNode P = new TreeNode(0);
/
...
Continue reading "Binary Trees and Graph Traversal: A Complete Data Structures Reference" »

8051 Microcontroller: LCD Interfacing and ADC0804 Control

Computer science2.51 KB

LCD Interfacing with 8051

#include <reg51.h>

sbit rs = P2^0;
sbit rw = P2^1;
sbit e = P2^2;

void msdelay(unsigned int time) {
    unsigned int i, j;
    for(i = 0; i < time; i++)
        for(j = 0; j < 1275; j++);
}

void lcd_cmd(unsigned char command) {
    P1 = command;
    rs = 0;
    rw = 0;
    e = 1;
    msdelay(1);
    e = 0;
}

void lcd_init() {
    lcd_cmd(0x38); // 2 lines and 5x7 matrix
    msdelay(10);
    lcd_cmd(0x0F);
    msdelay(10);
    lcd_cmd(0x01);
    msdelay(10);
    lcd_cmd(0x80);
    msdelay(10);
}

void lcd_data(unsigned char disp_data) {
    P1 = disp_data;
    rs = 1;
    rw = 0;
    e = 1;
    msdelay(1);
    e = 0;
}

void main() {
    unsigned char a[4] = "KTU";
    int l = 0;
    lcd_init();
    while(
...
Continue reading "8051 Microcontroller: LCD Interfacing and ADC0804 Control" »

Java Interview Questions: OOP, Collections, Concurrency & Database

Computer science4.8 KB

Java Interview Questions on OOP Concepts

  • What is the difference between loose coupling and tight coupling?

İki nesne birbirine çok fazla bağlıysa, yani biri değiştiğinde diğerini de değiştirmek gerekiyorsa tight coupling; değiştirmek gerekmiyorsa, birbirinden bağımsızsa loose coupling deriz.

  • Cohesion and coupling

Cohesion is defined as the degree of relationship between elements of the same module. Coupling is defined as the degree of interdependence between the modules.

  • SOLID
  • Single Responsibility Principle (Tek servis tek iş yapar)
  • Open/Closed Principle (Yeni class için açık, modify için kapalı bir kod)
  • Liskov Substitution Principle (Parent ve child classlar yer değiştirdiğinde aynı özellikleri gösterecek şekilde hiyerarşi
...
Continue reading "Java Interview Questions: OOP, Collections, Concurrency & Database" »

Java ConjuntoDatos Class: Reading and Processing Text File Data

Computer science3.7 KB

ConjuntoDatos Class in Java

public ConjuntoDatos(File archivoTexto, String separador, Locale locale) throws Exception {
    this.archivoTexto = archivoTexto;
    this.separador = separador;
    this.locale = locale;
    cabecera = cabecera(this.archivoTexto);
    numeroLineas = numLineas(this.archivoTexto);
    numeroColumnas = numColumnas(this.archivoTexto);
    datos = leerDatos(this.archivoTexto, numeroLineas, numeroColumnas);
}

Reading the Header

private List cabecera(File archivoTexto) throws Exception {
    cabecera = new ArrayList();
    Scanner fichero = new Scanner(archivoTexto);
    String primeraLinea = fichero.nextLine();
    Scanner scLinea = new Scanner(primeraLinea);
    scLinea.useDelimiter(separador)

...
Continue reading "Java ConjuntoDatos Class: Reading and Processing Text File Data" »

Java Entrada y Salida: Catálogo de Productos con Lectura y Escritura de Ficheros

Computer science7.05 KB

Entrada y salida en Java: catálogo de productos

A continuación se muestran las clases EntradaSalida, Producto, Catalogo y principal, que permiten introducir productos por teclado, mostrar el catálogo y guardarlo o leerlo desde un fichero.

Clase EntradaSalida

Esta clase centraliza la lectura de datos por teclado y el acceso a ficheros.

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Scanner;

public class EntradaSalida {
    private static Scanner teclado = new Scanner(System.in);

    public static String leeString(String mensaje) {
        System.out.println(mensaje);
        return teclado.nextLine();
    }

    public static float leeFloat(String mensaje)
...
Continue reading "Java Entrada y Salida: Catálogo de Productos con Lectura y Escritura de Ficheros" »

Pascal Programs: Salary, Survey and Loop Examples

Computer science2.85 KB

Pascal Programs

Program 1: pais

program pais;
var
  ano: integer;
  x, y: real;
begin
  writeln('ano');
  readln(ano);
  writeln('Y');
  readln(y);
  x := y * 2;
  while (y < x) do
  begin
    x := x * 1.03;
    y := y * 1.06;
    ano := ano + 1;
  end;
  writeln('X', x:8:2);
  writeln('Y', y:8:2);
  writeln('ano', ano);
end.

Program 2: caradepau

program caradepau;
var
  sexo, resp: char;
  id, numEnt, numS, numN, mascN, femS, masc23S, fem23N, col, lin: integer;
  percS, precN: real;
begin
  lin := 2;
  col := 3;
  numEnt := 0;
  numN := 0;
  numS := 0;
  femS := 0;
  mascN := 0;
  masc23S := 0;
  fem23N := 0;
  write(' IDADE SEXO RESP ');
  gotoxy(col, lin);
  readln(id);
  while (id > 0) do
  begin
    gotoxy(col+7, lin);
    readln(sexo)
...
Continue reading "Pascal Programs: Salary, Survey and Loop Examples" »

Classes Java para Passagens Nacionais e Internacionais

Computer science5.81 KB

O código a seguir apresenta um sistema de passagens desenvolvido em Java, utilizando herança e polimorfismo. A classe abstrata Passagem reúne os atributos comuns, enquanto as classes PassagemNacional e PassagemInternacional especializam o cálculo do valor total.

Classe abstrata Passagem

A classe Passagem define os atributos básicos de uma passagem, como número, nome do passageiro, origem, destino, quantidade, valor da passagem, tarifa, serviço de bordo e seu valor.

public abstract class Passagem {
private int numero;
private String nome;
private String origem;
private String destino;
private int quantidade;
private float valorPassagem;
private float tarifa;
private boolean servicoBordo;
private float valorServicoBordo;

public Passagem(
...
Continue reading "Classes Java para Passagens Nacionais e Internacionais" »

SQL y Java: Consultas, Funciones y Procedimientos

Computer science1.7 KB

Consultas SQL básicas con funciones de agregación

SELECT AVG(stock) FROM producto;


SELECT COUNT(numemp) FROM empleado
GROUP BY cargo;


SELECT SUM(precio) FROM producto;


SELECT MIN(sueldo), MAX(sueldo) FROM empleado;


SELECT nombre, limitecredito FROM cliente
WHERE nombre LIKE 'L%';


SELECT ciudad, direccion FROM oficina
ORDER BY codoficina DESC
GROUP BY codoficina DESC;


Función en PL/SQL: multiplicación

CREATE OR REPLACE FUNCTION multiplicacion(a INT, b INT)
RETURN INT AS salida INT;
BEGIN
  salida := a * b;
  RETURN salida;
END;


SELECT multiplicacion(10, 5) FROM dual;


BEGIN
  DBMS_OUTPUT.PUT_LINE(multiplicacion(10, 5));
END;


Procedimiento en PL/SQL: cálculo de fechas

CREATE OR REPLACE PROCEDURE sopaipa(entrada DATE) AS
troly DATE;
--lazo DATE;
BEGIN
  troly
...
Continue reading "SQL y Java: Consultas, Funciones y Procedimientos" »