<html>
<head>
<title>Ajax - Node</title>
<style>
.error {
    background-color: red;
}
</style>
<script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
</head>
<body>


    <h1>Ajax Get method</h1>
    <form>
        <label>Name</label><br> <input type="text" id="userNameGet"><br>
        <label>Age</label><br> <input type="text" id="userAgeGet"><br>
        <label>Address</label><br> <input type="text" id="userAddressGet"><br>
        <br> <input id="getButt" disabled type="button" value="Send by Get"
            onclick="sendDataByGetMethod()">

    </form>

    <br>

    <h1>Ajax Post method</h1>
    <form>
        <label>Name</label><br> <input type="text" id="userNamePost"><br>
        <label>Age</label><br> <input type="text" id="userAgePost"><br>
        <label>Address</label><br> <input type="text" id="userAddressPost"><br>
        <br> <input id="postButt" disabled type="button" value="send by Post"
            onclick="sendDataByPostMethod()">
    </form>

    <br>
    <script>
function sendDataByGetMethod() {
    
    var userData = {
        userName:document.getElementById('userNameGet').value,    
        userAge:document.getElementById('userAgeGet').value,
        userAddress:document.getElementById('userAddressGet').value
    };
    
    var xhr = new XMLHttpRequest();
    xhr.open("GET", "/userGet?userName="+userData.userName+"&userAge="+userData.userAge+"&userAddress="+userData.userAddress);
    xhr.setRequestHeader("Content-type","application/json");
    xhr.send();
}
function sendDataByPostMethod() {
    var userData = {
            userName:document.getElementById('userNamePost').value,    
            userAge:document.getElementById('userAgePost').value,
            userAddress:document.getElementById('userAddressPost').value
        };
        
        var xhr = new XMLHttpRequest();
        xhr.open("POST", "/userPost");
        xhr.setRequestHeader("Content-type","application/json");
        xhr.send(JSON.stringify(userData));
}
userAgeGet.onblur = function() {
    if(this.value>100||this.value<1||isNaN(this.value)){    
        this.classList.add('error');
        alert("wrong age input");
        document.getElementById("getButt").disabled = true;
    }else{
        this.classList.remove('error');    
        document.getElementById("getButt").disabled = false;
    }
}
userAgePost.onblur = function() {
    if(this.value>100||this.value<1||isNaN(this.value)){    
        this.classList.add('error');
        alert("wrong age input");
        document.getElementById("postButt").disabled = true;
    }else{
        this.classList.remove('error');    
        document.getElementById("postButt").disabled = false;
    }
}
</script>

</body>
</html>
var express = require("express");
var bodyParser = require("body-parser");

var server = express();
var jsonParser = bodyParser.json();

server.use(express.static(__dirname));
server.use(jsonParser);

server.get("/", function(request, response) {
    console.log('Start page is running');
    response.send("<h1>Welcome to the lesson regarding AJAX</h1>");
});

server.get("/userGet", function(request, response) {
    console.log(request.query);
    var obj = request.query;
    obj.userName += "ValidatedByGET";
    obj.userAge += "ValidatedByGET";
    obj.userAddress +="ValidatedByGET";
    response.send("You have successfully used Get method : "+ JSON.stringify(request.query));
});

server.post("/userPost", function(request, response) {
    console.log(request.body);
    var obj = request.body;
    obj.userName += "ValidatedByPOST";
    obj.userAge += "ValidatedByPOST";
    obj.userAddress +="ValidatedByPOST";
    response.send("You have successfully used Post method : "+ JSON.stringify(request.body));
});


server.listen(3000);

2

(11 відповідей, залишених у Java)

Моделюємо верховну раду.

Створити клас Людина, описати його наступними полями : вага, ріст, додати джентельменський набір. Створити клас депутат , унаслідувати його від Людини.
Описати його такими полями: прізвище, імя, вік, хабарник(Буліановське), розмір хабаря(не передавати в конструктор). Додати джентельменський набір . Додати метод : дати хабар(), в якому передбачити наступне :

  • якщо поле хабарник false - то вивести на консоль :" Цей депутат не бере хабарів", якщо умова не виконується, то ввести з консолі суму хабаря яку ви даєте,якщо це сума більша 5000, вивести на консоль "Миліція увязнить депутата",якщо не більша то занести в поле класу хабар дану суму.

