diff --git a/SQL/Vladimir.Pletniov/homework.sql b/SQL/Vladimir.Pletniov/homework.sql new file mode 100644 index 0000000..f66586f --- /dev/null +++ b/SQL/Vladimir.Pletniov/homework.sql @@ -0,0 +1,148 @@ +create table Address +( + ID int auto_increment, + country VARCHAR(256) not null, + city VARCHAR(256) not null, + post_index int null, + price int null, + primary key (ID) +); + +create table People +( + ID int auto_increment, + age int not null, + name VARCHAR(256) not null, + last_name VARCHAR(256) not null, + salary int not null, + primary key (ID) +); + +INSERT INTO `homework`.`Address` + (`country`, `city`, `post_index`, `price`) +VALUES ('Ukraine', 'Kiev', 12444211, 1000000); + +INSERT INTO `homework`.`People` + (`age`, `name`, `last_name`, `salary`) +VALUES (33, 'Mike', 'White', 30000); +INSERT INTO `homework`.`People` (`age`, `name`, `last_name`, `salary`) +VALUES (22, 'Dima', 'Bruno', 25325); +INSERT INTO `homework`.`People` (`age`, `name`, `last_name`, `salary`) +VALUES (34, 'Lina', 'Su', 53232); +INSERT INTO `homework`.`People` (`age`, `name`, `last_name`, `salary`) +VALUES (77, 'Mike', 'Kirov', 57464); +INSERT INTO `homework`.`People` (`age`, `name`, `last_name`, `salary`) +VALUES (18, 'Lena', 'Mukolova', 9335); +INSERT INTO `homework`.`People` (`age`, `name`, `last_name`, `salary`) +VALUES (55, 'Kiril', 'Yanov', 34532); +INSERT INTO `homework`.`People` (`age`, `name`, `last_name`, `salary`) +VALUES (88, 'Rinat', 'Kunicin', 34521); +INSERT INTO `homework`.`People` (`age`, `name`, `last_name`, `salary`) +VALUES (44, 'Marcus', 'Chu', 347654); +INSERT INTO `homework`.`People` (`age`, `name`, `last_name`, `salary`) +VALUES (98, 'Piter', 'Jacson', 57434); +INSERT INTO `homework`.`People` (`age`, `name`, `last_name`, `salary`) +VALUES (25, 'Mona', 'Light', 3946); + +INSERT INTO `homework`.`Address` (`country`, `city`, `post_index`, `price`) +VALUES ('Ukraine', 'Odessa', 43523, 52324); +INSERT INTO `homework`.`Address` (`country`, `city`, `post_index`, `price`) +VALUES ('Ukraine', 'Kiev', 35423, 676675); +INSERT INTO `homework`.`Address` (`country`, `city`, `post_index`, `price`) +VALUES ('Ukraine', 'Dnipro', 4534352, 5675765); +INSERT INTO `homework`.`Address` (`country`, `city`, `post_index`, `price`) +VALUES ('Ukraine', 'Dnipro', 7866876, 6576); +INSERT INTO `homework`.`Address` (`country`, `city`, `post_index`, `price`) +VALUES ('Ukraine', 'Odessa', 7868766, 5765); +INSERT INTO `homework`.`Address` (`country`, `city`, `post_index`, `price`) +VALUES ('Russia', 'Moscow', 65564, 65775); +INSERT INTO `homework`.`Address` (`country`, `city`, `post_index`, `price`) +VALUES ('Russia', 'Piter', 87877, 5765765); +INSERT INTO `homework`.`Address` (`country`, `city`, `post_index`, `price`) +VALUES ('Russia', 'Moscow', 67565, 56757); +INSERT INTO `homework`.`Address` (`country`, `city`, `post_index`, `price`) +VALUES ('Russia', 'Riga', 57576876, 897889); + + +INSERT INTO `homework`.`Address` + (`ID`, `country`, `city`, `post_index`, `price`) +VALUES (22, 'Angola', 'Luanda', 432234, 532332); +INSERT INTO `homework`.`Address` + (`ID`, `country`, `city`, `post_index`, `price`) +VALUES (23, 'Algeria', 'Algiers', null, 243223); + +INSERT INTO `homework`.`People` (`ID`, `age`, `name`, `last_name`, `salary`) +VALUES (44, 44, 'Kuto', 'Ruba', 54223); +INSERT INTO `homework`.`People` (`ID`, `age`, `name`, `last_name`, `salary`) +VALUES (45, 54, 'Nastia', 'Mira', 34321); + + +SELECT name, last_name, Address.post_index +from People + left join Address on People.ID = Address.Id; +SELECT * +from Address + left join People on Address.id = People.ID; + +select * +from People + inner join Address on People.ID = Address.ID; +select * +from Address + inner join People on Address.ID = People.ID; + +select * +from Address + left join People on Address.ID = People.ID +where People.ID is NULL; + +select count(*) +from Address + left join People on Address.ID = People.ID +where People.ID is NULL; + +SELECT count(*) +from People + left join Address on People.ID = Address.ID +where Address.ID is null; + +select * +from People + inner join Address on People.ID = Address.ID +where city = 'Kiev'; + + +select * +from Address + left join People on Address.ID = People.ID +where People.ID is NULL +having price > 250000 + and price < 1000000; + +SELECT * +from People + inner join Address on People.ID = Address.ID +where salary * 10 >= price; + +select * +from Address + inner join People on Address.ID = People.ID +where 10 * salary >= price +having People.ID = 5; + +INSERT into People (age, name, last_name, salary) +VALUES (32, 'Vasia', 'Petichkin', 1313134); + +create table PeopleAddress +( + ID int auto_increment, + constraint PeopleAddress_pk + primary key (ID), + constraint PeopleAddress__ID_fk + foreign key (ID) references People (ID), + constraint PeopleAddress__ID_fk_2 + foreign key (ID) references Address (ID) +); + + + diff --git a/lesson_3/Vladimir.Pletniov/Calculator.java b/lesson_3/Vladimir.Pletniov/Calculator.java new file mode 100644 index 0000000..ff66bba --- /dev/null +++ b/lesson_3/Vladimir.Pletniov/Calculator.java @@ -0,0 +1,54 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + + +public class Calculator { + public static void main(String[] args) throws IOException { + System.out.println("You have these operations:" + + "add, minus, multiply, divide, remainder, abs"); + String operation; + double firstOperand; + double secondOperand; + if (args.length > 0) { + operation = args[0]; + firstOperand = Double.parseDouble(args[1]); + secondOperand = Double.parseDouble(args[2]); + } else { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + System.out.println("Input operation:"); + operation = reader.readLine(); + System.out.println("Input first number:"); + firstOperand = Double.parseDouble(reader.readLine()); + System.out.println("Input second number:"); + secondOperand = Double.parseDouble(reader.readLine()); + } + calculate(operation, firstOperand, secondOperand); + } + + public static void calculate(String operation, double firstOperand, double secondOperand) { + double result = 0; + switch (operation) { + case "add": + result = firstOperand + secondOperand; + break; + case "minus": + result = firstOperand - secondOperand; + break; + case "multiply": + result = firstOperand * secondOperand; + break; + case "divide": + result = firstOperand / secondOperand; + break; + case "remainder": + result = firstOperand % secondOperand; + break; + case "abs": + result = Math.abs(firstOperand); + break; + } + System.out.println("Result is a " + result); + } + +} diff --git a/lesson_3/Vladimir.Pletniov/Tips.java b/lesson_3/Vladimir.Pletniov/Tips.java new file mode 100644 index 0000000..4409e66 --- /dev/null +++ b/lesson_3/Vladimir.Pletniov/Tips.java @@ -0,0 +1,31 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + + +public class Tips { + public static void main(String[] args) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + int sum = Integer.parseInt(reader.readLine()); + String service = reader.readLine(); + switch (service) { + case "terrible": + sum *= 1; + break; + case "poor": + sum *= 1.05; + break; + case "good": + sum *= 1.1; + break; + case "great": + sum *= 1.15; + break; + case "excellent": + sum *= 1.2; + break; + } + System.out.println("You have to pay: " + sum); + } +} +