program of paradigm and types of paradigm in detail
Programming Paradigms
A programming paradigm is a fundamental style or approach to programming that provides a
way to structure and organize code. Paradigms influence the design and implementation of
programs by providing specific principles and methodologies. Understanding different
paradigms is crucial for selecting the appropriate approach for a given problem and for
becoming a versatile and effective programmer.
Types of Programming Paradigms
Imperative Programming
Declarative Programming
Object-Oriented Programming (OOP)
Functional Programming
Procedural Programming
Logic Programming
Event-Driven Programming
1. Imperative Programming
Imperative programming is a paradigm that expresses computation in terms of statements that
change a program's state. It focuses on describing how a program operates, using statements
that explicitly change the program's state.
Example Languages: C, C++, Java, Python (when used imperatively)
Characteristics:
Use of variables to store state.
Use of loops and conditionals to control flow.
Focus on how to achieve the desired result.
Copy
// Example in C
int sum(int n) {
int total = 0;
for (int i = 1; i <= n; i++) {
total += i;
return total;
2. Declarative Programming
Declarative programming is a paradigm that expresses the logic of computation without
describing its control flow. It focuses on what the program should accomplish rather than how
to accomplish it.
Example Languages: SQL, HTML, CSS, Prolog, Haskell
Characteristics:
Focus on defining what needs to be done.
Typically involves higher-level abstractions.
Often used in domain-specific languages.
sql
Copy
-- Example in SQL
SELECT * FROM users WHERE age > 30;
3. Object-Oriented Programming (OOP)
Object-oriented programming (OOP) is a paradigm based on the concept of "objects," which are
instances of classes. Objects can contain data in the form of fields (attributes) and code in the
form of procedures (methods).
Example Languages: Java, C++, Python, Ruby
Characteristics:
Encapsulation: Bundling data and methods that operate on the data.
Inheritance: Creating new classes based on existing ones.
Polymorphism: Ability to treat objects of different classes through the same interface.
Abstraction: Hiding complex implementation details and showing only the necessary features.
java
Copy
// Example in Java
class Animal {
String name;
void makeSound() {
System.out.println("Some sound...");
class Dog extends Animal {
void makeSound() {
System.out.println("Bark");
}
4. Functional Programming
Functional programming is a paradigm where programs are constructed by applying and
composing functions. It emphasizes the use of pure functions, immutability, and avoiding side-
effects.
Example Languages: Haskell, Scala, Erlang, Lisp, Python (when used functionally)
Characteristics:
First-class and higher-order functions.
Pure functions: Functions that have no side effects.
Immutability: Data objects are not modified after creation.
Recursion over iteration.
haskell
Copy
-- Example in Haskell
sumList :: [Int] -> Int
sumList [] = 0
sumList (x:xs) = x + sumList(xs)
5. Procedural Programming
Procedural programming is a paradigm derived from structured programming, based on the
concept of procedure calls. Procedures, also known as routines, subroutines, or functions,
contain a series of computational steps to be carried out.
Example Languages: C, Pascal, Fortran
Characteristics:
Clearly defined procedures or functions.
Emphasis on sequence of actions to perform a task.
Use of local and global variables.
Copy
// Example in C
void greet() {
printf("Hello, World!");
6. Logic Programming
Logic programming is a paradigm based on formal logic. Programs are expressed in terms of
relations, and execution is the process of proving queries using these relations.
Example Languages: Prolog, Datalog
Characteristics:
Use of facts and rules to express logic.
Queries are used to retrieve data based on the logical relations.
Emphasis on "what" rather than "how".
7 Event-driven programming
Event-driven programming is a paradigm in which the flow of the program is determined by
events such as user actions (mouse clicks, key presses), sensor outputs, or message passing
from other programs.
Example Languages: JavaScript, C#, Visual Basic
Characteristics:
Programs respond to various events.
Use of event handlers to manage events.
Often used in graphical user interfaces (GUIs) and real-time systems.
javascript
Copy
// Example in JavaScript
document.getElementById('myButton').addEventListener('click', function() {
alert('Button was clicked!');
});
Summary
Understanding and mastering different programming paradigms is essential for effective
software development. Each paradigm offers unique strengths and is suitable for different
types of problems. Here’s a quick recap:
Imperative Programming: Focuses on how to perform tasks with explicit statements.
Declarative Programming: Focuses on what the outcome should be, without specifying how to
achieve it.
Object-Oriented Programming (OOP): Organizes code around objects and data encapsulation.
Functional Programming: Emphasizes pure functions and immutability.
Procedural Programming: Based on procedure calls and structured steps.
Logic Programming: Uses formal logic to express relations and rules.
Event-Driven Programming: Driven by events and event handlers, commonly used in GUIs and
real-time systems.
Each paradigm can be more effective depending on the task at hand. By understanding these
paradigms, developers can choose the most suitable approach, write better code, and solve
problems more efficiently.
Program of calculator
import java.util.Scanner;
public class IntegerOperations {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the first integer: ");
int num1 = scanner.nextInt();
System.out.print("Enter the second integer: ");
int num2 = scanner.nextInt();
System.out.println("Sum: " + sum(num1, num2));
System.out.println("Product: " + product(num1, num2));
System.out.println("Quotient: " + quotient(num1, num2));
System.out.println("Difference: " + difference(num1, num2));
scanner.close();
}
public static int sum(int a, int b) {
return a + b;
public static int product(int a, int b) {
return a * b;
public static int quotient(int a, int b) {
if (b == 0) {
System.out.println("Error: Division by zero");
return 0;
return a / b;
public static int difference(int a, int b) {
return a - b;
}
Program of to select head of department
import java.util.Scanner;
public class DepartmentHeads {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the name of the department: ");
String department = scanner.nextLine();
String message;
switch (department.toLowerCase()) {
case 1:"mulgeta":
message = "Head of IT";
system.out.println();
break;
case 2: "gebremariam":
message = "Head of CS";
system.out.println("He/She is not head of any department");
break;
case 3:"tedros":
message = "Head of IS";
system.out.println("He/She is not head of any department");
break;
default:
system.out.println("He/She is not head of any department");
break;
System.out.println(message);
scanner.close();
addition of two matrices (3X3)
import java.util.Scanner;
public class MatrixOperations {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Create a 3x3 matrix
int[][] matrix = new int[3][3];
System.out.println("Enter the elements of the 3x3 matrix:");
// Get input from the user and populate the matrix
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
System.out.print("Enter element at (" + i + ", " + j + "): ");
matrix[i][j] = scanner.nextInt();
// Display the input matrix
System.out.println("\nThe input matrix is:");
printMatrix(matrix);
// Perform matrix addition
int[][] resultMatrix = addMatrix(matrix, matrix);
System.out.println("\nThe result of matrix addition is:");
printMatrix(resultMatrix);
scanner.close();
// Function to add two matrices
public static int[][] addMatrix(int[][] matrix1, int[][] matrix2) {
int[][] result = new int[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
result[i][j] = matrix1[i][j] + matrix2[i][j];
}
}
return result;
// Function to print a matrix
public static void printMatrix(int[][] matrix) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
System.out.print(matrix[i][j] + " ");
System.out.println();
}
Multiplication of two matrices (3X3)
import java.util.Scanner;
public class MatrixMultiplication {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Create two 3x3 matrices
int[][] matrix1 = new int[3][3];
int[][] matrix2 = new int[3][3];
// Get input from the user and populate the matrices
System.out.println("Enter the elements of the first matrix:");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
System.out.print("Enter element at (" + i + ", " + j + "): ");
matrix1[i][j] = scanner.nextInt();
System.out.println("\nEnter the elements of the second matrix:");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
System.out.print("Enter element at (" + i + ", " + j + "): ");
matrix2[i][j] = scanner.nextInt();
// Multiply the matrices
int[][] resultMatrix = multiplyMatrices(matrix1, matrix2);
// Display the result matrix
System.out.println("\nThe result of matrix multiplication is:");
printMatrix(resultMatrix);
scanner.close();
// Function to multiply two matrices
public static int[][] multiplyMatrices(int[][] matrix1, int[][] matrix2) {
int[][] result = new int[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
result[i][j] += matrix1[i][k] * matrix2[k][j];
}
return result;
// Function to print a matrix
public static void printMatrix(int[][] matrix) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
System.out.print(matrix[i][j] + " ");
System.out.println();
}
please write a program about geometric for example circle ,
rectangle, triangle, using constructor Java
abstract class Geometric {
public Geometric() {
// Base constructor
public abstract double area();
public abstract double perimeter();
class Circle extends Geometric {
private double radius;
public Circle(double radius) {
this.radius = radius;
@Override
public double area() {
return Math.PI * radius * radius;
}
@Override
public double perimeter() {
return 2 * Math.PI * radius;
class Rectangle extends Geometric {
private double width;
private double height;
public Rectangle(double width, double height) {
this.width = width;
this.height = height;
@Override
public double area() {
return width * height;
@Override
public double perimeter() {
return 2 * (width + height);
}
class Triangle extends Geometric {
private double side1;
private double side2;
private double side3;
public Triangle(double side1, double side2, double side3) {
this.side1 = side1;
this.side2 = side2;
this.side3 = side3;
@Override
public double area() {
// Using Heron's formula
double s = (side1 + side2 + side3) / 2;
return Math.sqrt(s * (s - side1) * (s - side2) * (s - side3));
@Override
public double perimeter() {
return side1 + side2 + side3;
}
public class Main {
public static void main(String[] args) {
Circle circle = new Circle(5.0);
System.out.println("Circle: Area = " + circle.area() + ", Perimeter = " + circle.perimeter());
Rectangle rectangle = new Rectangle(4.0, 7.0);
System.out.println("Rectangle: Area = " + rectangle.area() + ", Perimeter = " +
rectangle.perimeter());
Triangle triangle = new Triangle(3.0, 4.0, 5.0);
System.out.println("Triangle: Area = " + triangle.area() + ", Perimeter = " +
triangle.perimeter());
For loop sum
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int x,y;
int sum=0;
Scanner D=new Scanner(System.in);
Scanner C=new Scanner(System.in);
x=D.nextInt();
y=C.nextInt();
for(x=0;x<=y;x++)
sum=sum+x;
System.out.println(sum);
Full Grade
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String grade ;
Scanner A= new Scanner(System.in);
while(true){
System.out.println("enter your mark");
double mark=A.nextDouble();
if(mark>=100){
grade="check";
else if (mark>=90){
grade="A+";
else if (mark>=85){
grade="A";
else if (mark>=80){
grade="A-";
else if (mark>=75){
grade="B+";
else if(mark>=70){
grade="B";
else if (mark>=65){
grade="B-";
else if (mark>=60){
grade="C+";
}
else if (mark>=50){
grade="C";
else if (mark>=50){
grade="C-";
else if (mark>=40){
grade="D";
else if (mark<40){
grade="F";
else if (mark<0){
grade="invalid";
else if (mark>100){
grade="F";
System.out.println(grade);
}
}
Progam of employe registration system
package employeregistrationsystem;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class lg implements ActionListener {
private JFrame frame;
private JPanel panel;
private JLabel welLabel,lastLabel,passportLabel,IdLabel,usernameLabel, ageLabel,
passwordLabel, sexLabel, departmentLabel, phoneLabel, emailLabel, addressLabel,
countryLabel, regionLabel;
private JTextField lastField,passportField,IdField,usernameField, ageField, departmentField,
phoneField, emailField, addressField;
private JPasswordField passwordField;
private ButtonGroup sexButtonGroup;
private JComboBox<String> countryComboBox,
regionComboBox,departmentComboBox,sexComboBox;
private JButton registerButton, exitButton;
private JTextArea fieldArea;
private JScrollPane scrollPane;
private final String[] COUNTRIES = {"Select Country", "USA", "Canada", "UK", "Australia"};
private final String[] REGIONS = {"Select Region", "East", "West", "North", "South"};
private final String[] department = {"Select department","chemistry", "maths", "english",
"physics"};
private final String[] sex = {"Select gender","male","female"};
public lg() {
frame = new JFrame("Student biography");
frame.setSize(21000, 1000);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new FlowLayout());
panel = new JPanel();
panel.setPreferredSize(new Dimension(750, 550));
panel.setLayout(null);
usernameLabel = new JLabel("Username:");
usernameLabel.setBounds(50, 50, 100, 30);
panel.add(usernameLabel);
usernameField = new JTextField();
usernameField.setBounds(160, 50, 150, 30);
panel.add(usernameField);
usernameField.setCursor(new Cursor(Cursor.HAND_CURSOR));
usernameField.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent evt) {
usernameField.setBackground(Color.RED);
usernameField.setForeground(Color.BLACK);
public void mouseExited(MouseEvent evt) {
usernameField.setBackground(UIManager.getColor("control"));
usernameField.setForeground(Color.red);
}});
lastLabel = new JLabel("father name:");
lastLabel.setBounds(50, 100, 100, 30);
panel.add(lastLabel);
lastField = new JTextField();
lastField.setBounds(160, 100, 150, 30);
panel.add(lastField);
lastField.setCursor(new Cursor(Cursor.HAND_CURSOR));
lastField.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent evt) {
lastField.setBackground(Color.RED);
lastField.setForeground(Color.BLACK);
public void mouseExited(MouseEvent evt) {
lastField.setBackground(UIManager.getColor("control"));
lastField.setForeground(Color.BLACK);
}});
IdLabel = new JLabel("Id:");
IdLabel.setBounds(50, 10, 100, 30);
panel.add(IdLabel);
IdField = new JTextField();
IdField.setBounds(160, 10, 150, 30);
panel.add(IdField);
IdField.setCursor(new Cursor(Cursor.HAND_CURSOR));
IdField.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent evt) {
IdField.setBackground(Color.RED);
IdField.setForeground(Color.BLACK);
public void mouseExited(MouseEvent evt) {
IdField.setBackground(UIManager.getColor("control"));
IdField.setForeground(Color.red);
}});
ageLabel = new JLabel("Age:");
ageLabel.setBounds(50, 150, 100, 30);
panel.add(ageLabel);
ageField = new JTextField();
ageField.setBounds(160, 150, 150, 30);
panel.add(ageField);
ageField.setCursor(new Cursor(Cursor.HAND_CURSOR));
ageField.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent evt) {
ageField.setBackground(Color.RED);
ageField.setForeground(Color.BLACK);
}
public void mouseExited(MouseEvent evt) {
ageField.setBackground(UIManager.getColor("control"));
ageField.setForeground(Color.red);
}});
passwordLabel = new JLabel("Password:");
passwordLabel.setBounds(50, 200, 100, 30);
panel.add(passwordLabel);
passwordField = new JPasswordField();
passwordField.setBounds(160, 200, 150, 30);
panel.add(passwordField);
passwordField.setCursor(new Cursor(Cursor.HAND_CURSOR));
passwordField.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent evt) {
passwordField.setBackground(Color.RED);
passwordField.setForeground(Color.BLACK);
}
public void mouseExited(MouseEvent evt) {
passwordField.setBackground(UIManager.getColor("control"));
passwordField.setForeground(Color.red);
}});
sexLabel = new JLabel("Sex:");
sexLabel.setBounds(50, 250, 100, 30);
panel.add(sexLabel);
sexComboBox = new JComboBox<>(sex);
sexComboBox.setBounds(160, 250, 150, 30);
panel.add(sexComboBox);
sexComboBox.setCursor(new Cursor(Cursor.HAND_CURSOR));
sexComboBox.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent evt) {
sexComboBox.setBackground(Color.RED);
sexComboBox.setForeground(Color.BLACK);
public void mouseExited(MouseEvent evt) {
sexComboBox.setBackground(UIManager.getColor("control"));
sexComboBox.setForeground(Color.red);
}});
departmentLabel = new JLabel("department:");
departmentLabel.setBounds(50, 300, 100, 30);
panel.add(departmentLabel);
departmentComboBox = new JComboBox<>(department);
departmentComboBox.setBounds(160, 300, 150, 30);
panel.add(departmentComboBox);
departmentComboBox.setCursor(new Cursor(Cursor.HAND_CURSOR));
departmentComboBox.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent evt) {
departmentComboBox.setBackground(Color.RED);
departmentComboBox.setForeground(Color.BLACK);
public void mouseExited(MouseEvent evt) {
departmentComboBox.setBackground(UIManager.getColor("control"));
departmentComboBox.setForeground(Color.red);
}});
phoneLabel = new JLabel("Phone Number:");
phoneLabel.setBounds(50, 350, 100, 30);
panel.add(phoneLabel);
phoneField = new JTextField();
phoneField.setBounds(160, 350, 150, 30);
panel.add(phoneField);
phoneField.setCursor(new Cursor(Cursor.HAND_CURSOR));
phoneField.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent evt) {
phoneField.setBackground(Color.RED);
phoneField.setForeground(Color.BLACK);
public void mouseExited(MouseEvent evt) {
phoneField.setBackground(UIManager.getColor("control"));
phoneField.setForeground(Color.red);
}});
emailLabel = new JLabel("Email:");
emailLabel.setBounds(400, 150, 100, 30);
panel.add(emailLabel);
emailField = new JTextField();
emailField.setBounds(510, 150, 150, 30);
panel.add(emailField);
emailField.setCursor(new Cursor(Cursor.HAND_CURSOR));
emailField.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent evt) {
emailField.setBackground(Color.RED);
emailField.setForeground(Color.BLACK);
public void mouseExited(MouseEvent evt) {
emailField.setBackground(UIManager.getColor("control"));
emailField.setForeground(Color.red);
}});
addressLabel = new JLabel("Address:");
addressLabel.setBounds(400, 50, 100, 30);
panel.add(addressLabel);
addressField = new JTextField();
addressField.setBounds(510, 50, 150, 30);
panel.add(addressField);
addressField.setCursor(new Cursor(Cursor.HAND_CURSOR));
addressField.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent evt) {
addressField.setBackground(Color.RED);
addressField.setForeground(Color.BLACK);
public void mouseExited(MouseEvent evt) {
addressField.setBackground(UIManager.getColor("control"));
addressField.setForeground(Color.red);
}});
passportLabel = new JLabel("passport number:");
passportLabel.setBounds(400, 100, 100, 30);
panel.add(passportLabel);
passportField = new JTextField();
passportField.setBounds(510, 100, 150, 30);
panel.add(passportField);
passportField.setCursor(new Cursor(Cursor.HAND_CURSOR));
passportField.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent evt) {
passportField.setBackground(Color.RED);
passportField.setForeground(Color.BLACK);
}
public void mouseExited(MouseEvent evt) {
passportField.setBackground(UIManager.getColor("control"));
passportField.setForeground(Color.red);
}});
countryLabel = new JLabel("Country:");
countryLabel.setBounds(400, 200, 100, 30);
panel.add(countryLabel);
countryComboBox = new JComboBox<>(COUNTRIES);
countryComboBox.setBounds(510, 200, 150, 30);
panel.add(countryComboBox);
countryComboBox.setCursor(new Cursor(Cursor.HAND_CURSOR));
countryComboBox.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent evt) {
countryComboBox.setBackground(Color.RED);
countryComboBox.setForeground(Color.BLACK);
public void mouseExited(MouseEvent evt) {
countryComboBox.setBackground(UIManager.getColor("control"));
countryComboBox.setForeground(Color.red);
}});
regionLabel = new JLabel("Region:");
regionLabel.setBounds(400, 250, 100, 30);
panel.add(regionLabel);
regionComboBox = new JComboBox<>(REGIONS);
regionComboBox.setBounds(510, 250, 150, 30);
panel.add(regionComboBox);
regionComboBox.setCursor(new Cursor(Cursor.HAND_CURSOR));
regionComboBox.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent evt) {
regionComboBox.setBackground(Color.RED);
regionComboBox.setForeground(Color.BLACK);
public void mouseExited(MouseEvent evt) {
regionComboBox.setBackground(UIManager.getColor("control"));
regionComboBox.setForeground(Color.red);
}});
registerButton = new JButton("Register");
registerButton.setBounds(250, 400, 100, 40);
registerButton.addActionListener(this);
panel.add(registerButton);
registerButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
registerButton.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent evt) {
registerButton.setBackground(Color.RED);
registerButton.setForeground(Color.BLACK);
public void mouseExited(MouseEvent evt) {
registerButton.setBackground(UIManager.getColor("control"));
registerButton.setForeground(Color.red);
}});
exitButton = new JButton("Exit");
exitButton.setBounds(400, 400, 100, 40);
exitButton.addActionListener(this);
panel.add(exitButton);
exitButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
exitButton.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent evt) {
exitButton.setBackground(Color.RED);
exitButton.setForeground(Color.BLACK);
public void mouseExited(MouseEvent evt) {
exitButton.setBackground(UIManager.getColor("control"));
exitButton.setForeground(Color.red);
}});
fieldArea = new JTextArea();
fieldArea.setEditable(false);
scrollPane = new JScrollPane(fieldArea);
scrollPane.setBounds(50, 450, 600, 80);
panel.add(scrollPane);
fieldArea.setCursor(new Cursor(Cursor.HAND_CURSOR));
fieldArea.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent evt) {
fieldArea.setBackground(Color.RED);
fieldArea.setForeground(Color.BLACK);
}
public void mouseExited(MouseEvent evt) {
fieldArea.setBackground(UIManager.getColor("control"));
fieldArea.setForeground(Color.darkGray);
}});
welLabel = new JLabel("THANKS FOR YOUR PARTISPATION");
welLabel.setBounds(200, 500, 500, 80);
panel.add(welLabel);
frame.add(panel);
frame.setVisible(true);
public static void main(String[] args) {
new lg();
private void setVisible(boolean b) {
lg sys=new lg();
sys.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == exitButton) {
JOptionPane.showMessageDialog(null, "thanks for your participation ");
System.exit(0);
if (e.getSource() == registerButton) {
String id = IdField.getText();
String username = usernameField.getText();
String fathername = lastField.getText();
String age = ageField.getText();
String password = new String(passwordField.getPassword());
String phoneNumber = phoneField.getText();
String email = emailField.getText();
String passport = passportField.getText();
String address = addressField.getText();
String country = (String) countryComboBox.getSelectedItem();
String region = (String) regionComboBox.getSelectedItem();
String department = (String) departmentComboBox.getSelectedItem();
String registrationData = "Id: "+id +"\n"+"Username: " + username + "\n" +
"Age: " + age + "\n" +
"Password: " + password + "\n" +
"Sex: " + sex + "\n" +
"Department: " + department + "\n" +
"Phone Number: " + phoneNumber + "\n" +
"Email: " + email + "\n" +
"passport: " + passport + "\n" +
"Address: " + address + "\n" +
"Country: " + country + "\n" +
"Region: " + region + "\n";
fieldArea.setText(registrationData);
//JOptionPane.showMessageDialog(null, username+" "+fathername);
//JOptionPane.showMessageDialog(null,"you are already registered");
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/registrationsystem","root" ,
"1234567890");
Statement st=con.createStatement();
String registerButton = e.getActionCommand();
if(registerButton.equals("register")){
String Choice;
do{
String id1=IdField .getText();
String fname1=usernameField.getText();
String fathername1=lastField.getText();
String Age=ageField.getText();
String sex=sexComboBox.getItemAt(sexComboBox.getSelectedIndex());
String
department1=departmentComboBox.getItemAt(departmentComboBox.getSelectedIndex());
String phone=phoneField.getText();
String Addres=addressField.getText();
String passport1=passportField.getText();
String email1=emailField.getText();
String
country1=countryComboBox.getItemAt(countryComboBox.getSelectedIndex());
String regoin=regionComboBox.getItemAt(regionComboBox.getSelectedIndex());
PreparedStatement pst=con.prepareStatement("insert into student
values(?,?,?,?,?,?,?,?)");
pst.setString(1, String.valueOf(id1));
pst.setString(2, fname1);
pst.setString(3, fathername1);
pst.setString(4, String.valueOf(Age));
pst.setString(5, String.valueOf(sex));
pst.setString(6,department1);
pst.setString(7,phone );
pst.setString(8,Addres);
pst.setString(9,passport1);
pst.setString(10,email1);
pst.setString(11,country1);
pst.setString(12,regoin);
int result=pst.executeUpdate();
if(result>=0){
JOptionPane.showMessageDialog(null, fname1+" "+fathername1);
JOptionPane.showMessageDialog(null,"you are already registered");
JOptionPane.showMessageDialog(null,"One row is added to table");
else{
//JOptionPane.showMessageDialog(null,"failed to register");
}
//JOptionPane.showMessageDialog(null,"do you went to continue/press Yes and press
anther word to stop");
Choice=JOptionPane.showInputDialog(null,"do you went to continue/press Yes and press
anther word to stop");
while(Choice.equals("Yes"));
}else{
JOptionPane.showMessageDialog(null,"failed to register");
lg sys=new lg();
sys.setVisible(true);
}catch(Exception ex){
JOptionPane.showMessageDialog(null,ex.getMessage());
void show() {
}
Program of Lowercase and to Uppercase
import java.util.*;
class ConvertCasePrg
public static void main(String args[])
Scanner sc= new Scanner(System.in);
String str="";
//input string
System.out.print("Enter any string: ");
str=sc.nextLine();
//declaring objects to store lowercase and uppercase strings
String lowerCaseString="",upperCaseString="";
//convert into lower case
lowerCaseString= str.toLowerCase();
//convert into upper case
upperCaseString= str.toUpperCase();
//printing the strings
System.out.println("Original String: "+str);
System.out.println("Lower Case String: "+lowerCaseString);
System.out.println("Upper Case String: "+upperCaseString);
To calculate the average and sum
import java.util.Scanner;
public class Average {
public static void main(String[] args) {
// create Scanner class object
Scanner scan = new Scanner(System.in);
// declare three numbers
double num1 = 0;
double num2 = 0;
double num3 = 0;
// declare sum variable
// and initialize with 0
double sum = 0.0;
// declare average variable
double avg = 0.0;
// take three numbers
System.out.print("Enter three numbers: ");
num1 = scan.nextDouble();
num2 = scan.nextDouble();
num3 = scan.nextDouble();
// calculate the sum value
sum = num1 + num2 + num3;
// calculate the average value
avg = sum/3;
// display result
System.out.println("sum: " + sum );
System.out.println("Average: " + avg );
}
Program of to identify odd and even
import java.util.Scanner;
public class EvenOdd {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = reader.nextInt();
if(num % 2 == 0)
System.out.println(num + " is even");
else
System.out.println(num + " is odd");