Створити клас фракція ,якому описати наступні методи :

  • додати депутата(вводимо з консолі)

  • видалити депутата(вводимо з консолі)

  • вивести всіх хабарників у фракції

  • вивести найбільшого хабарника у фракції

  • вивести всіх депутатів фракції

  • очистити всю фракцію від депутатів

Створити клас верховна рада і реалізувати в ньому наступні методи(дозволено створити тільки один екземпляр даного класу(singleton)):

  • додати фракцію

  • видалити фракцію

  • вивести всі фракції

  • вивести конкретну фракцію

  • додати депутата до конкретної фракції

  • видалити депутата(вводимо з консолі)

  • вивести всіх хабарників у фракції

  • вивести найбільшого хабарника у фракції

  • вивести всіх депутатів фракції

Створити клас Мейн в якому описати наступне консольне меню:

MINIMUM:

  • Введіть 1 щоб додати фракцію

  • Введіть 2 щоб видалити конкретну фракцію

  • Введіть 3 щоб вивести усі  фракції

  • Введіть 4 щоб очистити конкретну фракцію

  • Введіть 5 щоб вивести конкретну фракцію

MAXIMUM:

  • Введіть 6 щоб додати депутата в фракцію

  • Введіть 7 щоб видалити депутата з фракції

  • Введіть 8 щоб вивести список хабарників

  • Введіть 9 щоб вивести найбільшого хабарника

Мої напрацювання
package ua.lviv.lgs;

import java.util.Scanner;

public class Task_1 {

    public class Human  {

        private int height;
        private int weight;

        public Human(int height, int weight) {
            super();
            this.height = height;
            this.weight = weight;
        }

        public int getHeight() {
            return height;
        }

        public void setHeight(int height) {
            this.height = height;
        }

        public int getWeight() {
            return weight;
        }

        public void setWeight(int weight) {
            this.weight = weight;
        }



        @Override
        public String toString() {
            return "Human [height = " + height + ", weight = " + weight + "]";
        }
    }

    public class Deputy extends Human {

        private String surname;
        private String name;
        private int age;
        private boolean corrupt;
        private double bribe;
        private double bribeSize;

        Deputy(String surname, String name, int age, boolean corrupt, double bribe, double bribeSize) {
            this.surname = surname;
            this.name = name;
            this.age = age;
            this.corrupt = corrupt;
            this.bribe = bribe;
            this.bribeSize = bribeSize;
        }

        public String getSurname() {
            return surname;
        }

        public void setSurname(String surname) {
            this.surname = surname;
        }

        public String getName() {
            return name;
        }

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

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public boolean GetCorrupt() {
            return(corrupt);

        }

        public boolean setCorrupt() {
            return(corrupt);

        }

        @Override
        public String toString() {
            return "Deputy [surname - " + surname + ", name - " + name + ", age - " + age + "corrupt - " + corrupt + "bribe"+ bribe + "]";
        }

        public void give_a_bribe(){

            Scanner scan = new Scanner(System.in);
            if(corrupt == false) {
                System.out.println("Цей депутат не бере хабарів");
            } else {
                System.out.println("Введіть суму хабаря яку ви даєте : ");
                double bribe = scan.nextDouble();
                if(bribe > 5000) {
                    System.out.println("Поліція ув'язнить депутата");
                } else {
                    bribeSize = bribe;
                }
            }
        }
    }
}

3

(1 відповідей, залишених у JavaScript, TypeScript, ECMAScript)

Прихований текст
package ua.lviv.lgs;
 
import java.time.Month;
import java.util.Scanner;
 
public class Task_2 {
 
 
    static class Season {
 
 
        public enum Seasons {
 
            WINTER,
            SPRING,
            SUMMER,
            AUTUMN;
 
 
            public enum Month {
 
                JANUARY(31, "WINTER"),
                    FEBRUARY(28, "SPRING"),
                    MARCH(31, "SPRING"),
                    APRIL(30, "SPRING"),
                    MAY(31, "SUMMER"),
                    JUNE(30, "SUMMER"),
                    JULY(31, "SUMMER"),
                    AUGUST(31, "AUTUMN"),
                    SEPTEMBER(30, "AUTUMN"),
                    OCTOBER(31, "AUTUMN"),
                    NOVEMBER(30, "WINTER"),
                    DECEMBER(31, "WINTER");
 
                public int getInDays() {
                    return inDays;
                }
 
                public int setInDays(int inDays) {
                    return this.inDays = inDays;
                }
 
                public String getInSeasons() {
                    return inSeasons;
                }
 
                public void setInSeasons(String inSeasons) {
                    this.inSeasons = inSeasons;
                }
 
                public  int inDays;
 
                public String inSeasons;
 
                Month(int inDays, String inSeasons) {
 
                    this.inDays = inDays;
                    this.inSeasons = inSeasons;
 
                }
            }
        }
        public int inDays;
        public Month month;
        public Seasons inSeasons;
 
 
        public Season(Month month, Seasons inSeasons, int inDays) {
            this.month = month;
            this.inSeasons = inSeasons;
            this.inDays = inDays;
 
        }
 
 
 
 
        class ProcessingMonth {
            Scanner sc = new Scanner(System.in);
 
            /**
             * 
             * @return month equalized with the console entered month
             */
            public Month readMonth() {
                while (true) {
                    if (!(sc.hasNextInt())) {
                        String s = sc.nextLine().trim();
                        for (Month month: Month.values()) {
                            if (s.equalsIgnoreCase(month.name())) {
                                return month;
                            }
                        }
                        System.out.println("The word you entered is not \nthe name of the month, try again");
                        sc = new Scanner(System.in);
                    } else {
                        int m = sc.nextInt();
                        if (m > 12 || m < 1) {
                            System.out.println("You entered the wrong month, try again.");
                            sc = new Scanner(System.in);
                        } else {
                            for (Month month: Month.values()) {
                                if (m == month.ordinal() + 1) {
                                    return month;
                                }
                            }
                        }
                    }
                }
            }
 
            /**
             * 
             * @param month console entered month
             */
            public void sameSeasonMonths(Month month) {
                Seasons season;
                if (month.ordinal() >= 8 && month.ordinal() <= 10) {
                    season = Seasons.AUTUMN;
                } else if (month.ordinal() >= 2 && month.ordinal() <= 4) {
                    season = Seasons.SPRING;
                } else if (month.ordinal() >= 5 && month.ordinal() <= 7) {
                    season = Seasons.SUMMER;
                } else {
                    season = Seasons.WINTER;
                }
                switch (season) {
                    case AUTUMN:
                        for (Month months: Month.values()) {
                            if (months.ordinal() == month.ordinal() || months.ordinal() < 8 || months.ordinal() > 10) {} else {
                                System.out.println(months);
                            }
                        }
                        break;
                    case SPRING:
                        for (Month months: Month.values()) {
                            if (months.ordinal() == month.ordinal() || months.ordinal() < 2 || months.ordinal() > 4) {} else {
                                System.out.println(months);
                            }
                        }
                        break;
                    case SUMMER:
                        for (Month months: Month.values()) {
                            if (months.ordinal() == month.ordinal() || months.ordinal() < 5 || months.ordinal() > 7) {} else {
                                System.out.println(months);
                            }
                        }
                        break;
                    case WINTER:
                        for (Month months: Month.values()) {
                            if (months.ordinal() == month.ordinal() || months.ordinal() < 11 && months.ordinal() > 1) {} else {
                                System.out.println(months);
                            }
                        }
                        break;
                }
            }
 
            public void isEvenNumberOfDays(Month month, int days) {
                if (days % 2 == 0) {
                    System.out.println(month.name() + " has an even number of days.");
                } else {
                    System.out.println(month.name() + " has an odd number of days.");
                }
            }
        }
 
        class MethodsForComparison {
 
            public void withSpecifiedNumberOfDays(int specifiedNumber) {
                for (Month m: Month.values()) {
                    if (m.inDays == specifiedNumber) {
                        System.out.println(m.toString());
                    }
                }
            }
 
            public void withGreaterNumberOfDays(int specifiedNumber) {
                for (Month m: Month.values()) {
                    if (m.inDays > specifiedNumber) {
                        System.out.println(m.toString());
                    }
                }
            }
            public void withSmallerNumberOfDays(int specifiedNumber) {
                for (Month m: Month.values()) {
                    if (m.inDays < specifiedNumber) {
                        System.out.println(m.toString());
                    }
                }
            }
        }
 
        static class Main {
 
 
            public void withSpecifiedNumberOfDays(int specifiedNumber) {
                for (Month m: Month.values()) {
                    if (m.inDays == specifiedNumber) {
                        System.out.println(m.toString());
                    }
                }
            }
 
            public void withGreaterNumberOfDays(int specifiedNumber) {
                String s = null;
 
                for (Month m: Month.values()) {
                    if (m.inDays > specifiedNumber) {
                        System.out.println(m.toString());
                        s = m.toString();
 
                    }
                }
                if (s == null) {
                    System.out.println("not more Great month");
                }
 
            }
 
            public void withSmallerNumberOfDays(int specifiedNumber) {
 
                String s = null;
                for (Month m: Month.values()) {
                    if (m.inDays < specifiedNumber) {
                        System.out.println(m.toString());
                        s = m.toString();
                    }
                }
                if (s == null) {
                    System.out.println("not more Small month");
                }
 
            }
 
            public void nexSeasons(Month month) {
                int i = 0;
                String[] d = {
                    "WINTER",
                    "SPRING",
                    "SUMMER",
                    "AUTUMN"
                };
                for (Seasons seas: Seasons.values()) {
                    i++;
                    if (month.inSeasons.equals(seas.name())) {
                        System.out.println("next seasons is " + d[i + 1]);
                    }
                }
 
            }
 
            public void pastSeasons(Month month) {
                int i = 0;
                String[] d = {
                    "WINTER",
                    "SPRING",
                    "SUMMER",
                    "AUTUMN"
                };
                for (Seasons seas: Seasons.values()) {
                    i++;
                    if (month.inSeasons.equals(seas.name())) {
                        System.out.println("next past is " + d[i - 1]);
                    }
                }
            }
 
            public void evenMonth() {
 
                for (Month d: Month.values()) {
 
 
                    if (d.inDays % 2 == 0) {
                        System.out.println(d.name() + " day = " + d.inDays);
                    }
 
                }
 
            }
 
            public void oddMonth() {
                for (Month d: Month.values()) {
 
 
                    if (d.inDays % 2 == 1) {
                        System.out.println(d.name() + " day = " + d.inDays);
                    }
 
                }
 
 
            }
 
            public static void main(String[] args) {
 
                ProcessingMonth month = new ProcessingMonth();
 
                System.out.println("take your pick :(only number)\n1 - Check for a month\n2 - show on display all months with the same time of year\n3 - show on display if put the console month has an even number of days\n4 - show on display all months that have the equal number of days\n5 - show on display all months that have more Great days\n6 - show on display all months that have fewer days\n7 - show on display Display the next season\n8 - show on display past season\n9 - show on display all months that have an odd number of days\n10 - show on display or put the console has an even number of month days\n11 - exit   ");
 
 
 
                int number;
                boolean flag = true;
                Main monthMain = new Main();
 
 
                while (flag) {
                    Scanner scan = new Scanner(System.in);
                    if (scan.hasNextInt()) {
 
                        number = scan.nextInt();
 
                        if (number > 11 || number < 1) {
                            System.out.println("---------------------------------------------------------------------------");
                            System.out.println("your choice is incorrect");
                            System.out.println("---------------------------------------------------------------------------");
                        }
 
 
 
                        switch (number) {
                            case 1:
                                {
                                    System.out.println("---------------------------------------------------------------------------");
                                    System.out.println("1 - Check for a month");
                                    System.out.println("---------------------------------------------------------------------------");
                                    System.out.println("enter the month");
 
                                    month.readMonth();
 
                                    System.out.println("Select the next step");
                                    break;
                                }
                            case 2:
                                {
                                    System.out.println("---------------------------------------------------------------------------");
                                    System.out.println("2 - show on display all months with the same time of year");
                                    System.out.println("---------------------------------------------------------------------------");
                                    System.out.println("enter the month");
                                    month.sameSeasonMonths(month.readMonth());
 
                                    System.out.println("Select the next step");
                                    break;
                                }
                            case 3:
                                {
                                    System.out.println("---------------------------------------------------------------------------");
                                    System.out.println("3 - show on display if put the console month has an even number of days");
                                    System.out.println("---------------------------------------------------------------------------");
                                    System.out.println("enter the month");
                                    month.isEvenNumberOfDays(month.readMonth(), inDays);
 
                                    System.out.println("Select the next step");
                                    break;
                                }
                            case 4:
                                {
                                    System.out.println("---------------------------------------------------------------------------");
                                    System.out.println("4 - show on display all months that have the equal number of days");
                                    System.out.println("---------------------------------------------------------------------------");
                                    System.out.println("enter the month");
                                    monthMain.withSpecifiedNumberOfDays(month.readMonth().inDays);
 
                                    System.out.println("Select the next step");
                                    break;
                                }
                            case 5:
                                {
                                    System.out.println("---------------------------------------------------------------------------");
                                    System.out.println("5 - show on display all months that have more Great days");
                                    System.out.println("---------------------------------------------------------------------------");
                                    System.out.println("enter the month");
                                    monthMain.withGreaterNumberOfDays(month.readMonth().inDays);
 
                                    System.out.println("Select the next step");
                                    break;
                                }
                            case 6:
                                {
                                    System.out.println("---------------------------------------------------------------------------");
                                    System.out.println("6 - show on display all months that have fewer days");
                                    System.out.println("---------------------------------------------------------------------------");
                                    System.out.println("enter the month");
                                    monthMain.withSmallerNumberOfDays(month.readMonth().inDays);
 
                                    System.out.println("Select the next step");
                                    break;
                                }
                            case 7:
                                {
                                    System.out.println("---------------------------------------------------------------------------");
                                    System.out.println("7 - show on display the next season");
                                    System.out.println("---------------------------------------------------------------------------");
                                    System.out.println("enter the month");
                                    monthMain.nexSeasons(month.readMonth());
 
                                    System.out.println("Select the next step");
                                    break;
                                }
                            case 8:
                                {
                                    System.out.println("---------------------------------------------------------------------------");
                                    System.out.println("8 - show on display past season");
                                    System.out.println("---------------------------------------------------------------------------");
                                    System.out.println("enter the month");
                                    monthMain.nexSeasons(month.readMonth());
 
                                    System.out.println("Select the next step");
                                    break;
                                }
                            case 9:
                                {
                                    System.out.println("---------------------------------------------------------------------------");
                                    System.out.println("9 - show on display all months that have an odd number of days");
                                    System.out.println("---------------------------------------------------------------------------");
                                    monthMain.oddMonth();
 
                                    System.out.println("Select the next step");
                                    break;
                                }
                            case 10:
                                {
                                    System.out.println("---------------------------------------------------------------------------");
                                    System.out.println("10 - show on display or put the console has an even number of month days");
                                    System.out.println("---------------------------------------------------------------------------");
                                    monthMain.evenMonth();
 
                                    System.out.println("Select the next step");
                                    break;
                                }
                            case 11:
                                {
                                    System.out.println("---------------------------------------------------------------------------");
                                    System.out.println("11 - exit");
                                    System.out.println("---------------------------------------------------------------------------");
 
                                    flag = false;
                                    break;
                                }
                        }
                    } else {
                        System.out.println("---------------------------------------------------------------------------");
                        System.out.println("error invalid input");
                        System.out.println("---------------------------------------------------------------------------");
                    }
 
 
 
                }
            }
 
        }
    }
 
}