├── .DS_Store ├── PF-Java-CheatSheet.pdf ├── 03. Arrays - Lab ├── .DS_Store ├── ReverseAnArrayOfStrings_04.java ├── Demo │ ├── Demo2.java │ └── Demo3.java ├── EvenOddSubtraction_05.java ├── PrintNumbersInReverseOrder_02.java ├── DayOfWeek_01.java ├── SumEvenNumbers_03.java └── EqualArrays_06.java ├── 08. Text Processing - Lab ├── .DS_Store ├── RepeatStrings_02.java ├── TextFilter_04.java ├── ReverseStringWithStringBuilder_01.java ├── Substring_03.java ├── Demo │ ├── DemoStringVsStringBuilder.java │ └── DemoStringBuilder.java ├── ReverseString_01.java └── Digits_letters_Others_05.java ├── 06. Objects and Classes - Lab ├── .DS_Store ├── SumBigNumbers_02.java ├── demo │ ├── Demo.java │ └── Car.java ├── BigFactorial_03.java ├── songs │ ├── Song.java │ └── Main.java ├── RandomizeWords_01.java ├── students │ ├── Student.java │ └── Main.java └── stundents2 │ ├── Student.java │ └── Main.java ├── 07. Maps, Lambda, Stream API - Lab ├── .DS_Store ├── WordFilter_04.java ├── OddOccurrences_03.java ├── Demo │ ├── Demo2.java │ ├── Demo_Lambda_StreamAPI.java │ └── Demo.java ├── WordSynonyms_02.java └── CountRealNumbers_01.java ├── HTML and CSS Basics - Common Lection ├── apple.png ├── bear.jpg ├── kiwi.png ├── banana.png ├── orange.png ├── welcome.html ├── color-blocks-style.css ├── color-blocks.html ├── lists.html ├── wiki-page.html └── fruits.html ├── 02. Data Types and Variables - Exercise ├── TriplesOfLatinLetters_06.java ├── Main_02.java ├── Elevator_03.java ├── SumOfChars_04.java ├── IntegerOperations_01.java ├── WaterOverflow_07.java ├── PrintPartOfAsciiTable_05.java ├── SumDigits_02.java ├── PokeMon_10.java ├── SpiceMustFlow_09.java ├── Snowballs_11.java └── BeerKegs_08.java ├── 06. Objects and Classes - Exercise ├── demo │ ├── Main.java │ ├── RandomExample.java │ └── Book.java ├── opinion_poll_03 │ ├── Person.java │ └── Main.java ├── advertisement_message_01 │ ├── Main.java │ └── Message.java ├── order_by_age_06 │ ├── Person.java │ └── Main.java ├── students_04 │ ├── Student.java │ └── Main.java ├── articles_02 │ ├── Article.java │ └── Main.java ├── groomingSalon │ ├── Pet.java │ ├── Main.java │ └── GroomingSalon.java └── vehicle_catalogue_05 │ ├── Vehicle.java │ └── Main.java ├── 01. Basic Syntax, Conditional Statements and Loops - Exercise ├── Main.java ├── TriangleOfNumbers_08.java ├── Ages_01.java ├── PrintAndSum_04.java ├── Orders_09.java ├── Division_02.java ├── StrongNumber_06.java ├── Login_05.java ├── PadawanEquipment_10.java ├── RageExpense_11.java └── Vacation_03.java ├── 02. Data Types and Varibles - Lab ├── PoundsToDollars_02.java ├── ConvertMetersToKilometers_01.java ├── ReversedChars_07.java ├── TownInfo_04.java ├── ConcatNames_05.java ├── CharsToString_06.java ├── CenturiesToMinutes_09.java ├── ExactSumOfRealNumbers_03.java ├── RefactorVolumeOfPyramid_11.java ├── SpecialNumber_10.java ├── RefactorSpecialNumbers_12.java └── LowerOrUpper_08.java ├── 01. Basic Syntax, Conditional Statements and Loops - Lab ├── Passed_02.java ├── PassedOrFailed_03.java ├── RefactorSumOddNumbers_12.java ├── StudentInformation_01.java ├── SumOddNumbers_09.java ├── DivisibleBy3_08.java ├── BackIn30Minutes_04.java ├── EvenNumber_11.java ├── ForeignLanguages_06.java ├── MultiplicationTable_10.java ├── TheatrePromotions_07.java └── MonthPrinter_05.java ├── 04. Methods - Exercise ├── MethodsRecap.java ├── Matrix_07.java ├── SmallestOfThreeNumbers_01.java ├── VowelsCount_02.java ├── AddAndSubtract_05.java ├── FactorialDivision_08.java ├── PalindromeIntegers_09.java ├── CharactersInRange_03.java ├── MiddleCharacters_06.java ├── TopNumber_10.java └── PasswordValidator_04.java ├── 04. Methods - Lab ├── MathPower_08.java ├── CalculateArea_06.java ├── PrintingTriangle_03.java ├── MultiplyEvensByOdds_10.java ├── Orders_05.java ├── Grades_02.java ├── SignOfIntegers_01.java ├── RepeatString_07.java ├── MathOperations_11.java └── Calculations_04.java ├── 03. Arrays - Exercise ├── CommonElements_02.java ├── Train_1.java ├── CondenseArrayToNumber_07.java ├── MagicSum_08.java ├── ArrayRotation_04.java ├── ArrayRecap.java ├── TopIntegers_05.java ├── TheLift_10.java ├── EqualSums_06.java ├── ZigZagArrays_03.java └── ArrayModifier_09.java ├── 08. Text Processing - Exercise ├── CaesarCipher_04.java ├── ExtractFile_03.java ├── ReplaceRepeatingChars_06.java ├── MultiplyBigNumber_05.java ├── StringExplosion_07.java ├── ValidUsernames_01.java ├── LettersChangeNumbers_08.java └── CharacterMultiplier_02.java ├── 09. RegEx - Lab ├── MatchFullName_01.java ├── regex-cheatsheet.txt ├── MatchPhoneNumber_02.java └── MatchDates_03.java ├── 05. Lists - Exercise ├── AppendArrays_07.java ├── HouseParty_03.java ├── BombNumbers_05.java ├── ChangeList_02.java ├── Train_01.java ├── CardsGame_06.java └── PokemonDontGo_09.java ├── 05. Lists - Lab ├── GaussTrick_02.java ├── ListOfProducts_05.java ├── MergingLists_03.java ├── Demo │ └── DemoListsVsArrays.java └── RemoveNegativesAndReverse_06.java ├── 07. Associative Arrays - Exercise ├── AMinerTask_02.java ├── CountCharsInAString_01.java ├── Courses_05.java ├── CompanyUsers_08.java ├── Orders_03.java ├── StudentAcademy_06.java ├── SoftUniParking_04.java └── SoftUniExamResults_10.java ├── Mid Exam Preparation - Part 1 ├── CounterStrike_01.java ├── MuOnline_Bonus.java └── ShoppingList_02.java ├── 10. RegEx - Exercise ├── ExtractEmails_05.java ├── SoftuniBarIncome_02.java ├── ValidPassword_06.java ├── NetherRealms_04.java └── Furniture_01.java ├── regex-cheatsheet.txt ├── Final Exam Preparation - Part 1 └── DestinationMapper_02.java ├── Final Exam Preparation - Part 2 ├── FancyBarcodes_02.java └── ImitationGame_01.java ├── Additional Videos.txt └── Mid Exam Preparation - Part 2 ├── BlackFlag_01.java └── Numbers_03.java /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesislavaTopuzakova/Java-Fundamentals-January-2024/HEAD/.DS_Store -------------------------------------------------------------------------------- /PF-Java-CheatSheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesislavaTopuzakova/Java-Fundamentals-January-2024/HEAD/PF-Java-CheatSheet.pdf -------------------------------------------------------------------------------- /03. Arrays - Lab/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesislavaTopuzakova/Java-Fundamentals-January-2024/HEAD/03. Arrays - Lab/.DS_Store -------------------------------------------------------------------------------- /08. Text Processing - Lab/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesislavaTopuzakova/Java-Fundamentals-January-2024/HEAD/08. Text Processing - Lab/.DS_Store -------------------------------------------------------------------------------- /06. Objects and Classes - Lab/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesislavaTopuzakova/Java-Fundamentals-January-2024/HEAD/06. Objects and Classes - Lab/.DS_Store -------------------------------------------------------------------------------- /07. Maps, Lambda, Stream API - Lab/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesislavaTopuzakova/Java-Fundamentals-January-2024/HEAD/07. Maps, Lambda, Stream API - Lab/.DS_Store -------------------------------------------------------------------------------- /HTML and CSS Basics - Common Lection/apple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesislavaTopuzakova/Java-Fundamentals-January-2024/HEAD/HTML and CSS Basics - Common Lection/apple.png -------------------------------------------------------------------------------- /HTML and CSS Basics - Common Lection/bear.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesislavaTopuzakova/Java-Fundamentals-January-2024/HEAD/HTML and CSS Basics - Common Lection/bear.jpg -------------------------------------------------------------------------------- /HTML and CSS Basics - Common Lection/kiwi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesislavaTopuzakova/Java-Fundamentals-January-2024/HEAD/HTML and CSS Basics - Common Lection/kiwi.png -------------------------------------------------------------------------------- /HTML and CSS Basics - Common Lection/banana.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesislavaTopuzakova/Java-Fundamentals-January-2024/HEAD/HTML and CSS Basics - Common Lection/banana.png -------------------------------------------------------------------------------- /HTML and CSS Basics - Common Lection/orange.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesislavaTopuzakova/Java-Fundamentals-January-2024/HEAD/HTML and CSS Basics - Common Lection/orange.png -------------------------------------------------------------------------------- /02. Data Types and Variables - Exercise/TriplesOfLatinLetters_06.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class TriplesOfLatinLetters_06 { 4 | 5 | public static void main(String[] args) { 6 | 7 | 8 | 9 | 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /HTML and CSS Basics - Common Lection/welcome.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Welcome 6 | 7 | 8 |

I am learning HTML and CSS!

9 | 10 | 11 | -------------------------------------------------------------------------------- /06. Objects and Classes - Exercise/demo/Main.java: -------------------------------------------------------------------------------- 1 | package demo; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | 7 | 8 | Book myFirstBook = new Book("Harry Potter", "J.K.Rowling", 19.80); 9 | 10 | myFirstBook.sell(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /06. Objects and Classes - Exercise/demo/RandomExample.java: -------------------------------------------------------------------------------- 1 | package demo; 2 | 3 | import java.util.Random; 4 | 5 | public class RandomExample { 6 | 7 | public static void main(String[] args) { 8 | 9 | Random random = new Random(); 10 | 11 | int randomNumber = random.nextInt(10, 20); 12 | 13 | System.out.println(randomNumber); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /HTML and CSS Basics - Common Lection/color-blocks-style.css: -------------------------------------------------------------------------------- 1 | div { 2 | display: inline; 3 | } 4 | 5 | .green { 6 | background-color: green; 7 | } 8 | 9 | .blue { 10 | background-color: blue; 11 | } 12 | 13 | .red { 14 | background-color: red; 15 | } 16 | 17 | .purple { 18 | background-color: purple; 19 | } 20 | 21 | .orange { 22 | background-color: orange; 23 | } -------------------------------------------------------------------------------- /02. Data Types and Variables - Exercise/Main_02.java: -------------------------------------------------------------------------------- 1 | public class Main_02 { 2 | 3 | public static void main(String[] args) { 4 | 5 | char symbol = 'A'; 6 | 7 | int asciiValue1 = (int) symbol; // explicit casting 8 | int asciiValue2 = symbol; // implicit casting 9 | 10 | System.out.println(asciiValue1); 11 | System.out.println(asciiValue2); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Exercise/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | 3 | public static void main(String[] args) { 4 | 5 | 6 | String number = "145"; 7 | 8 | char symbol = number.charAt(0); 9 | 10 | String symbolAsText = symbol + ""; 11 | 12 | int digit = Integer.parseInt(symbolAsText); 13 | 14 | System.out.println(digit); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /02. Data Types and Varibles - Lab/PoundsToDollars_02.java: -------------------------------------------------------------------------------- 1 | package DataTypes; 2 | 3 | import java.util.Scanner; 4 | 5 | public class PoundsToDollars_02 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | double pounds = Double.parseDouble(scanner.nextLine()); 10 | double dollars = pounds * 1.36; 11 | System.out.printf("%.3f", dollars); 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Lab/Passed_02.java: -------------------------------------------------------------------------------- 1 | package BasicsOverview; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Passed_02 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | double grade = Double.parseDouble(scanner.nextLine()); 10 | 11 | if (grade >= 3.00) { 12 | System.out.println("Passed!"); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /02. Data Types and Varibles - Lab/ConvertMetersToKilometers_01.java: -------------------------------------------------------------------------------- 1 | package DataTypes; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ConvertMetersToKilometers_01 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int meters = Integer.parseInt(scanner.nextLine()); 10 | double kilometers = meters/ 1000.0; 11 | System.out.printf("%.2f", kilometers); 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /HTML and CSS Basics - Common Lection/color-blocks.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Title 7 | 8 | 9 |
green block
10 |
blue block
11 |
red block
12 |
purple block
13 |
orange block
14 | 15 | 16 | -------------------------------------------------------------------------------- /06. Objects and Classes - Lab/SumBigNumbers_02.java: -------------------------------------------------------------------------------- 1 | import java.math.BigInteger; 2 | import java.util.Scanner; 3 | 4 | public class SumBigNumbers_02 { 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | BigInteger firstNumber = new BigInteger(scanner.nextLine()); 8 | BigInteger secondNumber = new BigInteger(scanner.nextLine()); 9 | 10 | System.out.println(firstNumber.add(secondNumber)); 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /04. Methods - Exercise/MethodsRecap.java: -------------------------------------------------------------------------------- 1 | public class MethodsRecap { 2 | 3 | public static void main(String[] args) { 4 | 5 | String name = getName(); 6 | 7 | int minNumber = getMinNumber(5, 10); 8 | 9 | System.out.println(minNumber); 10 | } 11 | 12 | public static String getName() { 13 | 14 | return "Desi"; 15 | } 16 | 17 | public static int getMinNumber(int num1, int num2) { 18 | 19 | return Math.min(num1, num2); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /06. Objects and Classes - Lab/demo/Demo.java: -------------------------------------------------------------------------------- 1 | package demo; 2 | 3 | import demo.Car; 4 | 5 | public class Demo { 6 | public static void main(String[] args) { 7 | //автокъща 8 | 9 | Car.print(); //staticß 10 | Car car1 = new Car(230,"Skoda", "blue"); 11 | car1.setHp(450); 12 | 13 | 14 | 15 | 16 | } 17 | public static void printCar (Car car) { 18 | System.out.println(car.getHp()); 19 | System.out.println(car.getBrand()); 20 | } 21 | } -------------------------------------------------------------------------------- /02. Data Types and Variables - Exercise/Elevator_03.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Elevator_03 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int peopleCount = Integer.parseInt(scanner.nextLine()); 10 | int capacity = Integer.parseInt(scanner.nextLine()); 11 | 12 | double courses = Math.ceil(peopleCount * 1.0 / capacity); 13 | 14 | System.out.printf("%.0f", courses); 15 | } 16 | } -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Lab/PassedOrFailed_03.java: -------------------------------------------------------------------------------- 1 | package BasicsOverview; 2 | 3 | import java.util.Scanner; 4 | 5 | public class PassedOrFailed_03 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | double grade = Double.parseDouble(scanner.nextLine()); 10 | if (grade > 2.99) { 11 | System.out.println("Passed!"); 12 | } else { 13 | System.out.println("Failed!"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /06. Objects and Classes - Exercise/opinion_poll_03/Person.java: -------------------------------------------------------------------------------- 1 | package opinion_poll_03; 2 | 3 | public class Person { 4 | 5 | // 1. Fields 6 | private String name; 7 | private int age; 8 | 9 | // 2. Constructor 10 | public Person(String name, int age) { 11 | this.name = name; 12 | this.age = age; 13 | } 14 | 15 | // 3. Methods 16 | public String getName() { 17 | return this.name; 18 | } 19 | 20 | public int getAge() { 21 | return this.age; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /02. Data Types and Varibles - Lab/ReversedChars_07.java: -------------------------------------------------------------------------------- 1 | package DataTypes; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ReversedChars_07 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | char firstSymbol = scanner.nextLine().charAt(0); 10 | char secondSymbol = scanner.nextLine().charAt(0); 11 | char thirdSymbol = scanner.nextLine().charAt(0); 12 | 13 | System.out.printf("%c %c %c", thirdSymbol, secondSymbol, firstSymbol); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /02. Data Types and Varibles - Lab/TownInfo_04.java: -------------------------------------------------------------------------------- 1 | package DataTypesAndVariables; 2 | 3 | import java.util.Scanner; 4 | 5 | public class TownInfo_04 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | String town = scanner.nextLine(); 9 | long population = Long.parseLong(scanner.nextLine()); 10 | short area = Short.parseShort(scanner.nextLine()); 11 | 12 | System.out.printf("Town %s has population of %d and area %d square km.", town, population, area); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /02. Data Types and Variables - Exercise/SumOfChars_04.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class SumOfChars_04 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int n = Integer.parseInt(scanner.nextLine()); 10 | int sum = 0; 11 | 12 | for (int i = 1; i <= n; i++) { 13 | 14 | char symbol = scanner.nextLine().charAt(0); 15 | sum += (int) symbol; 16 | } 17 | 18 | System.out.println("The sum equals: " + sum); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /03. Arrays - Lab/ReverseAnArrayOfStrings_04.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ReverseAnArrayOfStrings_04 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | String [] texts = scanner.nextLine().split(" "); 9 | //"a b c d e".split(" ") -> ["a", "b", "c", "d", "e"] 10 | 11 | for (int position = texts.length - 1; position >= 0; position--) { 12 | System.out.print(texts[position] + " "); 13 | } 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /06. Objects and Classes - Lab/BigFactorial_03.java: -------------------------------------------------------------------------------- 1 | import java.math.BigInteger; 2 | import java.util.Scanner; 3 | 4 | public class BigFactorial_03 { 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | int n = Integer.parseInt(scanner.nextLine()); 8 | BigInteger factorial = new BigInteger("1"); 9 | for (int number = 1; number <= n; number++) { 10 | factorial = factorial.multiply(BigInteger.valueOf(number)); 11 | } 12 | System.out.print(factorial); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Lab/RefactorSumOddNumbers_12.java: -------------------------------------------------------------------------------- 1 | package BasicsOverview; 2 | 3 | import java.util.Scanner; 4 | 5 | public class RefactorSumOddNumbers_12 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int n = Integer.parseInt(sc.nextLine()); 9 | int sum = 0; 10 | for (int i = 0; i < n; i++) { 11 | System.out.println(2 * i + 1); 12 | sum += 2 * i + 1; 13 | } 14 | System.out.printf("Sum: %d%n", sum); 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /04. Methods - Lab/MathPower_08.java: -------------------------------------------------------------------------------- 1 | package Methods; 2 | 3 | import java.util.Scanner; 4 | 5 | public class MathPower_08 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | int number = Integer.parseInt(scanner.nextLine()); 9 | int power = Integer.parseInt(scanner.nextLine()); 10 | 11 | System.out.printf("%.0f",calculatePower(number, power)); 12 | } 13 | 14 | private static double calculatePower(int number, int power) { 15 | return Math.pow(number, power); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /06. Objects and Classes - Exercise/advertisement_message_01/Main.java: -------------------------------------------------------------------------------- 1 | package advertisement_message_01; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner scanner = new Scanner(System.in); 10 | 11 | int n = Integer.parseInt(scanner.nextLine()); 12 | 13 | Message message = new Message(); 14 | 15 | for (int i = 0; i < n; i++) { 16 | String randomMessage = message.randomMessage(); 17 | System.out.println(randomMessage); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Exercise/TriangleOfNumbers_08.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class TriangleOfNumbers_08 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int n = Integer.parseInt(scanner.nextLine()); 10 | 11 | for (int row = 1; row <= n; row++) { 12 | 13 | for (int number = 1; number <= row; number++) { 14 | System.out.print(row + " "); 15 | } 16 | System.out.println(); 17 | } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /06. Objects and Classes - Exercise/demo/Book.java: -------------------------------------------------------------------------------- 1 | package demo; 2 | 3 | public class Book { 4 | 5 | // 1. Fields 6 | private String title; 7 | private String author; 8 | private double price; 9 | 10 | // 2. Constructor 11 | public Book(String title, String author, double price) { 12 | this.title = title; 13 | this.author = author; 14 | this.price = price; 15 | } 16 | 17 | // 3. Methods 18 | public void sell() { 19 | System.out.printf("Book with title: %s was successfully sold for %.2f.", this.title, this.price); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /04. Methods - Exercise/Matrix_07.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Matrix_07 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int n = Integer.parseInt(scanner.nextLine()); 10 | 11 | printTable(n); 12 | } 13 | 14 | public static void printTable(int n) { 15 | 16 | for (int row = 1; row <= n; row++) { 17 | for (int col = 1; col <= n; col++) { 18 | System.out.print(n + " "); 19 | } 20 | System.out.println(); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /02. Data Types and Varibles - Lab/ConcatNames_05.java: -------------------------------------------------------------------------------- 1 | package DataTypes; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ConcatNames_05 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | String firstName = scanner.nextLine(); 9 | String secondName = scanner.nextLine(); 10 | String delimiter = scanner.nextLine(); 11 | 12 | //начин 1 13 | //System.out.println(firstName + delimiter + secondName); 14 | 15 | //начин 2 16 | System.out.printf("%s%s%s", firstName, delimiter, secondName); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /03. Arrays - Exercise/CommonElements_02.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class CommonElements_02 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String[] firstArray = scanner.nextLine().split(" "); 10 | String[] secondArray = scanner.nextLine().split(" "); 11 | 12 | for (String el2 : secondArray) { 13 | 14 | for (String el1 : firstArray) { 15 | if (el2.equals(el1)) { 16 | System.out.print(el1 + " "); 17 | } 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Lab/StudentInformation_01.java: -------------------------------------------------------------------------------- 1 | package BasicsOverview; 2 | 3 | import java.util.Scanner; 4 | public class StudentInformation_01 { 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | String name = scanner.nextLine(); //име на студента 8 | int age = Integer.parseInt(scanner.nextLine()); //възраст на судента 9 | double averageGrade = Double.parseDouble(scanner.nextLine()); //средна оценка на студента 10 | 11 | System.out.printf("Name: %s, Age: %d, Grade: %.2f", name, age, averageGrade); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /08. Text Processing - Exercise/CaesarCipher_04.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class CaesarCipher_04 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String text = scanner.nextLine(); 10 | 11 | StringBuilder encryptedText = new StringBuilder(); 12 | 13 | for (char symbol : text.toCharArray()) { 14 | // 'A' -> 'D' 15 | char encryptedSymbol = (char) (symbol + 3); 16 | encryptedText.append(encryptedSymbol); 17 | } 18 | 19 | System.out.println(encryptedText); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /02. Data Types and Variables - Exercise/IntegerOperations_01.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class IntegerOperations_01 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int number1 = Integer.parseInt(scanner.nextLine()); 10 | int number2 = Integer.parseInt(scanner.nextLine()); 11 | int number3 = Integer.parseInt(scanner.nextLine()); 12 | int number4 = Integer.parseInt(scanner.nextLine()); 13 | 14 | // Формула: ((n1 + n2) / n3) * n4 15 | System.out.println(((number1 + number2) / number3) * number4); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /08. Text Processing - Lab/RepeatStrings_02.java: -------------------------------------------------------------------------------- 1 | package textProcessing; 2 | 3 | import java.util.Scanner; 4 | 5 | public class RepeatStrings_02 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String [] texts = scanner.nextLine().split(" "); 10 | 11 | for (String text : texts) { 12 | int length = text.length(); //дължина на текста = брой символи в текст 13 | /*for (int count = 1; count <= length; count++) { 14 | System.out.print(text); 15 | }*/ 16 | System.out.println(text.repeat(length)); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Lab/SumOddNumbers_09.java: -------------------------------------------------------------------------------- 1 | package BasicsOverview; 2 | 3 | import java.sql.SQLOutput; 4 | import java.util.Scanner; 5 | 6 | public class SumOddNumbers_09 { 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | int n = Integer.parseInt(scanner.nextLine()); 10 | int sum = 0; 11 | 12 | int number = 1; 13 | for (int count = 1; count <= n; count++) { 14 | System.out.println(number); 15 | sum += number; 16 | number += 2; 17 | } 18 | 19 | System.out.println("Sum: " + sum); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /06. Objects and Classes - Exercise/order_by_age_06/Person.java: -------------------------------------------------------------------------------- 1 | package order_by_age_06; 2 | 3 | public class Person { 4 | 5 | // 1. Fields 6 | private String name; 7 | private String id; 8 | private int age; 9 | 10 | // 2. Constructor 11 | public Person(String name, String id, int age) { 12 | this.name = name; 13 | this.id = id; 14 | this.age = age; 15 | } 16 | 17 | // 3. Methods 18 | public String getName() { 19 | return this.name; 20 | } 21 | 22 | public String getId() { 23 | return this.id; 24 | } 25 | 26 | public int getAge() { 27 | return this.age; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /03. Arrays - Lab/Demo/Demo2.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Demo2 { 4 | public static void main(String[] args) { 5 | //създаваме масива 6 | String [] names = new String[10]; //[null, null, null, null, null, null, null, null, null, null] 7 | names[0] = "Desi";//["Desi", null, null, null, null, null, null, null, null, null] 8 | names[1] = "Ivan";//["Desi", "Ivan", null, null, null, null, null, null, null, null] 9 | names[2] = "Miroslav";//["Desi", "Ivan", "Miroslav", null, null, null, null, null, null, null] 10 | //валидни позиции: >= 0 и < дължина 11 | System.out.println(names[8]); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /02. Data Types and Varibles - Lab/CharsToString_06.java: -------------------------------------------------------------------------------- 1 | package DataTypes; 2 | 3 | import java.util.Scanner; 4 | 5 | public class CharsToString_06 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | char firstSymbol = scanner.nextLine().charAt(0); 10 | char secondSymbol = scanner.nextLine().charAt(0); 11 | char thirdSymbol = scanner.nextLine().charAt(0); 12 | 13 | //начин 1 14 | //System.out.println("" + firstSymbol + secondSymbol + thirdSymbol); 15 | 16 | //начин 2 17 | System.out.printf("%c%c%c", firstSymbol, secondSymbol, thirdSymbol); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /08. Text Processing - Lab/TextFilter_04.java: -------------------------------------------------------------------------------- 1 | package textProcessing; 2 | 3 | import java.util.Scanner; 4 | 5 | public class TextFilter_04 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String[] forbiddenWords = scanner.nextLine().split(", "); 10 | String text = scanner.nextLine(); 11 | 12 | for (String forbiddenWord : forbiddenWords) { 13 | //"mask" -> "****" 14 | String replaceWord = "*".repeat(forbiddenWord.length()); 15 | text = text.replace(forbiddenWord, replaceWord); 16 | } 17 | 18 | System.out.println(text); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /04. Methods - Lab/CalculateArea_06.java: -------------------------------------------------------------------------------- 1 | package Methods; 2 | 3 | import java.util.Scanner; 4 | 5 | public class CalculateArea_06 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int length = Integer.parseInt(scanner.nextLine()); 10 | int width = Integer.parseInt(scanner.nextLine()); 11 | 12 | int area = calculateArea(length, width); 13 | System.out.println(area); 14 | } 15 | 16 | //метод, който изчислява и връща лицето на правоъгълник 17 | public static int calculateArea(int length, int width) { 18 | int area = length * width; 19 | return area; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /02. Data Types and Varibles - Lab/CenturiesToMinutes_09.java: -------------------------------------------------------------------------------- 1 | package DataTypesAndVariables; 2 | 3 | import java.util.Scanner; 4 | 5 | public class CenturiesToMinutes_09 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | byte centuries = Byte.parseByte(scanner.nextLine()); 10 | int years = centuries * 100; 11 | double days = years * 365.2422; 12 | double hours = days * 24; 13 | double minutes = hours * 60; 14 | 15 | System.out.printf("%d centuries = %d years = %.0f days = %.0f hours = %.0f minutes", centuries, years, days, hours, minutes); 16 | 17 | 18 | 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Lab/DivisibleBy3_08.java: -------------------------------------------------------------------------------- 1 | package BasicsOverview; 2 | 3 | import java.util.Scanner; 4 | 5 | public class DivisibleBy3_08 { 6 | public static void main(String[] args) { 7 | //[1; 100] които се делят на 3 8 | //for цикъл 9 | //1. начало -> 1 10 | //2. край -> 100 11 | //3. какво повтарям -> проверка дали се дели на 3 -> принтирам 12 | //4. промяна -> +1 13 | 14 | for (int number = 1; number <= 100; number++) { 15 | if (number % 3 == 0) { 16 | //number се дели на 3 17 | System.out.println(number); 18 | } 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /08. Text Processing - Exercise/ExtractFile_03.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ExtractFile_03 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | //"C:\Internal\training-internal\Template.pptx" 10 | String path = scanner.nextLine(); 11 | 12 | String[] elements = path.split("\\\\"); 13 | 14 | String fileName = elements[elements.length - 1].split("\\.")[0]; 15 | String fileExtension = elements[elements.length - 1].split("\\.")[1]; 16 | 17 | System.out.println("File name: " + fileName); 18 | System.out.println("File extension: " + fileExtension); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /04. Methods - Exercise/SmallestOfThreeNumbers_01.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class SmallestOfThreeNumbers_01 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int firstNumber = Integer.parseInt(scanner.nextLine()); 10 | int secondNumber = Integer.parseInt(scanner.nextLine()); 11 | int thirdNumber = Integer.parseInt(scanner.nextLine()); 12 | 13 | printSmallestNumber(firstNumber, secondNumber, thirdNumber); 14 | } 15 | 16 | public static void printSmallestNumber(int num1, int num2, int num3) { 17 | 18 | System.out.println(Math.min(Math.min(num1, num2), num3)); 19 | } 20 | } -------------------------------------------------------------------------------- /09. RegEx - Lab/MatchFullName_01.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.regex.Matcher; 3 | import java.util.regex.Pattern; 4 | 5 | public class MatchFullName_01 { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner scanner = new Scanner(System.in); 10 | 11 | String text = scanner.nextLine(); 12 | 13 | String regex = "\\b([A-Z][a-z]+) ([A-Z][a-z]+)"; 14 | Pattern pattern = Pattern.compile(regex); 15 | Matcher matcher = pattern.matcher(text); 16 | 17 | //matcher.find() -> true/false Ако намери следващо съвпадение 18 | while (matcher.find()){ 19 | System.out.print(matcher.group() + " "); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /08. Text Processing - Exercise/ReplaceRepeatingChars_06.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ReplaceRepeatingChars_06 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String input = scanner.nextLine(); 10 | StringBuilder textBulder = new StringBuilder(input); 11 | 12 | for (int position = 0; position < textBulder.length() - 1; position++) { 13 | if (textBulder.charAt(position) == textBulder.charAt(position + 1)) { 14 | textBulder.deleteCharAt(position + 1); 15 | position--; 16 | } 17 | } 18 | 19 | System.out.println(textBulder); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /02. Data Types and Varibles - Lab/ExactSumOfRealNumbers_03.java: -------------------------------------------------------------------------------- 1 | package DataTypes; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.Scanner; 5 | 6 | public class ExactSumOfRealNumbers_03 { 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | int count = Integer.parseInt(scanner.nextLine()); 10 | 11 | BigDecimal sum = new BigDecimal("0"); 12 | for (int number = 1; number <= count; number++) { //всички числа от първото до последното 13 | BigDecimal value = new BigDecimal(scanner.nextLine()); //стойността на въведеното число 14 | 15 | sum = sum.add(value); 16 | } 17 | 18 | System.out.println(sum); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /02. Data Types and Variables - Exercise/WaterOverflow_07.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class WaterOverflow_07 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int n = Integer.parseInt(scanner.nextLine()); 10 | int litters = 0; 11 | 12 | for (int i = 1; i <= n; i++) { 13 | 14 | int pouredLiters = Integer.parseInt(scanner.nextLine()); 15 | litters += pouredLiters; 16 | 17 | if (litters > 255) { 18 | System.out.println("Insufficient capacity!"); 19 | litters -= pouredLiters; 20 | } 21 | } 22 | 23 | System.out.println(litters); 24 | } 25 | } -------------------------------------------------------------------------------- /02. Data Types and Variables - Exercise/PrintPartOfAsciiTable_05.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class PrintPartOfAsciiTable_05 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int n = Integer.parseInt(scanner.nextLine()); 10 | 11 | //{a-n}{a-n}{a-n} 12 | for (char letter1 = 'a'; letter1 < 'a' + n; letter1++) { 13 | 14 | for (char letter2 = 'a'; letter2 < 'a' + n; letter2++) { 15 | 16 | for (char letter3 = 'a'; letter3 < 'a' + n; letter3++) { 17 | 18 | System.out.printf("%c%c%c\n", letter1, letter2, letter3); 19 | } 20 | } 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /02. Data Types and Varibles - Lab/RefactorVolumeOfPyramid_11.java: -------------------------------------------------------------------------------- 1 | package DataTypesAndVariables; 2 | 3 | import java.util.Scanner; 4 | 5 | public class RefactorVolumeOfPyramid_11 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | System.out.print("Length: "); 9 | double length = Double.parseDouble(scanner.nextLine()); 10 | System.out.print("Width: "); 11 | double width = Double.parseDouble(scanner.nextLine()); 12 | System.out.print("Height: "); 13 | double height = Double.parseDouble(scanner.nextLine()); 14 | double volume = (length * width * height) / 3; 15 | System.out.printf("Pyramid Volume: %.2f", volume); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /06. Objects and Classes - Exercise/students_04/Student.java: -------------------------------------------------------------------------------- 1 | package students_04; 2 | 3 | public class Student { 4 | 5 | // 1. Fields 6 | private String firstName; 7 | private String lastName; 8 | private double grade; 9 | 10 | // 2. Constructor 11 | public Student(String firstName, String lastName, double grade) { 12 | this.firstName = firstName; 13 | this.lastName = lastName; 14 | this.grade = grade; 15 | } 16 | 17 | // 3. Methods 18 | public String getFirstName() { 19 | return this.firstName; 20 | } 21 | 22 | public String getLastName() { 23 | return this.lastName; 24 | } 25 | 26 | public double getGrade() { 27 | return this.grade; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /03. Arrays - Exercise/Train_1.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Train_1 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int wagonsCount = Integer.parseInt(scanner.nextLine()); 10 | int[] wagons = new int[wagonsCount]; 11 | 12 | for (int wagon = 0; wagon < wagonsCount; wagon++) { 13 | int group = Integer.parseInt(scanner.nextLine()); 14 | wagons[wagon] = group; 15 | } 16 | 17 | int sum = 0; 18 | 19 | for (int number : wagons) { 20 | System.out.print(number + " "); 21 | sum += number; 22 | } 23 | 24 | System.out.println(); 25 | System.out.println(sum); 26 | } 27 | } -------------------------------------------------------------------------------- /03. Arrays - Lab/EvenOddSubtraction_05.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | public class EvenOddSubtraction_05 { 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | int[] numbers = Arrays.stream(scanner.nextLine().split(" ")) 11 | .mapToInt(Integer::parseInt) 12 | .toArray(); 13 | 14 | int odd = 0; 15 | int even = 0; 16 | 17 | for (int number : numbers) { 18 | if (number % 2 == 0) { 19 | even += number; 20 | } else { 21 | odd += number; 22 | } 23 | 24 | } 25 | 26 | System.out.println(even - odd); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /04. Methods - Exercise/VowelsCount_02.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class VowelsCount_02 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String text = scanner.nextLine().toLowerCase(); 10 | 11 | printVowelsCount(text); 12 | } 13 | 14 | public static void printVowelsCount(String text) { 15 | 16 | int countVowels = 0; 17 | 18 | for (char letter : text.toCharArray()) { 19 | // a, e, i, o, u 20 | if (letter == 'a' || letter == 'e' || letter == 'i' || letter == 'o' || letter == 'u') { 21 | countVowels++; 22 | } 23 | } 24 | 25 | System.out.println(countVowels); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Exercise/Ages_01.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Ages_01 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int age = Integer.parseInt(scanner.nextLine()); 10 | 11 | if (age >= 0 && age <= 2) { 12 | System.out.println("baby"); 13 | } else if (age >= 3 && age <= 13) { 14 | System.out.println("child"); 15 | } else if (age >= 14 && age <= 19) { 16 | System.out.println("teenager"); 17 | } else if (age >= 20 && age <= 65) { 18 | System.out.println("adult"); 19 | } else { 20 | System.out.println("elder"); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /02. Data Types and Variables - Exercise/SumDigits_02.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class SumDigits_02 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int number = Integer.parseInt(scanner.nextLine()); 10 | int sum = 0; 11 | 12 | // Повтарям: числото > 0 13 | // 1. Вземам последната цифра от числото (числото % 10) 14 | // 2. Прибавям последната цифра към сумата (sum += lastDigit) 15 | // 3. Премахваме последната цифра от числото (числото / 10) 16 | 17 | while (number > 0) { 18 | int lastDigit = number % 10; 19 | sum += lastDigit; 20 | number /= 10; 21 | } 22 | 23 | System.out.println(sum); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Lab/BackIn30Minutes_04.java: -------------------------------------------------------------------------------- 1 | package BasicsOverview; 2 | 3 | import java.util.Scanner; 4 | 5 | public class BackIn30Minutes_04 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | int hour = Integer.parseInt(scanner.nextLine()); 9 | int minutes = Integer.parseInt(scanner.nextLine()); 10 | 11 | int totalMinutes = hour * 60 + minutes; 12 | int totalMinutesBack = totalMinutes + 30; 13 | 14 | int resultHour = totalMinutesBack / 60; 15 | int resultMinutes = totalMinutesBack % 60; 16 | 17 | if (resultHour > 23) { 18 | resultHour = 0; 19 | } 20 | 21 | System.out.printf("%d:%02d", resultHour, resultMinutes); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /06. Objects and Classes - Lab/songs/Song.java: -------------------------------------------------------------------------------- 1 | package songs; 2 | 3 | public class Song { 4 | //характеристики (field): Type List, Name and Time (3:23) 5 | private String typeList; 6 | private String name; 7 | private String time; 8 | 9 | //конструктор -> създава обект от класа 10 | public Song (String typeList, String name, String time) { 11 | //нов празен обект 12 | this.typeList = typeList; 13 | this.name = name; 14 | this.time = time; 15 | } 16 | 17 | //getter за полето name -> върне стойността на полето name 18 | public String getName() { 19 | return name; 20 | } 21 | 22 | //getter за полето typeList -> върне стойността на полето typeList 23 | public String getTypeList() { 24 | return typeList; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /08. Text Processing - Lab/ReverseStringWithStringBuilder_01.java: -------------------------------------------------------------------------------- 1 | package textProcessing; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ReverseStringWithStringBuilder_01 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String input = scanner.nextLine(); //входни данни -> дума или "end" 10 | 11 | while (!input.equals("end")) { 12 | //input -> дума 13 | //input = "hello" 14 | StringBuilder sb = new StringBuilder(input); 15 | sb.reverse(); 16 | 17 | //входяща дума -> input 18 | //обърната дума -> reverseWord 19 | System.out.println(input + " = " + sb.toString()); 20 | 21 | input = scanner.nextLine(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /06. Objects and Classes - Lab/RandomizeWords_01.java: -------------------------------------------------------------------------------- 1 | import java.util.Random; 2 | import java.util.Scanner; 3 | 4 | public class RandomizeWords_01 { 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | 8 | String[] wordsArr = scanner.nextLine().split(" "); 9 | 10 | Random random = new Random(); 11 | 12 | for (int i = 0; i < wordsArr.length; i++) { 13 | int rndIndexX = random.nextInt(wordsArr.length); 14 | int rndIndexY = random.nextInt(wordsArr.length); 15 | 16 | String oldWord = wordsArr[rndIndexX]; 17 | wordsArr[rndIndexX] = wordsArr[rndIndexY]; 18 | wordsArr[rndIndexY] = oldWord; 19 | } 20 | 21 | System.out.println(String.join(System.lineSeparator(), wordsArr)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /04. Methods - Lab/PrintingTriangle_03.java: -------------------------------------------------------------------------------- 1 | package Methods; 2 | 3 | import java.util.Scanner; 4 | 5 | public class PrintingTriangle_03 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int input = Integer.parseInt(scanner.nextLine()); 10 | 11 | printTriangle(input); 12 | } 13 | 14 | public static void printTriangle (int num) { 15 | for (int i = 1; i <= num; i++) { 16 | printLine(1, i); 17 | } 18 | 19 | for (int i = num - 1; i >= 1; i--) { 20 | printLine(1, i); 21 | } 22 | } 23 | 24 | public static void printLine(int start, int end) { 25 | for (int i = start; i <= end; i++) { 26 | System.out.print(i + " "); 27 | } 28 | System.out.println(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /05. Lists - Exercise/AppendArrays_07.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Collections; 3 | import java.util.List; 4 | import java.util.Scanner; 5 | import java.util.stream.Collectors; 6 | 7 | public class AppendArrays_07 { 8 | 9 | public static void main(String[] args) { 10 | 11 | Scanner scanner = new Scanner(System.in); 12 | 13 | List elements = Arrays.stream(scanner.nextLine().split("\\|")).collect(Collectors.toList()); 14 | 15 | Collections.reverse(elements); 16 | 17 | String output = elements.toString() 18 | .replace("[", "") 19 | .replace("]", "") 20 | .replace(",", "") 21 | .replaceAll("\\s+", " ") 22 | .trim(); 23 | 24 | //7 8 4 5 6 1 2 3 25 | System.out.println(output); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /04. Methods - Exercise/AddAndSubtract_05.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class AddAndSubtract_05 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int firstNumber = Integer.parseInt(scanner.nextLine()); 10 | int secondNumber = Integer.parseInt(scanner.nextLine()); 11 | int thirdNumber = Integer.parseInt(scanner.nextLine()); 12 | 13 | int sum = sumTwoNumbers(firstNumber, secondNumber); 14 | int result = subtractTwoNumbers(sum, thirdNumber); 15 | 16 | System.out.println(result); 17 | } 18 | 19 | public static int sumTwoNumbers(int num1, int num2) { 20 | 21 | return num1 + num2; 22 | } 23 | 24 | public static int subtractTwoNumbers(int num1, int num2) { 25 | 26 | return num1 - num2; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /05. Lists - Lab/GaussTrick_02.java: -------------------------------------------------------------------------------- 1 | package Lists; 2 | 3 | import java.util.Scanner; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | import java.util.stream.Collectors; 7 | 8 | 9 | public class GaussTrick_02 { 10 | public static void main(String[] args) { 11 | Scanner scanner = new Scanner(System.in); 12 | 13 | List numbers = Arrays.stream(scanner.nextLine().split(" ")) 14 | .map(Integer::parseInt).collect(Collectors.toList()); 15 | 16 | int iteration = numbers.size() / 2; 17 | for (int i = 0; i < iteration; i++) { 18 | numbers.set(i, numbers.get(i) + numbers.get(numbers.size() - 1)); 19 | numbers.remove(numbers.size() - 1); 20 | } 21 | 22 | for (int number : numbers) { 23 | System.out.print(number + " "); 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /07. Maps, Lambda, Stream API - Lab/WordFilter_04.java: -------------------------------------------------------------------------------- 1 | package maps; 2 | 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | public class WordFilter_04 { 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | String[] words = Arrays.stream(scanner.nextLine().split(" ")) //["kiwi", "orange", "banana", "apple"] 10 | .filter(word -> word.length() % 2 == 0) //["kiwi", "orange", "banana"] 11 | .toArray(String[] :: new); 12 | 13 | //1 начин -> StreamAPI 14 | //words = ["kiwi", "orange", "banana"] 15 | //Arrays.stream(words).forEach(word -> System.out.println(word)); 16 | 17 | //2 начин -> foreach 18 | for (String word : words) { 19 | System.out.println(word); 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /08. Text Processing - Exercise/MultiplyBigNumber_05.java: -------------------------------------------------------------------------------- 1 | import java.math.BigInteger; 2 | import java.util.Scanner; 3 | 4 | public class MultiplyBigNumber_05 { 5 | 6 | public static void main(String[] args) { 7 | 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | String firstNumber = scanner.nextLine(); 11 | String secondNumber = scanner.nextLine(); 12 | 13 | BigInteger number1 = new BigInteger(firstNumber); 14 | BigInteger number2 = new BigInteger(secondNumber); 15 | 16 | // Умножение 17 | System.out.println(number1.multiply(number2)); 18 | 19 | // // Събиране 20 | // System.out.println(number1.add(number2)); 21 | // // Изваждане 22 | // System.out.println(number1.subtract(number2)); 23 | // // Деление 24 | // System.out.println(number1.divide(number2)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Lab/EvenNumber_11.java: -------------------------------------------------------------------------------- 1 | package BasicsOverview; 2 | 3 | import java.util.Scanner; 4 | 5 | public class EvenNumber_11 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | //while 10 | //повтаряме: въвеждаме цяло число 11 | //стоп: число е четно 12 | //продължаваме: число е нечетно 13 | 14 | int number = Integer.parseInt(scanner.nextLine()); 15 | 16 | while (number % 2 != 0) { 17 | //нечетно число 18 | System.out.println("Please write an even number."); 19 | 20 | //прочитаме 21 | number = Integer.parseInt(scanner.nextLine()); 22 | } 23 | 24 | //четно число -> прекратили цикъла 25 | System.out.println("The number is: " + Math.abs(number)); 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /03. Arrays - Exercise/CondenseArrayToNumber_07.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class CondenseArrayToNumber_07 { 5 | 6 | public static void main(String[] args) { 7 | 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | int[] numbers = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray(); 11 | 12 | if (numbers.length == 1) { 13 | System.out.print(numbers[0]); 14 | return; 15 | } 16 | 17 | while (numbers.length > 1) { 18 | 19 | int[] condensed = new int[numbers.length - 1]; 20 | 21 | for (int i = 0; i < condensed.length; i++) { 22 | condensed[i] = numbers[i] + numbers[i + 1]; 23 | } 24 | 25 | numbers = condensed; 26 | } 27 | 28 | System.out.println(numbers[0]); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Exercise/PrintAndSum_04.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class PrintAndSum_04 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int startNumber = Integer.parseInt(scanner.nextLine()); 10 | int endNumber = Integer.parseInt(scanner.nextLine()); 11 | 12 | int sum = 0; 13 | 14 | for (int number = startNumber; number <= endNumber; number++) { 15 | 16 | System.out.print(number + " "); 17 | sum += number; 18 | } 19 | 20 | // int number = startNumber; 21 | // while (number <= endNumber) { 22 | // 23 | // System.out.print(number + " "); 24 | // sum += number; 25 | // 26 | // number++; 27 | // } 28 | 29 | System.out.println("\nSum: " + sum); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /02. Data Types and Varibles - Lab/SpecialNumber_10.java: -------------------------------------------------------------------------------- 1 | package DataTypesAndVariables; 2 | 3 | import java.util.Scanner; 4 | 5 | public class SpecialNumber_10 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | int n = Integer.parseInt(scanner.nextLine()); 9 | for (int number = 1; number <= n; number++) { 10 | int sum = 0; 11 | int currentNumber = number; 12 | while (currentNumber != 0) { 13 | int lastDigit = currentNumber % 10; 14 | sum += lastDigit; 15 | currentNumber /= 10; 16 | } 17 | 18 | if (sum == 5 || sum == 7 || sum == 11) { 19 | System.out.println(number + " -> True"); 20 | } else { 21 | System.out.println(number + " -> False"); 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /03. Arrays - Lab/PrintNumbersInReverseOrder_02.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | import java.util.Scanner; 4 | 5 | public class PrintNumbersInReverseOrder_02 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | //1. съхраняваме числата в масив 9 | int count = Integer.parseInt(scanner.nextLine()); //брой на числата, с които ще работим 10 | int [] numbers = new int[count]; 11 | 12 | for (int position = 0; position <= numbers.length - 1; position++) { 13 | numbers[position] = Integer.parseInt(scanner.nextLine()); 14 | } 15 | 16 | //2. отпечтваме в обратен ред 17 | //[10, 20, 30] 18 | //обратен ред: последната позиция към първата 19 | for (int position = numbers.length - 1; position >= 0; position--) { 20 | System.out.print(numbers[position] + " "); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /06. Objects and Classes - Exercise/articles_02/Article.java: -------------------------------------------------------------------------------- 1 | package articles_02; 2 | 3 | public class Article { 4 | 5 | // 1. Fields 6 | private String title; 7 | private String content; 8 | private String author; 9 | 10 | // 2. Constructor 11 | public Article(String title, String content, String author) { 12 | this.title = title; 13 | this.content = content; 14 | this.author = author; 15 | } 16 | 17 | // 3. Methods 18 | public void edit(String newContent) { 19 | this.content = newContent; 20 | } 21 | 22 | public void changeAuthor(String newAuthor) { 23 | this.author = newAuthor; 24 | } 25 | 26 | public void rename(String newTitle) { 27 | this.title = newTitle; 28 | } 29 | 30 | public String toString() { 31 | return String.format("%s - %s: %s", this.title, this.content, this.author); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /04. Methods - Lab/MultiplyEvensByOdds_10.java: -------------------------------------------------------------------------------- 1 | package Methods; 2 | 3 | import java.util.Scanner; 4 | 5 | public class MultiplyEvensByOdds_10 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int number = Integer.parseInt(scanner.nextLine()); 10 | int [] sums = getSumEvenDddDigits(Math.abs(number)); 11 | 12 | System.out.println(sums[0] * sums[1]); 13 | } 14 | 15 | private static int[] getSumEvenDddDigits(int number) { 16 | int sumEven = 0; 17 | int sumOdd = 0; 18 | 19 | while (number > 0) { 20 | int lastDigit = number % 10; 21 | if (lastDigit % 2 == 0) { 22 | sumEven += lastDigit; 23 | } else { 24 | sumOdd += lastDigit; 25 | } 26 | number /= 10; 27 | } 28 | return new int[] {sumEven, sumOdd}; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Exercise/Orders_09.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Orders_09 { 4 | public static void main(String[] args) { 5 | 6 | Scanner scanner = new Scanner(System.in); 7 | 8 | int orders = Integer.parseInt(scanner.nextLine()); 9 | double money = 0; 10 | 11 | for (int order = 1; order <= orders; order++) { 12 | 13 | double pricePerCapsule = Double.parseDouble(scanner.nextLine()); 14 | int daysInMonth = Integer.parseInt(scanner.nextLine()); 15 | int capsulesCount = Integer.parseInt(scanner.nextLine()); 16 | 17 | double orderPrice = ((daysInMonth * capsulesCount) * pricePerCapsule); 18 | money += orderPrice; 19 | 20 | System.out.printf("The price for the coffee is: $%.2f%n", orderPrice); 21 | } 22 | 23 | System.out.printf("Total: $%.2f", money); 24 | } 25 | } -------------------------------------------------------------------------------- /04. Methods - Exercise/FactorialDivision_08.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class FactorialDivision_08 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int firstNumber = Integer.parseInt(scanner.nextLine()); 10 | int secondNumber = Integer.parseInt(scanner.nextLine()); 11 | 12 | long firstNumberFactorial = calculateFactorial(firstNumber); 13 | long secondNumberFactorial = calculateFactorial(secondNumber); 14 | 15 | double result = firstNumberFactorial * 1.0 / secondNumberFactorial; 16 | 17 | System.out.printf("%.2f", result); 18 | } 19 | 20 | public static long calculateFactorial(int number) { 21 | 22 | // 5! = 1 * 2 * 3 * 4 * 5 23 | long fact = 1; 24 | for (int i = 2; i <= number; i++) { 25 | fact *= i; 26 | } 27 | 28 | return fact; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Lab/ForeignLanguages_06.java: -------------------------------------------------------------------------------- 1 | package BasicsOverview; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ForeignLanguages_06 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String country = scanner.nextLine(); 10 | //"USA" or "England" -> English 11 | //"Spain" or "Argentina" or "Mexico" -> Spanish 12 | //other -> unknown 13 | 14 | switch (country) { 15 | case "USA": 16 | case "England": 17 | System.out.println("English"); 18 | break; 19 | case "Spain": 20 | case "Argentina": 21 | case "Mexico": 22 | System.out.println("Spanish"); 23 | break; 24 | default: 25 | System.out.println("unknown"); 26 | break; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /02. Data Types and Varibles - Lab/RefactorSpecialNumbers_12.java: -------------------------------------------------------------------------------- 1 | package DataTypesAndVariables; 2 | 3 | import java.util.Scanner; 4 | 5 | public class RefactorSpecialNumbers_12 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | int count = Integer.parseInt(scanner.nextLine()); 9 | 10 | for (int number = 1; number <= count; number++) { 11 | int sum = 0; 12 | int currentNumber = number; 13 | while (currentNumber > 0) { 14 | sum += currentNumber % 10; 15 | currentNumber = currentNumber / 10; 16 | } 17 | boolean isTrue = (sum == 5) || (sum == 7) || (sum == 11); 18 | if (isTrue) { 19 | System.out.printf("%d -> True%n", number); 20 | } else { 21 | System.out.printf("%d -> False%n", number); 22 | } 23 | 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /HTML and CSS Basics - Common Lection/lists.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | List Items 6 | 7 | 8 |
    9 |
  1. List item 1 10 |
      11 |
    1. Nested item 1.1
    2. 12 |
    3. Nested item 1.2
    4. 13 |
    14 |
  2. 15 | 16 |
  3. List item 2 17 |
      18 |
    1. Nested item 2.1
    2. 19 |
    3. Nested item 2.2 20 |
        21 |
      • Nested Item 2.2.1
      • 22 |
      • Nested Item 2.2.2
      • 23 |
      • Nested Item 2.2.3
      • 24 |
      25 |
    4. 26 |
    5. Nested item 2.3
    6. 27 |
    28 |
  4. 29 | 30 |
  5. List item 3
  6. 31 |
32 | 33 | -------------------------------------------------------------------------------- /03. Arrays - Lab/DayOfWeek_01.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | import java.util.Scanner; 4 | 5 | public class DayOfWeek_01 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | //1 -> "Monday" 10 | //2 -> "Tuesday" 11 | //3 -> "Wednesday" 12 | //4 -> "Thursday" 13 | //5 -> "Friday" 14 | //6 -> "Saturday" 15 | //7 -> "Sunday" 16 | //other -> Invalid day! 17 | int numberDay = Integer.parseInt(scanner.nextLine()); 18 | 19 | String [] daysOfWeek = {"Monday", "Tuesday", "Wednesday", "Thursday", 20 | "Friday", "Saturday", "Sunday"}; 21 | 22 | if (numberDay >= 1 && numberDay <= 7) { 23 | //отпечатваме деня на текущия номер 24 | System.out.println(daysOfWeek[numberDay - 1]); 25 | } else { 26 | System.out.println("Invalid day!"); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Exercise/Division_02.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Division_02 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int number = Integer.parseInt(scanner.nextLine()); 10 | 11 | if (number % 10 == 0) { 12 | System.out.println("The number is divisible by 10"); 13 | } else if (number % 7 == 0) { 14 | System.out.println("The number is divisible by 7"); 15 | } else if (number % 6 == 0) { 16 | System.out.println("The number is divisible by 6"); 17 | } else if (number % 3 == 0) { 18 | System.out.println("The number is divisible by 3"); 19 | } else if (number % 2 == 0) { 20 | System.out.println("The number is divisible by 2"); 21 | } else { 22 | System.out.println("Not divisible"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /08. Text Processing - Lab/Substring_03.java: -------------------------------------------------------------------------------- 1 | package textProcessing; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Substring_03 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String firstText = scanner.nextLine(); 10 | String secondText = scanner.nextLine(); 11 | 12 | int index = secondText.indexOf(firstText); 13 | //firstText = "ice" 14 | //secondText = "kgb" 15 | //ако firstText се съдържа в secondText -> на коя позиция се намира 16 | //ако firstText НЕ СЕ СЪДЪРЖА в secondText -> -1 17 | 18 | while (index != -1) { 19 | //firstText го има secondText 20 | secondText = secondText.replace(firstText, ""); 21 | //след премахването -> търсим дали имаме тази дума 22 | index = secondText.indexOf(firstText); 23 | } 24 | 25 | System.out.println(secondText); 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /04. Methods - Lab/Orders_05.java: -------------------------------------------------------------------------------- 1 | package Methods; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Orders_05 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String product = scanner.nextLine(); 10 | int quantity = Integer.parseInt(scanner.nextLine()); 11 | printPrice(product, quantity); 12 | 13 | } 14 | 15 | public static void printPrice(String product, int quantity) { 16 | 17 | switch (product) { 18 | case "coffee": 19 | System.out.printf("%.2f", quantity * 1.50); 20 | break; 21 | case "water": 22 | System.out.printf("%.2f", quantity * 1.00); 23 | break; 24 | case "coke": 25 | System.out.printf("%.2f", quantity * 1.40); 26 | break; 27 | case "snacks": 28 | System.out.printf("%.2f", quantity * 2.00); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /09. RegEx - Lab/regex-cheatsheet.txt: -------------------------------------------------------------------------------- 1 | Quantity Modifier / Колко пъти искаме да се среща даден текст? 2 | + -> 1 или повече пъти 3 | * -> 0 или повече пъти 4 | ? -> 0 или 1 път 5 | {число} -> колко точно пъти 6 | {число1, } -> колко най-малко пъти 7 | {число1, число2} -> колко най-малко(число1) пъти и колко най-много(число2) пъти 8 | 9 | Regex: 10 | [a-z] -> 1 малка буква 11 | [A-Z] -> 1 главна буква 12 | [0-9] -> 1 цифра 13 | [abv] -> 1 символ, който е или 'а', или 'b', или 'v' 14 | [^abv] -> 1 символ, който е РАЗЛИЧЕН от 'а', от 'b' и от 'v' 15 | \w -> 1 символ, който може да е малка или главна буква, цифра, или _ 16 | \W -> 1 символ, който РАЗЛИЧЕН от малка или главна буква, цифра, или _ 17 | \d -> 1 цифра 18 | \D -> 1 символ РАЗЛИЧЕН от цифра 19 | \s -> 1 интервал 20 | \S -> 1 символ РАЗЛИЧЕН от интервал 21 | () -> обособяваме група 22 | (?) -> обособяваме група с име 23 | \b -> слагаме граница, която казва, че не искаме да има символи(букви/цифри) преди/след съвпадението, което е открито в текста. -------------------------------------------------------------------------------- /03. Arrays - Exercise/MagicSum_08.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class MagicSum_08 { 5 | 6 | public static void main(String[] args) { 7 | 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | int[] numbers = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray(); 11 | int magicSum = Integer.parseInt(scanner.nextLine()); 12 | 13 | //1 7 6 2 19 23 14 | 15 | for (int position = 0; position < numbers.length - 1; position++) { 16 | 17 | int currentNumber = numbers[position]; 18 | 19 | for (int nextPosition = position + 1; nextPosition <= numbers.length - 1; nextPosition++) { 20 | 21 | int nextNumber = numbers[nextPosition]; 22 | 23 | if (currentNumber + nextNumber == magicSum) { 24 | System.out.printf("%d %d\n", currentNumber, nextNumber); 25 | } 26 | } 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /08. Text Processing - Lab/Demo/DemoStringVsStringBuilder.java: -------------------------------------------------------------------------------- 1 | package textProcessing; 2 | 3 | import java.util.Scanner; 4 | 5 | public class DemoStringVsStringBuilder { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | //STRING VS STRING BUILDER 10 | //1. STRING BUILDER има повече вградени методи от STRING -> insert, delete, reverse 11 | //2. STRING BUILDER e по-бърз от STRING 12 | 13 | //бързина на долепяне в String 14 | String textExample = ""; 15 | for (int i = 0; i < 1000000; i++) { 16 | textExample += "a"; 17 | //textExample = textExample + "a"; 18 | } 19 | 20 | System.out.println(textExample); 21 | 22 | //бързина на долепяне в StringBuilder 23 | StringBuilder sb = new StringBuilder(); //"" 24 | for (int i = 0; i < 1000000; i++) { 25 | sb.append("a"); 26 | } 27 | 28 | System.out.println(sb); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /06. Objects and Classes - Exercise/opinion_poll_03/Main.java: -------------------------------------------------------------------------------- 1 | package opinion_poll_03; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Scanner; 6 | 7 | public class Main { 8 | 9 | public static void main(String[] args) { 10 | 11 | Scanner scanner = new Scanner(System.in); 12 | 13 | List people = new ArrayList<>(); 14 | int n = Integer.parseInt(scanner.nextLine()); 15 | 16 | for (int i = 1; i <= n; i++) { 17 | 18 | //"{name} {age}" 19 | String input = scanner.nextLine(); 20 | String name = input.split(" ")[0]; 21 | int age = Integer.parseInt(input.split(" ")[1]); 22 | 23 | Person person = new Person(name, age); 24 | if (age > 30) { 25 | people.add(person); 26 | } 27 | } 28 | 29 | for (Person person : people) { 30 | System.out.printf("%s - %d\n", person.getName(), person.getAge()); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /09. RegEx - Lab/MatchPhoneNumber_02.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.List; 3 | import java.util.Scanner; 4 | import java.util.regex.Matcher; 5 | import java.util.regex.Pattern; 6 | 7 | public class MatchPhoneNumber_02 { 8 | 9 | public static void main(String[] args) { 10 | 11 | Scanner scanner = new Scanner(System.in); 12 | 13 | String text = scanner.nextLine(); 14 | 15 | // 1. Създавам регекс 16 | String regex = "\\+359([ -])2\\1\\d{3}\\1\\d{4}\\b"; 17 | // 2. Създавам шаблон 18 | Pattern pattern = Pattern.compile(regex); 19 | // 3. Създавам инструмент с помощта на който ще проверявам за съвпадения в прочетеният текст от конзолата 20 | Matcher matcher = pattern.matcher(text); 21 | 22 | List validNumbers = new ArrayList<>(); 23 | while (matcher.find()){ 24 | validNumbers.add(matcher.group()); 25 | } 26 | 27 | System.out.println(String.join(", ", validNumbers)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /04. Methods - Lab/Grades_02.java: -------------------------------------------------------------------------------- 1 | package Methods; 2 | 3 | import java.util.Scanner; 4 | import java.util.regex.Pattern; 5 | 6 | public class Grades_02 { 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | double grade = Double.parseDouble(scanner.nextLine()); 11 | printGradeInWords(grade); 12 | } 13 | //метод, който отпечтва името на оценката 14 | public static void printGradeInWords(double grade) { 15 | if (grade >= 2.00 && grade <= 2.99) { 16 | System.out.println("Fail"); 17 | } else if (grade >= 3.00 && grade <= 3.49) { 18 | System.out.println("Poor"); 19 | } else if (grade >= 3.50 && grade <= 4.49) { 20 | System.out.println("Good"); 21 | } else if (grade >= 4.50 && grade <= 5.49) { 22 | System.out.println("Very good"); 23 | } else if (grade >= 5.50 && grade <= 6.00) { 24 | System.out.println("Excellent"); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /04. Methods - Exercise/PalindromeIntegers_09.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class PalindromeIntegers_09 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String input = scanner.nextLine(); 10 | 11 | while (!input.equals("END")) { 12 | 13 | System.out.println(isInputPalindrome(input)); 14 | input = scanner.nextLine(); 15 | } 16 | } 17 | 18 | public static boolean isInputPalindrome(String input) { 19 | 20 | //Viko 21 | //okiV 22 | 23 | //Начин 1: 24 | String reversedString = ""; 25 | for (int index = input.length() - 1; index >= 0; index--) { 26 | reversedString += input.charAt(index); 27 | } 28 | 29 | //Начин 2: 30 | // StringBuilder builder = new StringBuilder(input); 31 | // String reversedString = builder.reverse().toString(); 32 | 33 | return input.equals(reversedString); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /08. Text Processing - Exercise/StringExplosion_07.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class StringExplosion_07 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String input = scanner.nextLine(); 10 | StringBuilder textBuilder = new StringBuilder(input); 11 | 12 | int totalStrength = 0; 13 | 14 | for (int position = 0; position < textBuilder.length(); position++) { 15 | 16 | char currentSymbol = textBuilder.charAt(position); 17 | 18 | if (currentSymbol == '>') { 19 | int explosionStrength = Integer.parseInt(textBuilder.charAt(position + 1) + ""); 20 | totalStrength += explosionStrength; 21 | } else if (totalStrength > 0) { 22 | textBuilder.deleteCharAt(position); 23 | totalStrength--; 24 | position--; 25 | } 26 | } 27 | 28 | System.out.println(textBuilder); 29 | } 30 | } -------------------------------------------------------------------------------- /08. Text Processing - Lab/ReverseString_01.java: -------------------------------------------------------------------------------- 1 | package textProcessing; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ReverseString_01 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String input = scanner.nextLine(); //входни данни -> дума или "end" 10 | while (!input.equals("end")) { 11 | //input -> дума 12 | //input = "hello" 13 | String reverseWord = ""; //обърнатата дума 14 | for (int position = input.length() - 1; position >= 0; position--) { 15 | char currentSymbol = input.charAt(position); 16 | reverseWord = reverseWord + currentSymbol; 17 | //reverseWord += currentSymbol; 18 | } 19 | 20 | //входяща дума -> input 21 | //обърната дума -> reverseWord 22 | System.out.println(input + " = " + reverseWord); 23 | 24 | input = scanner.nextLine(); 25 | } 26 | 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /04. Methods - Lab/SignOfIntegers_01.java: -------------------------------------------------------------------------------- 1 | package Methods; 2 | 3 | import java.util.Scanner; 4 | 5 | public class SignOfIntegers_01 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | int number = Integer.parseInt(scanner.nextLine()); 9 | printTypeOfInteger(number); 10 | 11 | } 12 | //метод, който отпечатва вида на цялото число 13 | //< 0 -> negative 14 | //== 0 -> zero 15 | //> 0 -> positive 16 | //public static {тип на метода} {име на метод} ({параметри}) { } 17 | public static void printTypeOfInteger (int number) { 18 | if (number < 0) { 19 | //negative number 20 | System.out.printf("The number %d is negative.", number); 21 | } else if (number == 0) { 22 | //zero 23 | System.out.printf("The number %d is zero.", number); 24 | } else { 25 | //positive 26 | System.out.printf("The number %d is positive.", number); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /HTML and CSS Basics - Common Lection/wiki-page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | The Brown Bear 6 | 7 | 8 |

The Brown Bear

9 |

The brown bear (Ursus arctos) is native to parts of northern Eurasia and North America. 10 | It's conservation status is currently "Least Concern". There are many subspecies within 11 | the brown bear species, including the Atlas bear and the Himalayan brown bear.

12 | Learn More 13 |

Here are some bear species:

14 |
    15 |
  • Arctos
  • 16 |
  • Collarus
  • 17 |
  • Horribilis
  • 18 |
  • Nelsoni (extinct)
  • 19 |
20 |

The following countries have the largest populations of brown bears:

21 |
    22 |
  1. Russia
  2. 23 |
  3. United States
  4. 24 |
  5. Canada
  6. 25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /04. Methods - Exercise/CharactersInRange_03.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class CharactersInRange_03 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | char firstSymbol = scanner.nextLine().charAt(0); // "a" -> 'a' 10 | char secondSymbol = scanner.nextLine().charAt(0); 11 | 12 | printSymbolsInRange(firstSymbol, secondSymbol); 13 | } 14 | 15 | public static void printSymbolsInRange(char firstSymbol, char secondSymbol) { 16 | 17 | // по-малкият до по-големият 18 | if (firstSymbol < secondSymbol) { 19 | for (int asciiValue = firstSymbol + 1; asciiValue < secondSymbol; asciiValue++) { 20 | System.out.print((char) asciiValue + " "); 21 | } 22 | } else { 23 | for (int asciiValue = secondSymbol + 1; asciiValue < firstSymbol; asciiValue++) { 24 | System.out.print((char) asciiValue + " "); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /03. Arrays - Exercise/ArrayRotation_04.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ArrayRotation_04 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String[] array = scanner.nextLine().split(" "); 10 | int rotations = Integer.parseInt(scanner.nextLine()); 11 | 12 | for (int rotation = 1; rotation <= rotations; rotation++) { 13 | 14 | // 1 - Вземаме първият елемент от масива 15 | String firstElement = array[0]; 16 | 17 | // 2 - Обхождаме масива и преместваме елементите наляво 18 | for (int position = 0; position < array.length - 1; position++) { 19 | array[position] = array[position + 1]; 20 | } 21 | 22 | // 3 - Поставяме първият елемент на последна позиция 23 | array[array.length - 1] = firstElement; 24 | } 25 | 26 | for (String element : array) { 27 | System.out.print(element + " "); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /07. Associative Arrays - Exercise/AMinerTask_02.java: -------------------------------------------------------------------------------- 1 | import java.util.LinkedHashMap; 2 | import java.util.Map; 3 | import java.util.Scanner; 4 | 5 | public class AMinerTask_02 { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner scanner = new Scanner(System.in); 10 | 11 | Map resources = new LinkedHashMap<>(); 12 | 13 | String resource = scanner.nextLine(); 14 | while (!resource.equals("stop")) { 15 | 16 | int quantity = Integer.parseInt(scanner.nextLine()); 17 | 18 | if (resources.containsKey(resource)) { 19 | int existingQuantity = resources.get(resource); 20 | resources.put(resource, existingQuantity + quantity); 21 | } else { 22 | resources.put(resource, quantity); 23 | } 24 | 25 | resource = scanner.nextLine(); 26 | } 27 | 28 | resources.entrySet().forEach(entry -> System.out.printf("%s -> %d\n", entry.getKey(), entry.getValue())); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /03. Arrays - Exercise/ArrayRecap.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class ArrayRecap { 5 | 6 | public static void main(String[] args) { 7 | 8 | // Масив от числа 9 | int[] numbers1 = new int[3]; 10 | 11 | numbers1[0] = 5; 12 | numbers1[1] = 20; 13 | numbers1[2] = 25; 14 | 15 | // Прочитане на масив от конзолата 16 | Scanner scanner = new Scanner(System.in); 17 | String input = scanner.nextLine(); 18 | String[] towns = input.split(" "); 19 | 20 | // foreach цикъл 21 | for (String town : towns) { 22 | System.out.println(town + " is a nice city."); 23 | } 24 | 25 | // String.join 26 | System.out.println(String.join(", ", towns)); 27 | 28 | // Прочитане на целочислен масив от конзолата 29 | int[] numbers = Arrays.stream(scanner.nextLine().split(" ")) 30 | .mapToInt(Integer::parseInt) 31 | .toArray(); 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /04. Methods - Lab/RepeatString_07.java: -------------------------------------------------------------------------------- 1 | package Methods; 2 | 3 | import java.util.Scanner; 4 | 5 | public class RepeatString_07 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | //1. входни данни 10 | String textToRepeat = scanner.nextLine(); 11 | int countRepeat = Integer.parseInt(scanner.nextLine()); 12 | //2. контсруираме текста 13 | String finalText = buildText(textToRepeat, countRepeat); 14 | //3. отпечатваме текста 15 | System.out.println(finalText); 16 | } 17 | 18 | 19 | //метод, който образува текста и го връща 20 | public static String buildText (String textToRepeat, int countRepeat) { 21 | String builtText = ""; //изгрдения текст 22 | 23 | for (int count = 1; count <= countRepeat; count++) { 24 | builtText += textToRepeat; 25 | //builtText = builtText + textToRepeat; 26 | } 27 | 28 | //готовия текст с повторенията 29 | return builtText; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /07. Maps, Lambda, Stream API - Lab/OddOccurrences_03.java: -------------------------------------------------------------------------------- 1 | package maps; 2 | 3 | import java.util.ArrayList; 4 | import java.util.LinkedHashMap; 5 | import java.util.Map; 6 | import java.util.Scanner; 7 | 8 | public class OddOccurrences_03 { 9 | public static void main(String[] args) { 10 | Scanner scanner = new Scanner(System.in); 11 | 12 | String[] inputArr = scanner.nextLine().split(" "); 13 | 14 | LinkedHashMap wordsMap = new LinkedHashMap<>(); 15 | 16 | for (String word : inputArr) { 17 | word = word.toLowerCase(); 18 | 19 | wordsMap.putIfAbsent(word, 0); 20 | wordsMap.put(word, wordsMap.get(word) + 1); 21 | } 22 | ArrayList resultList = new ArrayList<>(); 23 | for (Map.Entry entry : wordsMap.entrySet()) { 24 | if (entry.getValue() % 2 != 0) { 25 | resultList.add(entry.getKey()); 26 | } 27 | } 28 | System.out.println(String.join(", ", resultList)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Mid Exam Preparation - Part 1/CounterStrike_01.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class CounterStrike_01 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int energy = Integer.parseInt(scanner.nextLine()); 10 | int wins = 0; 11 | 12 | String input = scanner.nextLine(); 13 | while (!input.equals("End of battle")) { 14 | 15 | int distance = Integer.parseInt(input); 16 | if (distance <= energy) { 17 | wins++; 18 | energy -= distance; 19 | if (wins % 3 == 0) { 20 | energy += wins; 21 | } 22 | } else { 23 | System.out.printf("Not enough energy! Game ends with %d won battles and %d energy", wins, energy); 24 | return; 25 | } 26 | 27 | input = scanner.nextLine(); 28 | } 29 | 30 | System.out.printf("Won battles: %d. Energy left: %d", wins, energy); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /06. Objects and Classes - Lab/students/Student.java: -------------------------------------------------------------------------------- 1 | package students; 2 | 3 | public class Student { 4 | //характеристики: first name, last name, age and hometown 5 | //fields 6 | private String firstName; 7 | private String lastName; 8 | private int age; 9 | private String hometown; 10 | 11 | //конструктор -> създаваме обекти от класа 12 | public Student(String firstName, String lastName, int age, String hometown) { 13 | //нов празен обект 14 | this.firstName = firstName; 15 | this.lastName = lastName; 16 | this.age = age; 17 | this.hometown = hometown; 18 | } 19 | 20 | //методи -> действията, които ще може да прави всеки един студент 21 | //getters and setters 22 | public String getFirstName() { 23 | return firstName; 24 | } 25 | 26 | public String getLastName() { 27 | return lastName; 28 | } 29 | 30 | public int getAge() { 31 | return age; 32 | } 33 | 34 | public String getHometown() { 35 | return hometown; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /02. Data Types and Variables - Exercise/PokeMon_10.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class PokeMon_10 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int power = Integer.parseInt(scanner.nextLine()); 10 | int distance = Integer.parseInt(scanner.nextLine()); 11 | int factor = Integer.parseInt(scanner.nextLine()); 12 | int startPower = power; 13 | 14 | int countPokes = 0; 15 | 16 | while (power >= distance) { 17 | 18 | // 1. Отива до целта (power -= distance) 19 | power -= distance; 20 | // 2. Отброяваме успешно намушкване 21 | countPokes++; 22 | // 3. Проверяваме дали сме стигнали фактор на умора 23 | if (power == startPower / 2) { 24 | if (factor != 0) { 25 | power /= factor; 26 | } 27 | } 28 | } 29 | 30 | System.out.println(power); 31 | System.out.println(countPokes); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /06. Objects and Classes - Exercise/groomingSalon/Pet.java: -------------------------------------------------------------------------------- 1 | package groomingSalon; 2 | 3 | public class Pet { 4 | 5 | // 1. Fields 6 | private String name; 7 | private int age; 8 | private String owner; 9 | 10 | // 2. Constructor 11 | public Pet(String name, int age, String owner) { 12 | this.name = name; 13 | this.age = age; 14 | this.owner = owner; 15 | } 16 | 17 | // 3. Methods 18 | public String getName() { 19 | return this.name; 20 | } 21 | 22 | public int getAge() { 23 | return this.age; 24 | } 25 | 26 | public String getOwner() { 27 | return this.owner; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public void setAge(int age) { 35 | this.age = age; 36 | } 37 | 38 | public void setOwner(String owner) { 39 | this.owner = owner; 40 | } 41 | 42 | public String toString() { 43 | return String.format("%s %d - (%s)", this.name, this.age, this.owner); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /07. Associative Arrays - Exercise/CountCharsInAString_01.java: -------------------------------------------------------------------------------- 1 | import java.util.LinkedHashMap; 2 | import java.util.Map; 3 | import java.util.Scanner; 4 | 5 | public class CountCharsInAString_01 { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner scanner = new Scanner(System.in); 10 | 11 | Map characterCounts = new LinkedHashMap<>(); 12 | 13 | String input = scanner.nextLine(); 14 | 15 | for (char symbol : input.toCharArray()) { 16 | 17 | if (symbol == ' ') { 18 | continue; 19 | } 20 | 21 | if (characterCounts.containsKey(symbol)) { 22 | int count = characterCounts.get(symbol); 23 | characterCounts.put(symbol, count + 1); 24 | } else { 25 | characterCounts.put(symbol, 1); 26 | } 27 | } 28 | 29 | for (Map.Entry entry : characterCounts.entrySet()) { 30 | System.out.println(entry.getKey() + " -> " + entry.getValue()); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Exercise/StrongNumber_06.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class StrongNumber_06 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String inputNumber = scanner.nextLine(); 10 | int sumOfFactorials = 0; 11 | 12 | for (int position = 0; position <= inputNumber.length() - 1; position++) { 13 | 14 | int digit = Integer.parseInt(inputNumber.charAt(position) + ""); 15 | 16 | // Calculate Factorial 17 | int factorial = 1; 18 | for (int i = 2; i <= digit; i++) { 19 | factorial *= i; 20 | } 21 | 22 | // Add current Factorial to the SUM 23 | sumOfFactorials += factorial; 24 | } 25 | 26 | int number = Integer.parseInt(inputNumber); 27 | 28 | if (number == sumOfFactorials) { 29 | System.out.println("yes"); 30 | } else { 31 | System.out.println("no"); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /03. Arrays - Exercise/TopIntegers_05.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class TopIntegers_05 { 5 | 6 | public static void main(String[] args) { 7 | 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | int[] numbers = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray(); 11 | 12 | for (int position = 0; position < numbers.length - 1; position++) { 13 | 14 | int currentNumber = numbers[position]; 15 | boolean isTop = true; 16 | 17 | for (int nextPosition = position + 1; nextPosition < numbers.length; nextPosition++) { 18 | int nextNumber = numbers[nextPosition]; 19 | if (nextNumber >= currentNumber) { 20 | isTop = false; 21 | break; 22 | } 23 | } 24 | 25 | if (isTop) { 26 | System.out.print(currentNumber + " "); 27 | } 28 | } 29 | 30 | System.out.println(numbers[numbers.length - 1]); 31 | } 32 | } -------------------------------------------------------------------------------- /08. Text Processing - Exercise/ValidUsernames_01.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ValidUsernames_01 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String[] usernames = scanner.nextLine().split(", "); 10 | 11 | for (String username : usernames) { 12 | 13 | if (isUsernameValid(username)) { 14 | System.out.println(username); 15 | } 16 | } 17 | 18 | } 19 | 20 | private static boolean isUsernameValid(String username) { 21 | 22 | //Has a length of between 3 and 16 characters. 23 | if (username.length() < 3 || username.length() > 16) { 24 | return false; 25 | } 26 | 27 | //It contains only letters, numbers, hyphens, and underscores. 28 | for (char symbol : username.toCharArray()) { 29 | if (!Character.isLetterOrDigit(symbol) && symbol != '-' && symbol != '_') { 30 | return false; 31 | } 32 | } 33 | 34 | return true; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /09. RegEx - Lab/MatchDates_03.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.regex.Matcher; 3 | import java.util.regex.Pattern; 4 | 5 | public class MatchDates_03 { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner scanner = new Scanner(System.in); 10 | 11 | String text = scanner.nextLine(); 12 | 13 | String regex = "\\b(?\\d{2})([\\.\\-\\/])(?[A-Z][a-z]{2})\\2(?\\d{4})\\b"; 14 | Pattern pattern = Pattern.compile(regex); 15 | Matcher matcher = pattern.matcher(text); 16 | 17 | while (matcher.find()) { 18 | String wholeMatch = matcher.group(); //"13/Jul/1928" 19 | String day = matcher.group("day"); //"13" 20 | String month = matcher.group("month"); //"Jul" 21 | String year = matcher.group("year"); //"1928" 22 | // String day = matcher.group(1); 23 | // String month = matcher.group(3); 24 | // String year = matcher.group(4); 25 | System.out.printf("Day: %s, Month: %s, Year: %s\n", day, month, year); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /02. Data Types and Varibles - Lab/LowerOrUpper_08.java: -------------------------------------------------------------------------------- 1 | package DataTypes; 2 | 3 | import java.util.Scanner; 4 | 5 | public class LowerOrUpper_08 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | //на 0 позиция стои първата буква 10 | char symbol = scanner.nextLine().charAt(0); 11 | 12 | //проверка дали буквата е главна или малка 13 | 14 | //начин 1 15 | /*if (Character.isUpperCase(symbol)) { 16 | //главна буква 17 | System.out.println("upper-case"); 18 | } else { 19 | //малка буква 20 | System.out.println("lower-case"); 21 | }*/ 22 | 23 | //начин 2 24 | 25 | int code = (int) symbol; //аски код на въведения символ 26 | if (code >= 97 && code <= 122) { 27 | //малка буква - код: [97; 122] 28 | System.out.println("lower-case"); 29 | } else if (code >= 65 && code <= 90) { 30 | //голяма буква - код: [65; 90] 31 | System.out.println("upper-case"); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /07. Maps, Lambda, Stream API - Lab/Demo/Demo2.java: -------------------------------------------------------------------------------- 1 | package maps; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.Scanner; 6 | 7 | public class Demo2 { 8 | public static void main(String[] args) { 9 | Scanner scanner = new Scanner(System.in); 10 | //фирма 11 | //име на човек(String) -> заплата(double) 12 | Map salariesMap = new HashMap<>(); 13 | 14 | //HashMap -> няма специфична подредба на елементите 15 | salariesMap.put("Plamen", 564.54); //добавя при всички случаи 16 | salariesMap.putIfAbsent("Ivan", 3450.50); //добавя ако такъв ключ няма 17 | 18 | //nested maps -> in Java Advanced 19 | Map> nestedMap = new HashMap<>(); 20 | 21 | 22 | //salariesMap 23 | //Plamen -> 564.54 24 | //Ivan -> 3450.50 25 | 26 | salariesMap.replace("Plamen", 4500.00); 27 | //salariesMap 28 | //Plamen -> 4500.00 29 | //Ivan -> 3450.50 30 | 31 | salariesMap.replace("Ivan", 3450.50, 2300.00); 32 | 33 | 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /02. Data Types and Variables - Exercise/SpiceMustFlow_09.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class SpiceMustFlow_09 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // Началната сила на полето 10 | int startingYield = Integer.parseInt(scanner.nextLine()); 11 | 12 | int days = 0; 13 | int totalSpices = 0; 14 | 15 | while (startingYield >= 100) { 16 | 17 | // Берем подправки за деня 18 | totalSpices += startingYield; 19 | 20 | // Намаляме силата на полето с 10 21 | startingYield -= 10; 22 | 23 | // Екипажът, който събира подправките консумира по 26 подправки всеки ден 24 | totalSpices -= 26; 25 | 26 | days++; 27 | 28 | // Бракуваме допълнително 26 подправки, само ако полето е изтощено 29 | if (startingYield < 100) { 30 | totalSpices -= 26; 31 | } 32 | } 33 | 34 | System.out.println(days); 35 | System.out.println(totalSpices); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Exercise/Login_05.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Login_05 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String username = scanner.nextLine(); 10 | String password = ""; 11 | 12 | // Generate password 13 | for (int position = username.length() - 1; position >= 0; position--) { 14 | 15 | password += username.charAt(position); 16 | } 17 | 18 | int incorrectPasswordCount = 0; 19 | String enteredPassword = scanner.nextLine(); 20 | while (!enteredPassword.equals(password)) { 21 | 22 | incorrectPasswordCount++; 23 | if (incorrectPasswordCount == 4) { 24 | System.out.printf("User %s blocked!", username); 25 | return; 26 | } 27 | 28 | System.out.println("Incorrect password. Try again."); 29 | enteredPassword = scanner.nextLine(); 30 | } 31 | 32 | System.out.printf("User %s logged in.", username); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /07. Associative Arrays - Exercise/Courses_05.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Courses_05 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | Map> courses = new LinkedHashMap<>(); 10 | 11 | String input = scanner.nextLine(); 12 | while (!input.equals("end")) { 13 | 14 | String[] tokens = input.split(" : "); 15 | String courseName = tokens[0]; 16 | String studentName = tokens[1]; 17 | 18 | courses.putIfAbsent(courseName, new ArrayList<>()); 19 | courses.get(courseName).add(studentName); 20 | 21 | input = scanner.nextLine(); 22 | } 23 | 24 | for (Map.Entry> entry : courses.entrySet()) { 25 | 26 | String courseName = entry.getKey(); 27 | List studentNames = entry.getValue(); 28 | 29 | System.out.printf("%s: %d\n", courseName, studentNames.size()); 30 | studentNames.forEach(name -> System.out.printf("-- %s\n", name)); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Lab/MultiplicationTable_10.java: -------------------------------------------------------------------------------- 1 | package BasicsOverview; 2 | 3 | import java.util.Scanner; 4 | 5 | public class MultiplicationTable_10 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int number = Integer.parseInt(scanner.nextLine()); 10 | //for 11 | //1. начало: 1 12 | //2. край: 10 13 | //3. повтаряме: отпечатваме number * друго число = резултат 14 | //4. промяна: +1 15 | 16 | for (int multiplier = 1; multiplier <= 10 ; multiplier++) { 17 | System.out.printf("%d X %d = %d%n", number, multiplier, number * multiplier); 18 | //System.out.println(number + " X " + multiplier + " = " + number * multiplier); 19 | } 20 | 21 | //стоп: втория множител > 10 22 | //продължавам: втория множител <= 10 23 | int multiplier = 1; //втория множител 24 | while (multiplier <= 10) { 25 | System.out.printf("%d X %d = %d%n", number, multiplier, number * multiplier); 26 | multiplier++; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /06. Objects and Classes - Exercise/order_by_age_06/Main.java: -------------------------------------------------------------------------------- 1 | package order_by_age_06; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Comparator; 5 | import java.util.List; 6 | import java.util.Scanner; 7 | 8 | public class Main { 9 | 10 | public static void main(String[] args) { 11 | 12 | Scanner scanner = new Scanner(System.in); 13 | 14 | List people = new ArrayList<>(); 15 | 16 | String input = scanner.nextLine(); 17 | while (!input.equals("End")) { 18 | 19 | //"George 123456 20" 20 | String name = input.split(" ")[0]; 21 | String id = input.split(" ")[1]; 22 | int age = Integer.parseInt(input.split(" ")[2]); 23 | 24 | Person person = new Person(name, id, age); 25 | people.add(person); 26 | 27 | input = scanner.nextLine(); 28 | } 29 | 30 | people.sort(Comparator.comparing(Person::getAge)); 31 | 32 | for (Person person : people) { 33 | System.out.printf("%s with ID: %s is %d years old.\n", person.getName(), person.getId(), person.getAge()); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /HTML and CSS Basics - Common Lection/fruits.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Fruits 6 | 7 | 8 |

Fruits

9 |

10 | 11 | 12 | 13 | 14 | 15 |

16 |

17 | 18 | 19 | 20 | 21 | 22 |

23 |

24 | 25 | 26 | 27 | 28 | 29 |

30 | 31 | -------------------------------------------------------------------------------- /05. Lists - Exercise/HouseParty_03.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.List; 3 | import java.util.Scanner; 4 | 5 | public class HouseParty_03 { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner scanner = new Scanner(System.in); 10 | 11 | List guest = new ArrayList<>(); 12 | int number = Integer.parseInt(scanner.nextLine()); 13 | 14 | for (int i = 0; i < number; i++) { 15 | 16 | String command = scanner.nextLine(); 17 | String name = command.split(" ")[0]; 18 | 19 | if (command.contains("not")) { 20 | if (guest.contains(name)) { 21 | guest.remove(name); 22 | } else { 23 | System.out.printf("%s is not in the list!\n", name); 24 | } 25 | } else if (guest.contains(name)) { 26 | System.out.printf("%s is already in the list!\n", name); 27 | } else { 28 | guest.add(name); 29 | } 30 | } 31 | 32 | for (String name : guest) { 33 | System.out.println(name); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /07. Associative Arrays - Exercise/CompanyUsers_08.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class CompanyUsers_08 { 4 | 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | 8 | Map> listOfEmployees = new LinkedHashMap<>(); 9 | 10 | String input = scanner.nextLine(); 11 | while (!input.equals("End")) { 12 | 13 | String[] data = input.split(" -> "); 14 | 15 | List currentCompanyEmployees = listOfEmployees.get(data[0]); 16 | boolean containsId = currentCompanyEmployees != null && currentCompanyEmployees.contains(data[1]); 17 | 18 | if (!containsId) { 19 | listOfEmployees.putIfAbsent(data[0], new ArrayList<>()); 20 | listOfEmployees.get(data[0]).add(data[1]); 21 | } 22 | 23 | input = scanner.nextLine(); 24 | } 25 | 26 | for (Map.Entry> entry : listOfEmployees.entrySet()) { 27 | System.out.printf("%s\n", entry.getKey()); 28 | entry.getValue().forEach(id -> System.out.printf("-- %s\n", id)); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /06. Objects and Classes - Exercise/students_04/Main.java: -------------------------------------------------------------------------------- 1 | package students_04; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Comparator; 5 | import java.util.List; 6 | import java.util.Scanner; 7 | 8 | public class Main { 9 | 10 | public static void main(String[] args) { 11 | 12 | Scanner scanner = new Scanner(System.in); 13 | 14 | List students = new ArrayList<>(); 15 | int n = Integer.parseInt(scanner.nextLine()); 16 | 17 | for (int i = 1; i <= n; i++) { 18 | 19 | //"Lakia Eason 3.90" 20 | String input = scanner.nextLine(); 21 | String firstName = input.split(" ")[0]; 22 | String lastName = input.split(" ")[1]; 23 | double grade = Double.parseDouble(input.split(" ")[2]); 24 | 25 | Student student = new Student(firstName, lastName, grade); 26 | students.add(student); 27 | } 28 | 29 | students.sort(Comparator.comparing(Student::getGrade).reversed()); 30 | 31 | for (Student student : students) { 32 | System.out.printf("%s %s: %.2f\n", student.getFirstName(), student.getLastName(), student.getGrade()); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /04. Methods - Lab/MathOperations_11.java: -------------------------------------------------------------------------------- 1 | package Methods; 2 | 3 | import java.util.Scanner; 4 | 5 | public class MathOperations_11 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | int a = Integer.parseInt(scanner.nextLine()); 9 | String operation = scanner.nextLine(); 10 | int b = Integer.parseInt(scanner.nextLine()); 11 | 12 | switch (operation) { 13 | case "/": 14 | divide(a, b); 15 | break; 16 | case "*": 17 | multiply(a, b); 18 | break; 19 | case "+": 20 | add(a, b); 21 | break; 22 | case "-": 23 | subtract(a, b); 24 | break; 25 | } 26 | } 27 | 28 | public static void divide(int a, int b) { 29 | System.out.println(a / b); 30 | } 31 | 32 | public static void multiply(int a, int b) { 33 | System.out.println(a * b); 34 | } 35 | 36 | public static void add(int a, int b) { 37 | System.out.println(a + b); 38 | } 39 | 40 | public static void subtract(int a, int b) { 41 | System.out.println(a - b); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /05. Lists - Exercise/BombNumbers_05.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.List; 3 | import java.util.Scanner; 4 | import java.util.stream.Collectors; 5 | 6 | public class BombNumbers_05 { 7 | 8 | public static void main(String[] args) { 9 | 10 | Scanner scanner = new Scanner(System.in); 11 | 12 | List elements = Arrays.stream(scanner.nextLine().split("\\s+")).collect(Collectors.toList()); 13 | 14 | String[] data = scanner.nextLine().split("\\s+"); 15 | String bombNumber = data[0]; 16 | int power = Integer.parseInt(data[1]); 17 | 18 | while (elements.contains(bombNumber)) { 19 | int elementIndex = elements.indexOf(bombNumber); 20 | 21 | int start = elementIndex - power; 22 | if (start < 0) { 23 | start = 0; 24 | } 25 | 26 | int end = elementIndex + power; 27 | if (end > elements.size() - 1) { 28 | end = elements.size() - 1; 29 | } 30 | 31 | for (int i = end; i >= start; i--) { 32 | elements.remove(i); 33 | } 34 | } 35 | 36 | System.out.println(elements.stream().mapToInt(Integer::parseInt).sum()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /08. Text Processing - Lab/Digits_letters_Others_05.java: -------------------------------------------------------------------------------- 1 | package textProcessing; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Digits_letters_Others_05 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String text = scanner.nextLine(); //"Agd#53Dfg^&4F53" 10 | 11 | //цифри 12 | StringBuilder digits = new StringBuilder(); 13 | //букви 14 | StringBuilder letters = new StringBuilder(); 15 | //други символи 16 | StringBuilder others = new StringBuilder(); 17 | 18 | for (char symbol : text.toCharArray()) { 19 | if (Character.isDigit(symbol)) { 20 | //символът ми е цифра 21 | digits.append(symbol); 22 | } else if (Character.isLetter(symbol)) { 23 | //символът ми е буква 24 | letters.append(symbol); 25 | } else { 26 | //символът ми е друг (различен от буква или цифра) 27 | others.append(symbol); 28 | } 29 | } 30 | 31 | System.out.println(digits); 32 | System.out.println(letters.toString()); 33 | System.out.println(others.toString()); 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /10. RegEx - Exercise/ExtractEmails_05.java: -------------------------------------------------------------------------------- 1 | package RegEx; 2 | 3 | import java.util.Scanner; 4 | import java.util.regex.Matcher; 5 | import java.util.regex.Pattern; 6 | 7 | public class ExtractEmails_05 { 8 | public static void main(String[] args) { 9 | Scanner scanner = new Scanner(System.in); 10 | String text = scanner.nextLine(); 11 | //да намерим валидните имейли 12 | //{user}@{host} 13 | //desislava.topuzakova@softuni.bg 14 | 15 | String regexUser = "[A-Za-z0-9]+[\\.\\-\\_]?[A-Za-z0-9]+"; 16 | String regexHost = "[A-Za-z]+\\-?[A-Za-z]+(\\.[A-Za-z]+\\-?[A-Za-z]+)+"; 17 | String regexEmail = regexUser + "@" + regexHost; //текст на шаблона 18 | Pattern pattern = Pattern.compile(regexEmail); //шаблон 19 | 20 | Matcher matcher = pattern.matcher(text); 21 | //text = "Just send email to s.miller@mit.edu and j.hopking@york.ac.uk for more information." 22 | //matcher -> съвкупност от всички текстове, които ми отговарят на шаблона -> всички валидни имейли 23 | //matcher -> ["s.miller@mit.edu", "j.hopking@york.ac.uk"] 24 | 25 | while (matcher.find()) { 26 | System.out.println(matcher.group()); 27 | } 28 | 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /06. Objects and Classes - Exercise/groomingSalon/Main.java: -------------------------------------------------------------------------------- 1 | package groomingSalon; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | 7 | // Initialize the repository 8 | GroomingSalon salon = new GroomingSalon(20); 9 | 10 | // Initialize entity 11 | Pet dog = new Pet("Ellias", 5, "Tim"); 12 | 13 | // Print Pet 14 | System.out.println(dog); // Ellias 5 - (Tim) 15 | 16 | // Add Pet 17 | salon.add(dog); 18 | 19 | // Remove Pet 20 | System.out.println(salon.remove("Ellias")); // true 21 | System.out.println(salon.remove("Pufa")); // false 22 | 23 | Pet cat = new Pet("Bella", 2, "Mia"); 24 | Pet bunny = new Pet("Zak", 4, "Jon"); 25 | 26 | salon.add(cat); 27 | salon.add(bunny); 28 | 29 | // Get Pet 30 | Pet pet = salon.getPet("Bella", "Mia"); 31 | System.out.println(pet); // Bella 2 - (Mia) 32 | 33 | // Count 34 | System.out.println(salon.getCount()); // 2 35 | 36 | // Get Statistics 37 | System.out.println(salon.getStatistics()); 38 | // The grooming salon has the following clients: 39 | //Bella Mia 40 | //Zak Jon 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /05. Lists - Lab/ListOfProducts_05.java: -------------------------------------------------------------------------------- 1 | package Lists; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | import java.util.Scanner; 7 | 8 | public class ListOfProducts_05 { 9 | public static void main(String[] args) { 10 | Scanner scanner = new Scanner(System.in); 11 | int countProducts = Integer.parseInt(scanner.nextLine()); //брой продуктите 12 | List products = new ArrayList<>(); //списък с продуктите 13 | 14 | for (int count = 1; count <= countProducts; count++) { 15 | String productName = scanner.nextLine(); 16 | products.add(productName); 17 | } 18 | 19 | //products = {"Potatoes", "Tomatoes", "Onions", "Apples"} 20 | //sort -> сортира в ascending order (нарастващ ред) 21 | //списък с числа.sort -> нарастващ ред от най-малкото към най-голямото 22 | //списък с текстове.sort -> нарастващ ред от A към Z 23 | Collections.sort(products); 24 | //products = {"Apples", "Onions", "Potatoes", "Tomato"} 25 | 26 | int number = 1; //пореден номер на продукта 27 | for (String product : products) { 28 | System.out.println(number + "." + product); 29 | number++; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /03. Arrays - Lab/SumEvenNumbers_03.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | public class SumEvenNumbers_03 { 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | //scanner.nextLine() -> "1 2 3 4 5 6" 10 | //scanner.nextLine().split(" ") -> ["1", "2","3", "4", "5", "6"] 11 | //Arrays.stream(scanner.nextLine().split(" ")) -> дава възможност да модифицирам лесно елементите на масив 12 | //mapToInt(Integer::parseInt) -> извършва действието в скобите върху всички елементи -> //[1, 2, 3, 4, 5, 6] 13 | int [] numbers = Arrays.stream(scanner.nextLine() 14 | .split(" ")) 15 | .mapToInt(Integer::parseInt) 16 | .toArray(); 17 | 18 | //numbers = [1, 2, 3, 4, 5, 6] 19 | int sumEven = 0; //сума на четните елементи в масива 20 | //обхождаме с foreach 21 | for (int number : numbers) { 22 | //действие, което повтаряме за всеки елемент 23 | if (number % 2 == 0) { 24 | sumEven += number; 25 | } 26 | } 27 | 28 | //обходили всички елементи 29 | System.out.println(sumEven); 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /02. Data Types and Variables - Exercise/Snowballs_11.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Snowballs_11 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int n = Integer.parseInt(scanner.nextLine()); 10 | 11 | double maxValue = 0; 12 | int snowballSnowBiggest = 0; 13 | int snowballTTimeBiggest = 0; 14 | int snowballQualityBiggest = 0; 15 | 16 | for (int snowBall = 1; snowBall <= n; snowBall++) { 17 | 18 | int snowBallSnow = Integer.parseInt(scanner.nextLine()); 19 | int snowBallTime = Integer.parseInt(scanner.nextLine()); 20 | int snowBallQuality = Integer.parseInt(scanner.nextLine()); 21 | double snowBallValue = Math.pow(snowBallSnow / snowBallTime, snowBallQuality); 22 | 23 | if (snowBallValue > maxValue) { 24 | maxValue = snowBallValue; 25 | snowballSnowBiggest = snowBallSnow; 26 | snowballTTimeBiggest = snowBallTime; 27 | snowballQualityBiggest = snowBallQuality; 28 | } 29 | } 30 | 31 | System.out.printf("%d : %d = %.0f (%d) ", snowballSnowBiggest, snowballTTimeBiggest, maxValue, snowballQualityBiggest); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Exercise/PadawanEquipment_10.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class PadawanEquipment_10 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | double budget = Double.parseDouble(scanner.nextLine()); 10 | int studentsCount = Integer.parseInt(scanner.nextLine()); 11 | double saberPrice = Double.parseDouble(scanner.nextLine()); 12 | double robePrice = Double.parseDouble(scanner.nextLine()); 13 | double beltPrice = Double.parseDouble(scanner.nextLine()); 14 | 15 | //Calculate sabers 16 | double sumSabers = Math.ceil(studentsCount * 1.10) * saberPrice; 17 | //Calculate robes 18 | double sumRobes = studentsCount * robePrice; 19 | //Calculate belts 20 | double sumBelts = (studentsCount - (studentsCount / 6)) * beltPrice; 21 | 22 | // Total Sum 23 | double totalSum = sumSabers + sumRobes + sumBelts; 24 | 25 | if (totalSum <= budget) { 26 | System.out.printf("The money is enough - it would cost %.2flv.", totalSum); 27 | } else { 28 | System.out.printf("George Lucas will need %.2flv more.", Math.abs(totalSum - budget)); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /03. Arrays - Lab/EqualArrays_06.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | import java.util.Scanner; 4 | import java.util.Arrays; 5 | 6 | public class EqualArrays_06 { 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | int[] firstArr = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray(); 11 | int[] secondArr = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray(); 12 | boolean identical = true; 13 | int sum = 0; 14 | int foundPosition = 0; 15 | 16 | for (int position = 0; position <= firstArr.length - 1; position++) { 17 | int firstNum = firstArr[position]; 18 | int secondNum = secondArr[position]; 19 | 20 | if (firstNum == secondNum) { 21 | sum += firstNum; 22 | } else { 23 | foundPosition = position; 24 | identical = false; 25 | break; 26 | } 27 | 28 | } 29 | if (identical) { 30 | System.out.printf("Arrays are identical. Sum: %d", sum); 31 | } else { 32 | System.out.printf("Arrays are not identical. Found difference at %d foundPosition.", foundPosition); 33 | } 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /04. Methods - Exercise/MiddleCharacters_06.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class MiddleCharacters_06 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String text = scanner.nextLine(); 10 | 11 | printMiddleCharacter(text); 12 | } 13 | 14 | public static void printMiddleCharacter(String text) { 15 | 16 | int length = text.length(); 17 | 18 | if (length % 2 != 0) { 19 | //aString -> 'r' -> 3 index 20 | //length 7 21 | //Vik -> 'i' -> 1 index 22 | //length 3 23 | //Carts -> 'r' -> 2 index 24 | //length 5 25 | 26 | int indexOfMiddleChar = length / 2; 27 | System.out.println(text.charAt(indexOfMiddleChar)); 28 | } else { 29 | //Desi -> 'e' -> 1 index ; 's' -> 2 index 30 | //length 4 31 | //Viktor -> 'k' -> 2 index ; 't' -> 3 index 32 | //length 6 33 | 34 | int indexOfFirstMiddleChar = length / 2 - 1; 35 | int indexOfSecondMiddleChar = length / 2; 36 | System.out.print(text.charAt(indexOfFirstMiddleChar)); 37 | System.out.print(text.charAt(indexOfSecondMiddleChar)); 38 | } 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /08. Text Processing - Lab/Demo/DemoStringBuilder.java: -------------------------------------------------------------------------------- 1 | package textProcessing; 2 | 3 | public class DemoStringBuilder { 4 | public static void main(String[] args) { 5 | 6 | //STRING BUILDER 7 | StringBuilder sb = new StringBuilder(); //празен string builder 8 | //1. лесно се модифицира текста 9 | //2. бърз 10 | sb.append("Hello, "); 11 | sb.append("John! "); 12 | sb.append("I sent you an email."); 13 | System.out.println(sb.toString()); 14 | 15 | StringBuilder sbName = new StringBuilder("Desi"); 16 | //добавям текст 17 | sbName.append(" Topuzakova"); 18 | //взимам текста 19 | System.out.println(sbName.toString()); 20 | //изтривам елементи от текст 21 | sbName.delete(3, 9); 22 | //обръщане на текст 23 | String fullName = "Desislava Topuzakova"; 24 | StringBuilder fullNameBuilder = new StringBuilder(fullName); 25 | fullNameBuilder.reverse(); 26 | System.out.println(fullNameBuilder); 27 | 28 | 29 | System.out.println(sb.length()); //дължината на текста в StringBuilder-a 30 | 31 | //вмъкване в текст 32 | sb.insert(0, "Ivan"); 33 | 34 | //достъпване на символ в текста в StringBuilder 35 | System.out.println(sb.charAt(0)); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /regex-cheatsheet.txt: -------------------------------------------------------------------------------- 1 | Regular Expressions - cheat sheet 2 | 3 | Основен синтаксис: 4 | [A-Z] - една главна буква (аски код от 65 до 90) 5 | [a-z] - една малка буква (аски код от 97 до 120) 6 | [0-9] - една цифра [0-9] (аски код от 48 до 57) 7 | [A-Za-z] - една буква, която или е малка, или е голяма 8 | [aeiou] - всички гласни букви 9 | [^aeiou] - всички съгласни букви 10 | \w - един символ, който може да е малка буква, главна буква, цифра или _ 11 | \W - един символ, различен от малка буква, главна буква, цифра или _ 12 | \s - един интервал 13 | \S - един символ, различен от интервал 14 | \d - една цифра [0-9] (аски код от 48 до 57) 15 | \D - един символ, различен от цифра 16 | 17 | Брой на срещанията: 18 | * -> срещания 0 или безброй много пъти 19 | + -> срещания 1 или безброй много пъти 20 | ? -> срещания 0 или 1 пъти 21 | {число} -> срещания {число} пъти 22 | {число, } -> минимум колко пъти 23 | {число1, число2} -> минимум се среща число1 пъти, максимум се среща число2 брой пъти 24 | () -> обособяваме група 25 | (? шаблон) -> обособяваме група с име 26 | 27 | Използване в Java: 28 | String text = scanner.nextLine(); 29 | String regex = "\\b[A-Z][a-z]+ [A-Z][a-z]+\\b"; //текст на шаблона 30 | Pattern pattern = Pattern.compile(regex); // шаблон 31 | Matcher matcher = pattern.matcher(text); //текстовете от променливата text, които отговарят на шаблона -------------------------------------------------------------------------------- /08. Text Processing - Exercise/LettersChangeNumbers_08.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class LettersChangeNumbers_08 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String[] codes = scanner.nextLine().split("\\s+"); 10 | 11 | double sum = 0; 12 | 13 | for (String code : codes) { 14 | double result = calculateCodeResult(code); 15 | sum += result; 16 | } 17 | 18 | System.out.printf("%.2f", sum); 19 | } 20 | 21 | private static double calculateCodeResult(String code) { 22 | 23 | //"A12b" 24 | char letterBefore = code.charAt(0); 25 | double number = Double.parseDouble(code.substring(1, code.length() - 1)); 26 | char letterAfter = code.charAt(code.length() - 1); 27 | 28 | // 1. Letter Before Manipulation 29 | if (Character.isUpperCase(letterBefore)) { 30 | number /= letterBefore - 64; 31 | } else { 32 | number *= letterBefore - 96; 33 | } 34 | 35 | // 2. Letter After Manipulation 36 | if (Character.isUpperCase(letterAfter)) { 37 | number -= letterAfter - 64; 38 | } else { 39 | number += letterAfter - 96; 40 | } 41 | 42 | return number; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /04. Methods - Exercise/TopNumber_10.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class TopNumber_10 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int n = Integer.parseInt(scanner.nextLine()); 10 | 11 | for (int number = 1; number <= n; number++) { 12 | 13 | boolean isValidSumDigits = isSumOfDigitsDivisibleByEight(number); 14 | boolean doesContainsOddDigit = doesNumberContainsOneOddDigit(number); 15 | 16 | if (isValidSumDigits && doesContainsOddDigit) { 17 | System.out.println(number); 18 | } 19 | } 20 | } 21 | 22 | public static boolean isSumOfDigitsDivisibleByEight(int number) { 23 | 24 | int sumOfDigits = 0; 25 | while (number > 0) { 26 | int lastDigit = number % 10; 27 | sumOfDigits += lastDigit; 28 | number /= 10; 29 | } 30 | 31 | return sumOfDigits % 8 == 0; 32 | } 33 | 34 | public static boolean doesNumberContainsOneOddDigit(int number) { 35 | 36 | while (number > 0) { 37 | int lastDigit = number % 10; 38 | if (lastDigit % 2 != 0) { 39 | return true; 40 | } 41 | number /= 10; 42 | } 43 | 44 | return false; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /06. Objects and Classes - Exercise/articles_02/Main.java: -------------------------------------------------------------------------------- 1 | package articles_02; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner scanner = new Scanner(System.in); 10 | 11 | //"some title, some content, some author" 12 | String input = scanner.nextLine(); 13 | String title = input.split(", ")[0]; 14 | String content = input.split(", ")[1]; 15 | String author = input.split(", ")[2]; 16 | 17 | Article article = new Article(title, content, author); 18 | 19 | int n = Integer.parseInt(scanner.nextLine()); 20 | for (int i = 1; i <= n; i++) { 21 | 22 | String row = scanner.nextLine(); 23 | String commandName = row.split(": ")[0]; 24 | String newValue = row.split(": ")[1]; 25 | 26 | switch (commandName) { 27 | case "Edit": 28 | article.edit(newValue); 29 | break; 30 | case "ChangeAuthor": 31 | article.changeAuthor(newValue); 32 | break; 33 | case "Rename": 34 | article.rename(newValue); 35 | break; 36 | } 37 | } 38 | 39 | System.out.println(article.toString()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /02. Data Types and Variables - Exercise/BeerKegs_08.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class BeerKegs_08 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int kegsCount = Integer.parseInt(scanner.nextLine()); 10 | 11 | // 1. Обходим всички кегове 12 | // - Изчисляваме обема на кега 13 | // - Проверяваме дали сме намерили по-голям кег от досегашният най-голям 14 | 15 | String maxModel = ""; 16 | double maxVolume = 0; 17 | 18 | for (int keg = 1; keg <= kegsCount; keg++) { 19 | 20 | // Информация за текущият кег: 21 | String model = scanner.nextLine(); 22 | double radius = Double.parseDouble(scanner.nextLine()); 23 | int height = Integer.parseInt(scanner.nextLine()); 24 | 25 | //Формула: π * r^2 * h 26 | double volume = Math.PI * radius * radius * height; 27 | //double volume2 = Math.PI * Math.pow(radius, 2) * height; 28 | 29 | // Проверяваме дали сме намерили по-голям кег 30 | if (volume > maxVolume) { 31 | maxModel = model; 32 | maxVolume = volume; 33 | } 34 | } 35 | 36 | // 2. Принтираме модела на най-големият кег 37 | System.out.println(maxModel); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /07. Maps, Lambda, Stream API - Lab/Demo/Demo_Lambda_StreamAPI.java: -------------------------------------------------------------------------------- 1 | package maps; 2 | 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | public class Demo_Lambda_StreamAPI { 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | String [] input = scanner.nextLine().split(" "); // ["1", "3", "2", "8", "6"] 10 | int [] numbers = Arrays.stream(input) 11 | .mapToInt(e -> Integer.parseInt(e)) 12 | .toArray(); 13 | //API - Application Program Interface 14 | //Stream API - съвкупоност от методи върху структури данни 15 | 16 | //2 вида stream / поточна линия / поток 17 | //1. Primitive -> IntStream, DoubleStream -> sum, average, min, max 18 | //2. Stream -> Stream, Stream 19 | 20 | //Stream -> mapToInt, mapToDouble -> Primitive 21 | 22 | int min = Arrays.stream(numbers) 23 | .min() 24 | .orElse(23); 25 | 26 | int[] nums = Arrays.stream(scanner.nextLine().split(" ")) 27 | .mapToInt(e -> Integer.parseInt(e)) 28 | .filter(n -> n > 0) 29 | .toArray(); 30 | 31 | 32 | } 33 | 34 | public static int convertToInt(String text) { 35 | return Integer.parseInt(text); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /07. Maps, Lambda, Stream API - Lab/WordSynonyms_02.java: -------------------------------------------------------------------------------- 1 | package maps; 2 | 3 | import java.util.*; 4 | 5 | public class WordSynonyms_02 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | int wordsCount = Integer.parseInt(scanner.nextLine()); //брой на думи за обработка 9 | 10 | //дума (String) -> списък със синоними (List) 11 | Map> wordSynonimsMap = new LinkedHashMap<>(); 12 | 13 | for (int count = 1; count <= wordsCount; count++) { 14 | String word = scanner.nextLine(); 15 | String synonym = scanner.nextLine(); 16 | 17 | //1. думата да не сме я срещали 18 | wordSynonimsMap.putIfAbsent(word, new ArrayList<>()); 19 | //думата я има 20 | wordSynonimsMap.get(word).add(synonym); 21 | } 22 | 23 | //запис / двойка / pair: key (String word) -> value (List synonyms) 24 | for (Map.Entry> pair : wordSynonimsMap.entrySet()) { 25 | //всеки един запис се съхранява pair 26 | //pair: key (String) value (List) 27 | String word = pair.getKey(); 28 | List synonyms = pair.getValue(); 29 | System.out.println(word + " - " + String.join(", ", synonyms)); 30 | } 31 | 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /06. Objects and Classes - Exercise/advertisement_message_01/Message.java: -------------------------------------------------------------------------------- 1 | package advertisement_message_01; 2 | 3 | import java.util.Random; 4 | 5 | public class Message { 6 | 7 | private Random random = new Random(); 8 | 9 | private String[] phrases = { 10 | "Excellent product.", 11 | "Such a great product.", 12 | "I always use that product.", 13 | "Best product of its category.", 14 | "Exceptional product.", 15 | "I can’t live without this product." 16 | }; 17 | private String[] events = { 18 | "Now I feel good.", 19 | "I have succeeded with this product.", 20 | "Makes miracles. I am happy of the results!", 21 | "I cannot believe but now I feel awesome.", 22 | "Try it yourself, I am very satisfied.", 23 | "I feel great!" 24 | }; 25 | private String[] author = {"Diana", "Petya", "Stella", "Elena", "Katya", "Iva", "Annie", "Eva"}; 26 | private String[] town = {"Burgas", "Sofia", "Plovdiv", "Varna", "Ruse"}; 27 | 28 | public String randomMessage() { 29 | 30 | return String.format("%s %s %s - %s", 31 | phrases[random.nextInt(phrases.length)], 32 | events[random.nextInt(events.length)], 33 | author[random.nextInt(author.length)], 34 | town[random.nextInt(town.length)]); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /03. Arrays - Exercise/TheLift_10.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class TheLift_10 { 5 | 6 | public static void main(String[] args) { 7 | 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | int waitingPeople = Integer.parseInt(scanner.nextLine()); 11 | int[] wagons = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray(); 12 | 13 | boolean isLiftFull = true; 14 | 15 | for (int position = 0; position < wagons.length; position++) { 16 | 17 | int availableSpace = 4 - wagons[position]; 18 | 19 | if (availableSpace > 0) { 20 | if (availableSpace > waitingPeople) { 21 | wagons[position] += waitingPeople; 22 | waitingPeople = 0; 23 | isLiftFull = false; 24 | 25 | } else { 26 | wagons[position] = 4; 27 | waitingPeople -= availableSpace; 28 | } 29 | } 30 | } 31 | 32 | if (!isLiftFull) { 33 | System.out.println("The lift has empty spots!"); 34 | } else if (waitingPeople > 0) { 35 | System.out.printf("There isn't enough space! %d people in a queue!\n", waitingPeople); 36 | } 37 | 38 | for (int wagon : wagons) { 39 | System.out.print(wagon + " "); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /03. Arrays - Exercise/EqualSums_06.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class EqualSums_06 { 5 | 6 | public static void main(String[] args) { 7 | 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | int[] numbers = Arrays.stream(scanner.nextLine().split(" ")) 11 | .mapToInt(Integer::parseInt) 12 | .toArray(); 13 | 14 | // 1. Вземаме всяко едно число от масива 15 | for (int position = 0; position <= numbers.length - 1; position++) { 16 | 17 | int currentNumber = numbers[position]; 18 | 19 | // 2 - проверяваме дали сумата на числата в ляво е равна на сумата на числата в дясно 20 | int leftSum = 0; 21 | int rightSum = 0; 22 | 23 | // Обхождам всички числа в ляво: 24 | for (int leftPosition = 0; leftPosition < position; leftPosition++) { 25 | leftSum += numbers[leftPosition]; 26 | } 27 | 28 | // Обхождам всички числа в дясно: 29 | for (int rightPosition = position + 1; rightPosition <= numbers.length - 1; rightPosition++) { 30 | rightSum += numbers[rightPosition]; 31 | } 32 | 33 | if (leftSum == rightSum) { 34 | System.out.println(position); 35 | return; 36 | } 37 | } 38 | 39 | System.out.println("no"); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Final Exam Preparation - Part 1/DestinationMapper_02.java: -------------------------------------------------------------------------------- 1 | package ExamPrep; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Scanner; 6 | import java.util.regex.Matcher; 7 | import java.util.regex.Pattern; 8 | 9 | public class DestinationMapper_02 { 10 | public static void main(String[] args) { 11 | Scanner scanner = new Scanner(System.in); 12 | String allDestinations = scanner.nextLine(); 13 | //"=Hawai=/Cyprus/=Invalid/invalid==i5valid=/I5valid/=i=" 14 | 15 | String regex = "([=\\/])(?[A-Z][A-Za-z]{2,})\\1"; //текст на шаблона 16 | Pattern pattern = Pattern.compile(regex); //шаблон 17 | Matcher matcher = pattern.matcher(allDestinations); 18 | //съвкупност от текстовете, които ми отговарят на шаблона -> валидни дестинации 19 | //matcher = ["=Hawai=", "/Cyprus/"] 20 | 21 | List validDestinations = new ArrayList<>(); 22 | while (matcher.find()) { 23 | //matcher.group -> "=Hawai=" 24 | validDestinations.add(matcher.group("destination")); 25 | } 26 | System.out.println("Destinations: " + String.join(", ", validDestinations)); 27 | 28 | int travelPoints = 0; 29 | for (String destination : validDestinations) { 30 | travelPoints += destination.length(); 31 | } 32 | System.out.println("Travel Points: " + travelPoints); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Exercise/RageExpense_11.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class RageExpense_11 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int countLoseGames = Integer.parseInt(scanner.nextLine()); 10 | double headsetPrice = Double.parseDouble(scanner.nextLine()); 11 | double mousePrice = Double.parseDouble(scanner.nextLine()); 12 | double keyboardPrice = Double.parseDouble(scanner.nextLine()); 13 | double displayPrice = Double.parseDouble(scanner.nextLine()); 14 | 15 | int headsetCount = 0; 16 | int mouseCount = 0; 17 | int keyboardCount = 0; 18 | int displayCount = 0; 19 | 20 | for (int game = 1; game <= countLoseGames; game++) { 21 | if (game % 2 == 0) { 22 | headsetCount++; 23 | } 24 | if (game % 3 == 0) { 25 | mouseCount++; 26 | } 27 | if (game % 6 == 0) { 28 | keyboardCount++; 29 | } 30 | if (game % 12 == 0) { 31 | displayCount++; 32 | } 33 | } 34 | 35 | double totalPrice = (headsetCount * headsetPrice) + (mouseCount * mousePrice) + (keyboardCount * keyboardPrice) + (displayCount * displayPrice); 36 | System.out.printf("Rage expenses: %.2f lv.", totalPrice); 37 | } 38 | } -------------------------------------------------------------------------------- /06. Objects and Classes - Lab/stundents2/Student.java: -------------------------------------------------------------------------------- 1 | package stundents2; 2 | 3 | public class Student { 4 | //характеристики: first name, last name, age and hometown 5 | //fields 6 | private String firstName; 7 | private String lastName; 8 | private int age; 9 | private String hometown; 10 | 11 | //конструктор -> създаваме обекти от класа 12 | public Student(String firstName, String lastName, int age, String hometown) { 13 | //нов празен обект 14 | this.firstName = firstName; 15 | this.lastName = lastName; 16 | this.age = age; 17 | this.hometown = hometown; 18 | } 19 | 20 | //методи -> действията, които ще може да прави всеки един студент 21 | //getters and setters 22 | public String getFirstName() { 23 | return firstName; 24 | } 25 | 26 | public String getLastName() { 27 | return lastName; 28 | } 29 | 30 | public int getAge() { 31 | return age; 32 | } 33 | 34 | public String getHometown() { 35 | return hometown; 36 | } 37 | 38 | public void setFirstName(String firstName) { 39 | this.firstName = firstName; 40 | } 41 | 42 | public void setLastName(String lastName) { 43 | this.lastName = lastName; 44 | } 45 | 46 | public void setAge(int age) { 47 | this.age = age; 48 | } 49 | 50 | public void setHometown(String hometown) { 51 | this.hometown = hometown; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Final Exam Preparation - Part 2/FancyBarcodes_02.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.regex.Matcher; 3 | import java.util.regex.Pattern; 4 | 5 | public class FancyBarcodes_02 { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner scanner = new Scanner(System.in); 10 | 11 | int n = Integer.parseInt(scanner.nextLine()); 12 | 13 | String regex = "@#+[A-Z][A-Za-z0-9]{4,}[A-Z]@#+"; 14 | Pattern pattern = Pattern.compile(regex); 15 | 16 | for (int i = 0; i < n; i++) { 17 | 18 | //@#FreshFisH@# 19 | String barcode = scanner.nextLine(); 20 | Matcher matcher = pattern.matcher(barcode); 21 | 22 | if (matcher.find()) { 23 | 24 | StringBuilder productGroup = new StringBuilder(); 25 | for (char symbol : barcode.toCharArray()) { 26 | if (Character.isDigit(symbol)) { 27 | productGroup.append(symbol); 28 | } 29 | } 30 | 31 | // НЕ ИЗПОЛЗВАЙТЕ .isEmpty() -> compile-time error in Judge! 32 | if (productGroup.length() == 0) { 33 | System.out.println("Product group: 00"); 34 | } else { 35 | System.out.println("Product group: " + productGroup); 36 | } 37 | } else { 38 | System.out.println("Invalid barcode"); 39 | } 40 | } 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /06. Objects and Classes - Lab/students/Main.java: -------------------------------------------------------------------------------- 1 | package students; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Scanner; 6 | 7 | public class Main { 8 | public static void main(String[] args) { 9 | Scanner scanner = new Scanner(System.in); 10 | List studentList = new ArrayList<>(); //списък с въведени студенти 11 | 12 | String input = scanner.nextLine(); 13 | 14 | while (!input.equals("end")) { 15 | //input = "John Smith 15 Sofia" 16 | String[] data = input.split(" "); 17 | //input.split(" ") -> ["John", "Smith", "15", "Sofia"] 18 | String firstName = data[0]; //първото име 19 | String lastName = data[1]; //фамилното име 20 | int age = Integer.parseInt(data[2]); 21 | String hometown = data[3]; 22 | 23 | //СТУДЕНТ 24 | Student student = new Student(firstName, lastName, age, hometown); 25 | 26 | //добавяме в списъка с всички студенти 27 | studentList.add(student); 28 | 29 | input = scanner.nextLine(); 30 | } 31 | 32 | //ПЪЛЕН СПИСЪК ОТ ВЪВЕДЕНИ СТУДЕНТИ -> studentList 33 | String enteredTown = scanner.nextLine(); 34 | 35 | for (Student student : studentList) { 36 | if (student.getHometown().equals(enteredTown)) { 37 | System.out.printf("%s %s is %d years old%n", student.getFirstName(), student.getLastName(), student.getAge()); 38 | } 39 | } 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /03. Arrays - Exercise/ZigZagArrays_03.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ZigZagArrays_03 { 4 | 5 | public static void main(String[] args) { 6 | 7 | 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | int n = Integer.parseInt(scanner.nextLine()); 11 | 12 | String[] firstArray = new String[n]; 13 | String[] secondArray = new String[n]; 14 | 15 | int position = 0; 16 | 17 | for (int row = 1; row <= n; row++) { 18 | 19 | String textRow = scanner.nextLine(); 20 | String[] currentRowElements = textRow.split(" "); 21 | 22 | String firstElement = currentRowElements[0]; 23 | String secondElement = currentRowElements[1]; 24 | 25 | if (row % 2 != 0) { 26 | // първият елемент -> първият масив 27 | // вторият елемент -> вторият масив 28 | firstArray[position] = firstElement; 29 | secondArray[position] = secondElement; 30 | } else { 31 | // първият елемент -> вторият масив 32 | // вторият елемент -> първият масив 33 | firstArray[position] = secondElement; 34 | secondArray[position] = firstElement; 35 | } 36 | 37 | position++; 38 | } 39 | 40 | for (String el : firstArray) { 41 | System.out.print(el + " "); 42 | } 43 | System.out.println(); 44 | for (String el : secondArray) { 45 | System.out.print(el + " "); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /06. Objects and Classes - Exercise/groomingSalon/GroomingSalon.java: -------------------------------------------------------------------------------- 1 | package groomingSalon; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class GroomingSalon { 7 | 8 | // 1. Fields 9 | private List data; 10 | private int capacity; 11 | 12 | // 2. Constructor 13 | public GroomingSalon(int capacity) { 14 | this.capacity = capacity; 15 | this.data = new ArrayList<>(); 16 | } 17 | 18 | // 3. Methods 19 | public void add(Pet pet) { 20 | if (this.data.size() < capacity) { 21 | this.data.add(pet); 22 | } 23 | } 24 | 25 | public boolean remove(String name) { 26 | for (Pet pet : this.data) { 27 | if (pet.getName().equals(name)) { 28 | this.data.remove(pet); 29 | return true; 30 | } 31 | } 32 | return false; 33 | } 34 | 35 | public Pet getPet(String name, String owner) { 36 | for (Pet pet : this.data) { 37 | if (pet.getName().equals(name) && pet.getOwner().equals(owner)) { 38 | return pet; 39 | } 40 | } 41 | return null; 42 | } 43 | 44 | public int getCount() { 45 | return this.data.size(); 46 | } 47 | 48 | public String getStatistics() { 49 | String statistics = "The grooming salon has the following clients:\n"; 50 | for (Pet pet : this.data) { 51 | statistics += String.format("%s %s\n", pet.getName(), pet.getOwner()); 52 | } 53 | return statistics; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /06. Objects and Classes - Exercise/vehicle_catalogue_05/Vehicle.java: -------------------------------------------------------------------------------- 1 | package vehicle_catalogue_05; 2 | 3 | public class Vehicle { 4 | 5 | // 1. Fields 6 | private String type; 7 | private String model; 8 | private String color; 9 | private int horsePower; 10 | 11 | // 2. Constructor 12 | public Vehicle(String type, String model, String color, int horsePower) { 13 | this.type = type; 14 | this.model = model; 15 | this.color = color; 16 | this.horsePower = horsePower; 17 | } 18 | 19 | // 3. Methods 20 | public String getType() { 21 | return type; 22 | } 23 | 24 | public String getModel() { 25 | return model; 26 | } 27 | 28 | public String getColor() { 29 | return color; 30 | } 31 | 32 | public int getHorsePower() { 33 | return horsePower; 34 | } 35 | 36 | public void setModel(String model) { 37 | this.model = model; 38 | } 39 | 40 | public void setColor(String color) { 41 | this.color = color; 42 | } 43 | 44 | public void setHorsePower(int horsePower) { 45 | this.horsePower = horsePower; 46 | } 47 | 48 | public void setType(String type) { 49 | this.type = type; 50 | } 51 | 52 | public String toString() { 53 | 54 | String vehicleType = type.equals("car") ? "Car" : "Truck"; 55 | return "Type: " + vehicleType + "\n" + 56 | "Model: " + model + "\n" + 57 | "Color: " + color + "\n" + 58 | "Horsepower: " + horsePower; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Lab/TheatrePromotions_07.java: -------------------------------------------------------------------------------- 1 | package BasicsOverview; 2 | 3 | import java.util.Scanner; 4 | 5 | public class TheatrePromotions_07 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | String day = scanner.nextLine(); 9 | int age = Integer.parseInt(scanner.nextLine()); 10 | 11 | int price = 0; 12 | 13 | if (day.equals("Weekday")) { 14 | if ((age >= 0 && age <= 18) || (age > 64 && age <= 122)) { 15 | price = 12; 16 | } else if (age > 18 && age <= 64) { 17 | price = 18; 18 | } else { 19 | System.out.println("Error!"); 20 | } 21 | } else if (day.equals("Weekend")) { 22 | if ((age >= 0 && age <= 18) || (age > 64 && age <= 122)) { 23 | price = 15; 24 | } else if (age > 18 && age <= 64) { 25 | price = 20; 26 | } else { 27 | System.out.println("Error!"); 28 | } 29 | } else if (day.equals("Holiday")) { 30 | if ((age >= 0 && age <= 18)) { 31 | price = 5; 32 | } else if (age > 18 && age <= 64) { 33 | price = 12; 34 | } else if (age > 64 && age <= 122) { 35 | price = 10; 36 | } else { 37 | System.out.println("Error!"); 38 | } 39 | } 40 | 41 | if (price != 0) { 42 | System.out.printf("%d$", price); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /05. Lists - Exercise/ChangeList_02.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.List; 3 | import java.util.Scanner; 4 | import java.util.stream.Collectors; 5 | 6 | public class ChangeList_02 { 7 | 8 | public static void main(String[] args) { 9 | 10 | Scanner scanner = new Scanner(System.in); 11 | 12 | List numbers = Arrays.stream(scanner.nextLine().split(" ")) 13 | .map(Integer::parseInt) 14 | .collect(Collectors.toList()); 15 | 16 | //"Delete {element}" - delete all elements in the array which are equal to the given element 17 | //"Insert {element} {position}" - insert element at the given position 18 | 19 | String command = scanner.nextLine(); 20 | while (!command.equals("end")) { 21 | 22 | if (command.contains("Delete")) { 23 | // 1. "Delete {element}".split(" ") -> ["Delete", "45"] 24 | int element = Integer.parseInt(command.split(" ")[1]); 25 | numbers.removeAll(List.of(element)); 26 | } else if (command.contains("Insert")) { 27 | // 2. "Insert {element} {position}".split(" ") -> ["Insert", "29", "2"] 28 | int element = Integer.parseInt(command.split(" ")[1]); 29 | int position = Integer.parseInt(command.split(" ")[2]); 30 | numbers.add(position, element); 31 | } 32 | 33 | command = scanner.nextLine(); 34 | } 35 | 36 | for (Integer number : numbers) { 37 | System.out.print(number + " "); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /07. Associative Arrays - Exercise/Orders_03.java: -------------------------------------------------------------------------------- 1 | import java.util.LinkedHashMap; 2 | import java.util.Map; 3 | import java.util.Scanner; 4 | 5 | public class Orders_03 { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner scanner = new Scanner(System.in); 10 | 11 | Map productsQuantity = new LinkedHashMap<>(); 12 | Map productsPrice = new LinkedHashMap<>(); 13 | 14 | String input = scanner.nextLine(); 15 | while (!input.equals("buy")) { 16 | 17 | //Beer 2.20 100 18 | String productName = input.split(" ")[0]; 19 | double price = Double.parseDouble(input.split(" ")[1]); 20 | int quantity = Integer.parseInt(input.split(" ")[2]); 21 | 22 | if (productsQuantity.containsKey(productName)) { 23 | int existingQuantity = productsQuantity.get(productName); 24 | productsQuantity.put(productName, existingQuantity + quantity); 25 | } else { 26 | productsQuantity.put(productName, quantity); 27 | } 28 | 29 | productsPrice.put(productName, price); 30 | 31 | input = scanner.nextLine(); 32 | } 33 | 34 | for (Map.Entry entry : productsQuantity.entrySet()) { 35 | 36 | String productName = entry.getKey(); 37 | int productQuantity = entry.getValue(); 38 | double productPrice = productsPrice.get(productName); 39 | 40 | System.out.printf("%s -> %.2f\n", productName, productQuantity * productPrice); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /07. Associative Arrays - Exercise/StudentAcademy_06.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class StudentAcademy_06 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int countStudents = Integer.parseInt(scanner.nextLine()); 10 | 11 | Map> studentGrades = new LinkedHashMap<>(); 12 | 13 | for (int i = 0; i < countStudents; i++) { 14 | 15 | String studentName = scanner.nextLine(); 16 | double grade = Double.parseDouble(scanner.nextLine()); 17 | 18 | if (studentGrades.containsKey(studentName)) { 19 | studentGrades.get(studentName).add(grade); 20 | } else { 21 | studentGrades.put(studentName, new ArrayList<>()); 22 | studentGrades.get(studentName).add(grade); 23 | } 24 | } 25 | 26 | for (Map.Entry> entry : studentGrades.entrySet()) { 27 | 28 | String studentName = entry.getKey(); 29 | List grades = entry.getValue(); 30 | 31 | // Option 1 32 | double sum = grades.stream().mapToDouble(Double::doubleValue).sum(); 33 | 34 | // Option 2 35 | // double sum = 0; 36 | // for (Double grade : grades) { 37 | // sum += grade; 38 | // } 39 | double averageGrade = sum / grades.size(); 40 | if (averageGrade >= 4.50){ 41 | System.out.printf("%s -> %.2f\n", studentName, averageGrade); 42 | } 43 | } 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /06. Objects and Classes - Lab/demo/Car.java: -------------------------------------------------------------------------------- 1 | package demo; 2 | 3 | public class Car { 4 | //характеристики - конски сили, марка, цвят - полета (fields) 5 | //private - достъпваме само в рамките на класа 6 | //public - достъпвам навсякъде в класовете в проекта 7 | public int hp; 8 | public String brand; 9 | public String color; 10 | 11 | //конструктори - public методи, чрез които създаваме обекти от класа 12 | //1. default constructor -> създава празен обект от класа 13 | //2. custom constructor -> създава обект, на който мога да задам стойности на полетата 14 | public Car (int hp, String brand, String color) { 15 | //празен обект 16 | //hp = 0 17 | //brand = null 18 | //color = null 19 | this.hp = hp; 20 | this.brand = brand; 21 | this.color = color; 22 | } 23 | 24 | //действия - drive, test drive, maintenance - методи 25 | 26 | //getters and setters - методи, които осигуряват достъп до полето 27 | public int getHp () { 28 | //връща стойността на полето hp 29 | return hp; 30 | } 31 | public void setHp (int hp) { 32 | //зададе стойност на полето hp 33 | this.hp = hp; 34 | } 35 | 36 | public String getBrand() { 37 | return brand; 38 | } 39 | 40 | public void setBrand(String brand) { 41 | this.brand = brand; 42 | } 43 | 44 | public String getColor() { 45 | return color; 46 | } 47 | 48 | public void setColor(String color) { 49 | this.color = color; 50 | } 51 | 52 | public static void print() { 53 | //методи, които са за класа 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /05. Lists - Lab/MergingLists_03.java: -------------------------------------------------------------------------------- 1 | package Lists; 2 | import java.util.ArrayList; 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.Scanner; 6 | import java.util.stream.Collectors; 7 | public class MergingLists_03 { 8 | public static void main(String[] args) { 9 | Scanner scanner = new Scanner(System.in); 10 | 11 | List firstList = Arrays 12 | .stream(scanner.nextLine().split(" ")) 13 | .map(Integer::parseInt) 14 | .collect(Collectors.toList()); 15 | 16 | List secondList = Arrays 17 | .stream(scanner.nextLine().split(" ")) 18 | .map(Integer::parseInt) 19 | .collect(Collectors.toList()); 20 | 21 | List resultList = new ArrayList<>(); 22 | int minSize = Math.min(firstList.size(), secondList.size()); 23 | for (int i = 0; i < minSize; i++) { 24 | int numFirstList = firstList.get(i); 25 | int numSecondList = secondList.get(i); 26 | 27 | resultList.add(numFirstList); 28 | resultList.add(numSecondList); 29 | } 30 | 31 | if (firstList.size() > secondList.size()) { 32 | List subList = firstList.subList(minSize, firstList.size()); 33 | 34 | resultList.addAll(subList); 35 | } else if (secondList.size() > firstList.size()) { 36 | List subList = secondList.subList(minSize, secondList.size()); 37 | 38 | resultList.addAll(subList); 39 | } 40 | 41 | System.out.println(resultList.toString().replaceAll("[\\[\\],]", "")); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /08. Text Processing - Exercise/CharacterMultiplier_02.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class CharacterMultiplier_02 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String input = scanner.nextLine(); 10 | 11 | String firstText = input.split("\\s+")[0]; 12 | String secondText = input.split("\\s+")[1]; 13 | 14 | int minLength = Math.min(firstText.length(), secondText.length()); 15 | int maxLength = Math.max(firstText.length(), secondText.length()); 16 | 17 | int sum = 0; 18 | for (int index = 0; index < minLength; index++) { 19 | sum += (firstText.charAt(index) * secondText.charAt(index)); 20 | } 21 | 22 | if (maxLength == minLength) { 23 | System.out.println(sum); 24 | return; 25 | } else { 26 | sum += getRemainingSymbolSum(firstText, secondText, minLength, maxLength); 27 | } 28 | 29 | System.out.println(sum); 30 | } 31 | 32 | private static int getRemainingSymbolSum(String firstText, String secondText, int minLength, int maxLength) { 33 | 34 | int remainingSum = 0; 35 | 36 | if (maxLength == firstText.length()) { 37 | for (int index = minLength; index < firstText.length(); index++) { 38 | remainingSum += firstText.charAt(index); 39 | } 40 | } else { 41 | for (int index = minLength; index < secondText.length(); index++) { 42 | remainingSum += secondText.charAt(index); 43 | } 44 | } 45 | return remainingSum; 46 | } 47 | } -------------------------------------------------------------------------------- /07. Maps, Lambda, Stream API - Lab/CountRealNumbers_01.java: -------------------------------------------------------------------------------- 1 | package maps; 2 | 3 | import java.util.*; 4 | 5 | public class CountRealNumbers_01 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | double [] numbers = Arrays.stream(scanner.nextLine().split(" ")) 10 | .mapToDouble(Double::parseDouble).toArray(); 11 | //numbers = [8, 2, 2, 8, 2] 12 | 13 | //запис / двойка (pair): число -> бр. срещанията 14 | Map numbersCountMap = new TreeMap<>(); 15 | 16 | for (double number : numbers) { 17 | //1. не сме го срещали до момента -> нямаме го записано 18 | if (!numbersCountMap.containsKey(number)) { 19 | //първото срещане на числото 20 | numbersCountMap.put(number, 1); 21 | } 22 | //2. вече да сме го срещали -> има го записано 23 | else { 24 | int currentCount = numbersCountMap.get(number);//текущия брой на срещанията 25 | numbersCountMap.put(number, currentCount + 1); 26 | } 27 | } 28 | 29 | //принтиране на записите в map 30 | //numbersCountMap: 31 | //2 -> 3 32 | //8 -> 2 33 | //запис: key(число) -> value(бр. срещанията) 34 | 35 | for (Map.Entry pair : numbersCountMap.entrySet()) { 36 | //всеки един запис е съхранен в pair 37 | //pair: key (число) value (бр. срещания) 38 | System.out.printf("%.0f -> %d%n", pair.getKey(), pair.getValue()); 39 | } 40 | 41 | 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /05. Lists - Exercise/Train_01.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.List; 3 | import java.util.Scanner; 4 | import java.util.stream.Collectors; 5 | 6 | public class Train_01 { 7 | 8 | public static void main(String[] args) { 9 | 10 | Scanner scanner = new Scanner(System.in); 11 | 12 | List wagons = Arrays.stream(scanner.nextLine().split(" ")) 13 | .map(Integer::parseInt) 14 | .collect(Collectors.toList()); 15 | //.toList(); // НЯМА ДА МОЖЕ ДА МАНИПУЛИРАМЕ ТОЗИ СПИСЪК, АКО ИЗПОЛЗВАМЕ ТОЗИ МЕТОД! 16 | 17 | int maxCapacity = Integer.parseInt(scanner.nextLine()); 18 | 19 | String command = scanner.nextLine(); 20 | while (!command.equals("end")) { 21 | 22 | if (command.contains("Add")) { 23 | // 1. "Add 40".split(" ") -> ["Add", "40"] 24 | int count = Integer.parseInt(command.split(" ")[1]); 25 | wagons.add(count); 26 | } else { 27 | // 2. "40" 28 | int passengersToBeAdded = Integer.parseInt(command); 29 | for (int position = 0; position <= wagons.size() - 1; position++) { 30 | int wagon = wagons.get(position); 31 | if (wagon + passengersToBeAdded <= maxCapacity) { 32 | wagons.set(position, wagon + passengersToBeAdded); 33 | break; 34 | } 35 | } 36 | } 37 | 38 | command = scanner.nextLine(); 39 | } 40 | 41 | for (Integer wagon : wagons) { 42 | System.out.print(wagon + " "); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /07. Maps, Lambda, Stream API - Lab/Demo/Demo.java: -------------------------------------------------------------------------------- 1 | package maps; 2 | 3 | import java.util.*; 4 | 5 | public class Demo { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | //запис: име на ученик (String) -> оценка (double) 9 | 10 | //съзадаване на празен map 11 | Map studentsMap = new TreeMap<>(); 12 | 13 | //видове: 14 | //1. HashMap -> редът на записите не е гарантиран 15 | //2. LinkedHashMap -> редът на записите се запазва спрямо реда на добавяне 16 | //3. TreeMap -> нарежда записите спрямо ключа в нарастващ ред (ascending order) 17 | 18 | //добавяме записи в map 19 | studentsMap.put("Ivan", 5.60); 20 | studentsMap.put("Petya", 4.30); 21 | studentsMap.put("Georgi", 3.40); 22 | 23 | System.out.println(studentsMap.size()); //брой на записите в map-a 24 | 25 | //премахваме записи от map 26 | studentsMap.remove("Petya"); //премахване по ключ, ако го има 27 | studentsMap.remove("Georgi", 3.40); //премахване на запис, ако го има 28 | studentsMap.remove("Peter"); 29 | 30 | //проверка дали map е празен (size = 0) 31 | System.out.println(studentsMap.isEmpty()); 32 | 33 | //проверка дали съществува запис с даден ключ 34 | System.out.println(studentsMap.containsKey("Desi")); 35 | System.out.println(studentsMap.containsValue(5.60)); 36 | 37 | //премахва всички елементи от map 38 | studentsMap.clear(); 39 | 40 | //запис: име на ученика -> списък с оценки 41 | Map> studentGrades = new HashMap<>(); 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /05. Lists - Lab/Demo/DemoListsVsArrays.java: -------------------------------------------------------------------------------- 1 | package Lists; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class DemoListsVsArrays { 7 | public static void main(String[] args) { 8 | //1. съзадаването 9 | int [] array = new int[10]; //задаваме брой на елементите 10 | List list = new ArrayList<>(); //няма нужда да задаваме брой елементи 11 | 12 | //2. брой елементи 13 | System.out.println(array.length); //дължина = брой елементи 14 | System.out.println(list.size()); //размер = брой елементи 15 | 16 | //3. достъп елементи 17 | System.out.println(array[0]); 18 | System.out.println(list.get(0)); 19 | 20 | //4. добавяме елементи 21 | array[1] = 5; 22 | list.add(50); //добавяме елемента в скобите в края на списъка 23 | list.add(0, 12); //вмъквате елемента на дадения индекс 24 | 25 | //5. обхождане с foreach 26 | for (int number: array) { 27 | System.out.println(number); 28 | } 29 | 30 | for (int number: list) { 31 | System.out.println(number); 32 | } 33 | 34 | //5. обхождане с for 35 | for (int position = 0; position <= array.length - 1; position++) { 36 | System.out.println(array[position]); 37 | } 38 | 39 | for (int position = 0; position <= list.size() - 1; position++) { 40 | System.out.println(list.get(position)); 41 | } 42 | 43 | //ПРЕДИМСТВА НА ЛИСТ ПРЕД МАСИВ 44 | //1. ПРЕОРАЗМЕРЯВАНЕ - НЯМА НУЖДА ПРЕДВАРИТЕЛНО ДА ЗНАЕМ БРОЯ НА ЕЛЕМЕНТИ 45 | //2. ПО-ФУНКЦИОНАЛЕН = ПО-ЛЕСНО СЕ МОДИФИЦИРА 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /05. Lists - Exercise/CardsGame_06.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.List; 3 | import java.util.Scanner; 4 | import java.util.stream.Collectors; 5 | 6 | public class CardsGame_06 { 7 | 8 | public static void main(String[] args) { 9 | 10 | Scanner scanner = new Scanner(System.in); 11 | 12 | List firstPlayerCards = Arrays.stream(scanner.nextLine().split(" ")).map(Integer::parseInt).collect(Collectors.toList()); 13 | List secondPlayerCards = Arrays.stream(scanner.nextLine().split(" ")).map(Integer::parseInt).collect(Collectors.toList()); 14 | 15 | while (!firstPlayerCards.isEmpty() && !secondPlayerCards.isEmpty()) { 16 | 17 | int firstPlayerCard = firstPlayerCards.get(0); 18 | int secondPlayerCard = secondPlayerCards.get(0); 19 | 20 | firstPlayerCards.remove(0); 21 | secondPlayerCards.remove(0); 22 | 23 | if (firstPlayerCard > secondPlayerCard) { 24 | firstPlayerCards.add(firstPlayerCard); 25 | firstPlayerCards.add(secondPlayerCard); 26 | } else if (secondPlayerCard > firstPlayerCard) { 27 | secondPlayerCards.add(secondPlayerCard); 28 | secondPlayerCards.add(firstPlayerCard); 29 | } 30 | } 31 | 32 | if (!firstPlayerCards.isEmpty()) { 33 | int sum = firstPlayerCards.stream().mapToInt(Integer::intValue).sum(); 34 | System.out.println("First player wins! Sum: " + sum); 35 | } else { 36 | int sum = secondPlayerCards.stream().mapToInt(Integer::intValue).sum(); 37 | System.out.println("Second player wins! Sum: " + sum); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Lab/MonthPrinter_05.java: -------------------------------------------------------------------------------- 1 | package BasicsOverview; 2 | 3 | import java.util.Scanner; 4 | 5 | public class MonthPrinter_05 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int number = Integer.parseInt(scanner.nextLine()); 10 | //switch -> серия от проверки за точни стойности, само 1 да е вярна 11 | 12 | switch (number) { 13 | case 1: 14 | System.out.println("January"); 15 | break; 16 | case 2: 17 | System.out.println("February"); 18 | break; 19 | case 3: 20 | System.out.println("March"); 21 | break; 22 | case 4: 23 | System.out.println("April"); 24 | break; 25 | case 5: 26 | System.out.println("May"); 27 | break; 28 | case 6: 29 | System.out.println("June"); 30 | break; 31 | case 7: 32 | System.out.println("July"); 33 | break; 34 | case 8: 35 | System.out.println("August"); 36 | break; 37 | case 9: 38 | System.out.println("September"); 39 | break; 40 | case 10: 41 | System.out.println("October"); 42 | break; 43 | case 11: 44 | System.out.println("November"); 45 | break; 46 | case 12: 47 | System.out.println("December"); 48 | break; 49 | default: 50 | System.out.println("Error!"); 51 | break; 52 | } 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Additional Videos.txt: -------------------------------------------------------------------------------- 1 | 9. Sum of Odd Numbers (Basic Syntax, Conditional Statements and Loops - Lab) 2 | Видео: https://youtu.be/kouRiwgX2l4 3 | Решение: https://pastebin.com/P38mhmdi 4 | 5 | 4. Time After 30 Minutes (Basic Syntax, Conditional Statements and Loops - Lab) 6 | Видео: https://youtu.be/s_1ObG7HQHM 7 | Решение: https://pastebin.com/quuhcsTe 8 | 9 | 5. Messages (Data Types and Variables - More Exercises) 10 | Видео: https://youtu.be/fzg7eWRZdE0 11 | 12 | 1. Data Type Finder (Data Types and Variables - More Exercises) 13 | Видео: https://youtu.be/vlDS4DD1Q4s 14 | 15 | 09. Centuries to Minutes (Data Types and Variables - Lab): 16 | Видео: https://youtu.be/l0c6sSO3Hwg 17 | решение: https://pastebin.com/u6Tr5Tb0 18 | 19 | 10. Special Numbers (Data Types and Variables - Lab) 20 | Видео: https://youtu.be/wINNgD0G7PM 21 | Решение: https://pastebin.com/SaDeHJ7Z 22 | 23 | 4. Town Info (Data Types and Variables - Lab) 24 | Видео: https://youtu.be/T1ZFFxvuqR8 25 | Решение: https://pastebin.com/5T6VrxFY 26 | 27 | 7. Water Overflow (Data Types and Variables - Exercise) 28 | Видео: https://youtu.be/bMZkPePJ1Dw 29 | 30 | 11. Snowballs (Data Types and Variables - Exercise) 31 | Видео: https://youtu.be/2fzK6GqGbkg 32 | 33 | 09. Padawan Equipment (Basic Syntax, Conditional Statements and Loops - Exercise) 34 | Видео: https://youtu.be/6--jkhQiI3c 35 | 36 | 5. Even and Odd Subtraction (Arrays - Lab) 37 | видео: https://youtu.be/kSyL0JrjO98 38 | решение: https://pastebin.com/kyGYg9UH 39 | 40 | 6. Lady Bugs 41 | видео: https://youtu.be/gH7P3RXPTXQ 42 | 43 | 6. Equal Arrays (Arrays - Lab) 44 | видео: https://www.youtube.com/watch?v=IZ_HXnMrjns 45 | решение: https://pastebin.com/uZ01U3hH 46 | 47 | 3. Big Factorial (Objects and Classes - Lab) 48 | видео: https://youtu.be/wI5K4rdmEew 49 | решение: https://pastebin.com/S8aKbQ2w 50 | -------------------------------------------------------------------------------- /05. Lists - Lab/RemoveNegativesAndReverse_06.java: -------------------------------------------------------------------------------- 1 | package Lists; 2 | 3 | import java.util.*; 4 | import java.util.stream.Collectors; 5 | 6 | public class RemoveNegativesAndReverse_06 { 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | List numbers = Arrays.stream(scanner.nextLine().split(" ")) 10 | .map(Integer::parseInt).collect(Collectors.toList()); //всички числа 11 | 12 | //numbers = {10, -5, 7, 9, -33, 50} 13 | 14 | List positiveNumbers = new ArrayList<>(); //положителните числа 15 | 16 | for (int number : numbers) { //всяко едно число от първоначалния списък 17 | if (number > 0) { 18 | //положително число 19 | positiveNumbers.add(number); 20 | } 21 | } 22 | //positiveNumbers -> имаме само положителните числа от първоначалния списък 23 | //positiveNumbers = {10, 7, 9, 50} 24 | //reverse (обръщаме на обратно) 25 | Collections.reverse(positiveNumbers); 26 | //positiveNumbers = {50, 9, 7, 10} 27 | 28 | //празен списък 29 | if (positiveNumbers.isEmpty()) { 30 | //празен списък 31 | System.out.println("empty"); 32 | } else { 33 | //има елементи в списъка 34 | /*System.out.println(positiveNumbers.toString() //"[50, 10, 9, 7]" 35 | .replace("[", "") //"50, 10, 9, 7]" 36 | .replace("]", "") //"50, 10, 9, 7" 37 | .replaceAll(",", "") //"50 10 9 7" 38 | );*/ 39 | 40 | for (int number : positiveNumbers) { 41 | System.out.print(number + " "); 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /10. RegEx - Exercise/SoftuniBarIncome_02.java: -------------------------------------------------------------------------------- 1 | package RegEx; 2 | 3 | import java.util.Scanner; 4 | import java.util.regex.Matcher; 5 | import java.util.regex.Pattern; 6 | 7 | public class SoftuniBarIncome_02 { 8 | public static void main(String[] args) { 9 | Scanner scanner = new Scanner(System.in); 10 | String regex = "%(?[A-Z][a-z]+)%[^\\|$%\\.]*<(?\\w+)>[^\\|\\$%\\.]*\\|(?[0-9]+)\\|[^\\|\\$%\\.]*?(?[0-9]+\\.?[0-9]*)\\$"; 11 | Pattern pattern = Pattern.compile(regex); //шаблон 12 | 13 | double totalIncome = 0; //приход от всички поръчки 14 | 15 | String input = scanner.nextLine(); //входни данни 16 | while (!input.equals("end of shift")) { 17 | //входни данни представляват поръчка 18 | //input = "%George%|2|10.3$" 19 | Matcher matcher = pattern.matcher(input); 20 | 21 | if (matcher.find()) { 22 | //валидна поръчка 23 | //matcher = "%(?George)%<(?Croissant)>|(?2)|(?10.3)$" 24 | String customerName = matcher.group("customerName"); //"George" 25 | String product = matcher.group("product"); //"Croissant" 26 | int count = Integer.parseInt(matcher.group("count")); //"2" -> parse -> 2 27 | double price = Double.parseDouble(matcher.group("price")); //"10.3" -> parse -> 10.3 28 | 29 | double totalPricePerOrder = count * price; //цена за текушата поръчка 30 | totalIncome += totalPricePerOrder; 31 | System.out.printf("%s: %s - %.2f%n", customerName, product, totalPricePerOrder); 32 | } 33 | input = scanner.nextLine(); 34 | } 35 | 36 | System.out.printf("Total income: %.2f", totalIncome); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Mid Exam Preparation - Part 1/MuOnline_Bonus.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class MuOnline_Bonus { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String[] rooms = scanner.nextLine().split("\\|"); 10 | 11 | int health = 100; 12 | int coins = 0; 13 | int roomsCount = 0; 14 | 15 | for (String room : rooms) { 16 | 17 | //"cat 10" 18 | String name = room.split(" ")[0]; 19 | int amount = Integer.parseInt(room.split(" ")[1]); 20 | roomsCount++; 21 | 22 | switch (name) { 23 | case "potion": 24 | int healAmount = Math.min(100 - health, amount); 25 | health += healAmount; 26 | System.out.printf("You healed for %d hp.\n", healAmount); 27 | System.out.printf("Current health: %d hp.\n", health); 28 | break; 29 | case "chest": 30 | coins += amount; 31 | System.out.printf("You found %d bitcoins.\n", amount); 32 | break; 33 | default: 34 | health -= amount; 35 | if (health > 0) { 36 | System.out.printf("You slayed %s.\n", name); 37 | } else { 38 | System.out.printf("You died! Killed by %s.\n", name); 39 | System.out.printf("Best room: %d", roomsCount); 40 | return; 41 | } 42 | break; 43 | } 44 | } 45 | 46 | System.out.println("You've made it!"); 47 | System.out.println("Bitcoins: " + coins); 48 | System.out.println("Health: " + health); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Mid Exam Preparation - Part 1/ShoppingList_02.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.List; 3 | import java.util.Scanner; 4 | import java.util.stream.Collectors; 5 | 6 | public class ShoppingList_02 { 7 | 8 | public static void main(String[] args) { 9 | 10 | Scanner scanner = new Scanner(System.in); 11 | 12 | List items = Arrays.stream(scanner.nextLine().split("!")).collect(Collectors.toList()); 13 | 14 | String input = scanner.nextLine(); 15 | while (!input.equals("Go Shopping!")) { 16 | 17 | String command = input.split(" ")[0]; 18 | String item = input.split(" ")[1]; 19 | 20 | switch (command) { 21 | case "Urgent": 22 | if (!items.contains(item)) { 23 | items.add(0, item); 24 | } 25 | break; 26 | case "Unnecessary": 27 | items.remove(item); 28 | break; 29 | case "Correct": 30 | if (items.contains(item)) { 31 | String newItem = input.split(" ")[2]; 32 | int itemIndex = items.indexOf(item); 33 | items.set(itemIndex, newItem); 34 | } 35 | break; 36 | case "Rearrange": 37 | if (items.contains(item)){ 38 | items.remove(item); 39 | items.add(item); 40 | } 41 | break; 42 | } 43 | 44 | input = scanner.nextLine(); 45 | } 46 | 47 | // System.out.println(items.toString().replace("[", "").replace("]", "")); 48 | 49 | // САМО ЗА List 50 | System.out.println(String.join(", ", items)); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /07. Associative Arrays - Exercise/SoftUniParking_04.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class SoftUniParking_04 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int n = Integer.parseInt(scanner.nextLine()); 10 | 11 | Map registeredStudents = new LinkedHashMap<>(); 12 | 13 | for (int i = 1; i <= n; i++) { 14 | 15 | String[] data = scanner.nextLine().split("\\s+"); 16 | String command = data[0]; 17 | 18 | switch (command) { 19 | case "register": 20 | String studentName = data[1]; 21 | String plateNumber = data[2]; 22 | if (registeredStudents.containsKey(studentName)) { 23 | System.out.printf("ERROR: already registered with plate number %s%n", plateNumber); 24 | } else { 25 | registeredStudents.put(studentName, plateNumber); 26 | System.out.printf("%s registered %s successfully%n", studentName, plateNumber); 27 | } 28 | break; 29 | case "unregister": 30 | String userName = data[1]; 31 | if (!registeredStudents.containsKey(userName)) { 32 | System.out.println(String.format("ERROR: user %s not found", userName)); 33 | } else { 34 | registeredStudents.remove(userName); 35 | System.out.println(String.format("%s unregistered successfully", userName)); 36 | } 37 | break; 38 | } 39 | } 40 | 41 | registeredStudents.entrySet().forEach(entry -> System.out.printf("%s => %s\n", entry.getKey(), entry.getValue())); 42 | } 43 | } -------------------------------------------------------------------------------- /06. Objects and Classes - Lab/songs/Main.java: -------------------------------------------------------------------------------- 1 | package songs; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Scanner; 6 | 7 | public class Main { 8 | public static void main(String[] args) { 9 | //логиката на задачата -> входни данни, алгоритми, изходни данни 10 | Scanner scanner = new Scanner(System.in); 11 | int countSongs = Integer.parseInt(scanner.nextLine()); //брой песните 12 | List songsList = new ArrayList<>(); 13 | 14 | for (int count = 1; count <= countSongs; count++) { 15 | String data = scanner.nextLine(); //"{typeList}_{name}_{time}" 16 | String[] songData = data.split("_"); 17 | //"{typeList}_{name}_{time}".split("_") -> ["{typeList}", "{name}", "{time}"] 18 | String typeList = songData[0]; //плейлиста на песента 19 | String name = songData[1]; //име на песента 20 | String time = songData[2]; //времетраенето на песента 21 | 22 | //ПЕСЕН 23 | Song song = new Song(typeList, name, time); 24 | 25 | //добавям песента към списъка с въведени песни 26 | songsList.add(song); 27 | } 28 | 29 | //пълен списък с въведените песни 30 | 31 | String command = scanner.nextLine(); 32 | //1. all -> имената на всички песни в листа 33 | //2. име на плейлист -> имената на всички песни в плейлиста 34 | if (command.equals("all")) { 35 | for (Song song : songsList) { 36 | System.out.println(song.getName()); 37 | } 38 | } else { 39 | //command е име на плейлист 40 | for (Song song : songsList) { 41 | if (song.getTypeList().equals(command)) { 42 | System.out.println(song.getName()); 43 | } 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /01. Basic Syntax, Conditional Statements and Loops - Exercise/Vacation_03.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Vacation_03 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int studentsCount = Integer.parseInt(scanner.nextLine()); 10 | String group = scanner.nextLine(); 11 | String weekday = scanner.nextLine(); 12 | 13 | double price = 0; 14 | 15 | if (group.equals("Students")) { 16 | if (weekday.equals("Friday")) { 17 | price = 8.45; 18 | } else if (weekday.equals("Saturday")) { 19 | price = 9.80; 20 | } else if (weekday.equals("Sunday")) { 21 | price = 10.46; 22 | } 23 | 24 | if (studentsCount >= 30) { 25 | price = price * 0.85; 26 | } 27 | } else if (group.equals("Business")) { 28 | if (weekday.equals("Friday")) { 29 | price = 10.90; 30 | } else if (weekday.equals("Saturday")) { 31 | price = 15.60; 32 | } else if (weekday.equals("Sunday")) { 33 | price = 16; 34 | } 35 | 36 | if (studentsCount >= 100) { 37 | studentsCount = studentsCount - 10; 38 | } 39 | } else if (group.equals("Regular")) { 40 | if (weekday.equals("Friday")) { 41 | price = 15; 42 | } else if (weekday.equals("Saturday")) { 43 | price = 20; 44 | } else if (weekday.equals("Sunday")) { 45 | price = 22.50; 46 | } 47 | 48 | if (studentsCount >= 10 && studentsCount <= 20) { 49 | price = price * 0.95; 50 | } 51 | } 52 | 53 | double totalPrice = studentsCount * price; 54 | System.out.printf("Total price: %.2f", totalPrice); 55 | } 56 | } -------------------------------------------------------------------------------- /Mid Exam Preparation - Part 2/BlackFlag_01.java: -------------------------------------------------------------------------------- 1 | package ExamPrepartion; 2 | 3 | import java.util.Scanner; 4 | 5 | public class First_Task { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | int days = Integer.parseInt(scanner.nextLine()); //общ брой дни за крадене 9 | int plundersPerDay = Integer.parseInt(scanner.nextLine()); //кражби за ден 10 | double targetCountPlunders = Double.parseDouble(scanner.nextLine()); //брой целеви кражби 11 | 12 | //1. изчисляваме брой направени кражби 13 | double totalPlunders = 0;//общ брой кражби 14 | 15 | for (int day = 1; day <= days; day++) { 16 | //повтаряме: извършваме кражби = plundersPerDay 17 | totalPlunders += plundersPerDay; 18 | 19 | if (day % 3 == 0) { 20 | //правим допълнителни кражби 21 | double extraPlunders = 0.5 * plundersPerDay; 22 | totalPlunders += extraPlunders; 23 | } 24 | 25 | if (day % 5 == 0) { 26 | //губим 30% от общия брой кражби 27 | totalPlunders = totalPlunders - totalPlunders * 0.3; 28 | //totalPlunders = totalPlunders * 0.7; 29 | //totalPlunders *= 0.7; 30 | } 31 | 32 | } 33 | //обходили всички дни -> колко са общо направените кражби -> totalPlunders 34 | //2. проверка дали сме постигнали целта 35 | if (totalPlunders >= targetCountPlunders) { 36 | //постигнали целта си 37 | System.out.printf("Ahoy! %.2f plunder gained.", totalPlunders); 38 | } else { 39 | //totalPlunders < targetCountPlunders 40 | //не сме успяли да постигнем целта си 41 | double percent = (totalPlunders / targetCountPlunders) * 100; 42 | System.out.printf("Collected only %.2f%% of the plunder.", percent); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /04. Methods - Exercise/PasswordValidator_04.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class PasswordValidator_04 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String password = scanner.nextLine(); 10 | 11 | //1. Проверяваме дали дължината на паролата е между 6 и 10 символа 12 | boolean isLengthValid = isLengthValid(password); 13 | if (!isLengthValid) { 14 | System.out.println("Password must be between 6 and 10 characters"); 15 | } 16 | 17 | //2. Проверяваме дали съдържа само цифри и букви 18 | boolean isContentValid = isContentValid(password); 19 | if (!isContentValid) { 20 | System.out.println("Password must consist only of letters and digits"); 21 | } 22 | 23 | //3. Проверяваме дали има поне 2 цифри 24 | boolean isAtLeastTwoDigits = isAtLeastTwoDigits(password); 25 | if (!isAtLeastTwoDigits) { 26 | System.out.println("Password must have at least 2 digits"); 27 | } 28 | 29 | // Ако и трите условия са спазени ще кажем, че паролата е валидна: 30 | if (isLengthValid && isContentValid && isAtLeastTwoDigits) { 31 | System.out.println("Password is valid"); 32 | } 33 | } 34 | 35 | public static boolean isAtLeastTwoDigits(String input) { 36 | 37 | int digitsCount = 0; 38 | for (char symbol : input.toCharArray()) { 39 | if (Character.isDigit(symbol)) { 40 | digitsCount++; 41 | } 42 | } 43 | return digitsCount >= 2; 44 | } 45 | 46 | 47 | public static boolean isLengthValid(String input) { 48 | return input.length() >= 6 && input.length() <= 10; 49 | } 50 | 51 | public static boolean isContentValid(String input) { 52 | for (char symbol : input.toCharArray()) { 53 | if (!Character.isLetterOrDigit(symbol)) { 54 | return false; 55 | } 56 | } 57 | return true; 58 | } 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /06. Objects and Classes - Exercise/vehicle_catalogue_05/Main.java: -------------------------------------------------------------------------------- 1 | package vehicle_catalogue_05; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Scanner; 6 | 7 | public class Main { 8 | 9 | public static void main(String[] args) { 10 | 11 | Scanner scanner = new Scanner(System.in); 12 | 13 | List vehicles = new ArrayList<>(); 14 | 15 | String input = scanner.nextLine(); 16 | while (!input.equals("End")) { 17 | String[] rowElements = input.split("\\s+"); 18 | vehicles.add(new Vehicle(rowElements[0], rowElements[1], rowElements[2], Integer.parseInt(rowElements[3]))); 19 | input = scanner.nextLine(); 20 | } 21 | 22 | String model = scanner.nextLine(); 23 | while (!model.equals("Close the Catalogue")) { 24 | for (Vehicle vehicle : vehicles) { 25 | if (vehicle.getModel().equals(model)) { 26 | System.out.println(vehicle); 27 | } 28 | } 29 | model = scanner.nextLine(); 30 | } 31 | 32 | double sumCar = 0; 33 | double sumTruck = 0; 34 | int countCar = 0; 35 | int countTruck = 0; 36 | 37 | for (Vehicle vehicle : vehicles) { 38 | if (vehicle.getType().equals("car")) { 39 | sumCar += vehicle.getHorsePower(); 40 | countCar++; 41 | } else if (vehicle.getType().equals("truck")) { 42 | sumTruck += vehicle.getHorsePower(); 43 | countTruck++; 44 | } 45 | } 46 | 47 | double averageCars = sumCar / countCar; 48 | if (countCar == 0) { 49 | averageCars = 0; 50 | } 51 | System.out.printf("Cars have average horsepower of: %.2f.%n", averageCars); 52 | 53 | double averageTrucks = sumTruck / countTruck; 54 | if (countTruck == 0) { 55 | averageTrucks = 0; 56 | } 57 | System.out.printf("Trucks have average horsepower of: %.2f.%n", averageTrucks); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /10. RegEx - Exercise/ValidPassword_06.java: -------------------------------------------------------------------------------- 1 | package RegEx; 2 | 3 | import java.util.Scanner; 4 | import java.util.regex.Matcher; 5 | import java.util.regex.Pattern; 6 | 7 | public class ValidPassword_06 { 8 | public static void main(String[] args) { 9 | Scanner scanner = new Scanner(System.in); 10 | String regexPassword = "_\\.+(?[A-Z][A-Za-z0-9]{4,}[A-Z])_\\.+"; 11 | Pattern pattern = Pattern.compile(regexPassword); 12 | 13 | int n = Integer.parseInt(scanner.nextLine()); //брой пароли 14 | for (int count = 1; count <= n; count++) { 15 | String password = scanner.nextLine(); 16 | //1. проверка дали е валидна паролата 17 | Matcher matcher = pattern.matcher(password); 18 | //1. matcher = [] -> невалидна парола 19 | //2. matcher = ["_.A123f23A_."] -> валидна парола 20 | 21 | if (matcher.find()) { 22 | //matcher.find() -> "_.A123f23A_." 23 | //имаме валидна парола -> категоризирам 24 | String textPassword = matcher.group("passwordText"); //"A123f23A" 25 | //2. категоризация 26 | StringBuilder sbDigits = new StringBuilder(); //долепям намерените цифри в паролата 27 | for (char symbol : textPassword.toCharArray()) { 28 | if (Character.isDigit(symbol)) { 29 | //цифра 30 | sbDigits.append(symbol); 31 | } 32 | } 33 | //sbDigits -> долепени всички цифри в паролата 34 | //1. нямаме цифри в паролата -> група default 35 | if (sbDigits.length() == 0) { 36 | System.out.println("Group: default"); 37 | } 38 | //2. имаме цифри в паролата 39 | else { 40 | System.out.println("Group: " + sbDigits); 41 | } 42 | } else { 43 | //matcher = [] -> невалидна парола 44 | System.out.println("Invalid pass!"); 45 | } 46 | 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /07. Associative Arrays - Exercise/SoftUniExamResults_10.java: -------------------------------------------------------------------------------- 1 | import java.util.LinkedHashMap; 2 | import java.util.Map; 3 | import java.util.Scanner; 4 | 5 | public class SoftUniExamResults_10 { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner scanner = new Scanner(System.in); 10 | 11 | Map userAndPoints = new LinkedHashMap<>(); 12 | Map languageCount = new LinkedHashMap<>(); 13 | 14 | String input = scanner.nextLine(); 15 | while (!input.equals("exam finished")) { 16 | 17 | if (input.contains("banned")) { 18 | //Katy-banned 19 | String username = input.split("-")[0]; 20 | userAndPoints.remove(username); 21 | } else { 22 | //Peter-Java-84 23 | String username = input.split("-")[0]; 24 | String language = input.split("-")[1]; 25 | int points = Integer.parseInt(input.split("-")[2]); 26 | 27 | if (!userAndPoints.containsKey(username)) { 28 | userAndPoints.put(username, points); 29 | } else { 30 | int existingPoints = userAndPoints.get(username); 31 | if (points > existingPoints) { 32 | userAndPoints.put(username, points); 33 | } 34 | } 35 | 36 | if (!languageCount.containsKey(language)) { 37 | languageCount.put(language, 1); 38 | } else { 39 | int existingCount = languageCount.get(language); 40 | languageCount.put(language, existingCount + 1); 41 | } 42 | } 43 | 44 | input = scanner.nextLine(); 45 | } 46 | 47 | System.out.println("Results:"); 48 | userAndPoints.entrySet().forEach(entry -> System.out.printf("%s | %d\n", entry.getKey(), entry.getValue())); 49 | System.out.println("Submissions:"); 50 | languageCount.entrySet().forEach(entry -> System.out.printf("%s - %d\n", entry.getKey(), entry.getValue())); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /05. Lists - Exercise/PokemonDontGo_09.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.List; 3 | import java.util.Scanner; 4 | import java.util.stream.Collectors; 5 | 6 | public class PokemonDontGo_09 { 7 | 8 | public static void main(String[] args) { 9 | 10 | Scanner scanner = new Scanner(System.in); 11 | 12 | List numbers = Arrays.stream(scanner.nextLine().split(" ")) 13 | .map(Integer::parseInt) 14 | .collect(Collectors.toList()); 15 | 16 | int sum = 0; 17 | 18 | while (numbers.size() > 0) { 19 | 20 | int index = Integer.parseInt(scanner.nextLine()); 21 | 22 | if (index >= 0 && index <= numbers.size() - 1) { 23 | int removedElement = numbers.get(index); 24 | sum += removedElement; 25 | numbers.remove(index); 26 | modifyList(numbers, removedElement); 27 | } else if (index < 0) { 28 | int removedElement = numbers.get(0); 29 | sum += removedElement; 30 | int lastElement = numbers.get(numbers.size() - 1); 31 | numbers.set(0, lastElement); 32 | modifyList(numbers, removedElement); 33 | } else if (index > numbers.size() - 1) { 34 | int removedElement = numbers.get(numbers.size() - 1); 35 | sum += removedElement; 36 | int firstElement = numbers.get(0); 37 | numbers.set(numbers.size() - 1, firstElement); 38 | modifyList(numbers, removedElement); 39 | } 40 | } 41 | 42 | System.out.println(sum); 43 | } 44 | 45 | private static void modifyList(List numbers, int removedElement) { 46 | 47 | for (int position = 0; position <= numbers.size() - 1; position++) { 48 | 49 | int currentElement = numbers.get(position); 50 | 51 | if (currentElement <= removedElement) { 52 | currentElement += removedElement; 53 | } else { 54 | currentElement -= removedElement; 55 | } 56 | 57 | numbers.set(position, currentElement); 58 | } 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /10. RegEx - Exercise/NetherRealms_04.java: -------------------------------------------------------------------------------- 1 | package RegEx; 2 | 3 | import java.util.Scanner; 4 | import java.util.regex.Matcher; 5 | import java.util.regex.Pattern; 6 | 7 | public class NetherRealms_04 { 8 | public static void main(String[] args) { 9 | Scanner scanner = new Scanner(System.in); 10 | 11 | String [] demonNames = scanner.nextLine().replace(" ", "").split(","); 12 | 13 | for (String demonName : demonNames) { 14 | int health = getHealth(demonName); 15 | double damage = getDamage(demonName); 16 | 17 | //модификации на damage 18 | for (char symbol : demonName.toCharArray()) { 19 | if (symbol == '*') { 20 | damage *= 2; 21 | } else if (symbol == '/') { 22 | damage /= 2; 23 | } 24 | } 25 | 26 | //отпечатваме за всеки демон 27 | System.out.printf("%s - %d health, %.2f damage%n", demonName, health, damage); 28 | } 29 | } 30 | 31 | //изчислява и връща damage 32 | private static double getDamage(String demonName) { 33 | double damage = 0; 34 | //всички дробни и цели числа, които са положителни и отрицателни 35 | String regexNumbers = "[-]?[0-9]+\\.?[0-9]*"; 36 | Pattern pattern = Pattern.compile(regexNumbers); 37 | Matcher matcher = pattern.matcher(demonName); 38 | //matcher -> съвкупност от всички тесктове, които ми отговарят на шаблона 39 | //demonName = "M3ph-0.5s-0.5t0.0**" 40 | //matcher = ["3", "-0.5", "-0.5", "0.0"] 41 | while (matcher.find()) { 42 | damage += Double.parseDouble(matcher.group()); 43 | } 44 | return damage; 45 | } 46 | 47 | //изчислява и връща health 48 | private static int getHealth(String demonName) { 49 | int health = 0; 50 | //всички символи без: [0-9], +, -, ., *, / 51 | for (char symbol : demonName.toCharArray()) { 52 | if (!Character.isDigit(symbol) && symbol != '+' && symbol != '-' && symbol != '*' && symbol != '.' && symbol != '/') { 53 | health += (int)(symbol); 54 | } 55 | } 56 | return health; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /03. Arrays - Lab/Demo/Demo3.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class Demo3 { 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | //1. масивът е съвкупност от еднотипни елементи 8 | //2. масивът има постоянна дължина 9 | //3. дължина на масив = максималния брой елементи, които можем да съхраним 10 | //4. позиции / индекси -> 0 до последната (дължина на масива - 1) 11 | //5. задавате стойност в масив: array[0] = 56; 12 | //6. достъпвате стойност в масив: array[5] 13 | //7. foreach - обхожда масив, когато ни трябват елементите последователно, без значение от позицията 14 | //8. for - обхожда масив, когато ни трябват елементите и позициите им 15 | //9. Пълнене на масив 16 | 17 | //вариант 1 за запълване на масив(статичен с предварително зададени елементи) 18 | int [] dates = {4, 5, 6, 7}; 19 | 20 | //вариант 2 за запълване на масив (празен масив и добавяме елементи) 21 | double[] prices = new double[10]; 22 | prices[0] = 34.5; 23 | prices[1] = 23.5; 24 | 25 | //вариант 3 за запълване на масив (елементите се въвеждат на отделни редове) 26 | int n = Integer.parseInt(scanner.nextLine()); 27 | int [] numbers = new int[n]; 28 | 29 | for (int position = 0; position <= numbers.length - 1; position++) { 30 | numbers[position] = Integer.parseInt(scanner.nextLine()); 31 | } 32 | 33 | //вариант 4 за запълване на масив (елементите са на един ред) 34 | String[] inputs = scanner.nextLine().split(" "); 35 | int [] integerNumbers = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray(); 36 | double [] decimalNumbers = Arrays.stream(scanner.nextLine().split(" ")).mapToDouble(Double::parseDouble).toArray(); 37 | 38 | String names = "Desi Ivan Georgi Tanya"; 39 | String [] namesArray = names.split(" "); //["Desi", "Ivan", "Georgi", "Tanya"] 40 | System.out.println(String.join(" ", namesArray)); //"Desi Ivan Georgi Tanya" 41 | 42 | //split (раздели): текст -> масив 43 | //join (обедини): масив -> текст 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /04. Methods - Lab/Calculations_04.java: -------------------------------------------------------------------------------- 1 | package Methods; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Calculations_04 { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String operation = scanner.nextLine(); //"add", "multiply", "subtract", "divide" 10 | int firstNumber = Integer.parseInt(scanner.nextLine()); //първото число 11 | int secondNumber = Integer.parseInt(scanner.nextLine()); //второто число 12 | 13 | executeOperation(operation, firstNumber, secondNumber); 14 | } 15 | 16 | private static void executeOperation(String operation, int firstNumber, int secondNumber) { 17 | switch (operation) { 18 | case "add": 19 | //събиране на firstNumber и secondNumber -> отпечатвам сумата 20 | sumAndPrint(firstNumber, secondNumber); 21 | break; 22 | case "multiply": 23 | //умножние на firstNumber и secondNumber -> отпечатвам произведението 24 | multiplyAndPrint(firstNumber, secondNumber); 25 | break; 26 | case "subtract": 27 | //изваждане на firstNumber и secondNumber -> отпечатвам разлика 28 | subtractAndPrint(firstNumber, secondNumber); 29 | break; 30 | case "divide": 31 | //деление на firstNumber и secondNumber -> отпечатвам частно 32 | divideAndPrint(firstNumber, secondNumber); 33 | break; 34 | 35 | } 36 | } 37 | 38 | //метод, който събира две цели числа и отпечтва сумата 39 | public static void sumAndPrint(int n1, int n2) { 40 | System.out.println(n1 + n2); 41 | } 42 | 43 | //метод, който умножава две цели числа и отпечатва произведението 44 | public static void multiplyAndPrint(int n1, int n2) { 45 | System.out.println(n1 * n2); 46 | } 47 | 48 | //метод, който изважда две цели числа и отпечатва разлика 49 | public static void subtractAndPrint(int n1, int n2) { 50 | int diff = n1 - n2; 51 | System.out.println(diff); 52 | } 53 | 54 | //метод, който дели две цели числа и отпечатва частно 55 | public static void divideAndPrint(int n1, int n2) { 56 | System.out.println(n1 / n2); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /10. RegEx - Exercise/Furniture_01.java: -------------------------------------------------------------------------------- 1 | package RegEx; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Scanner; 6 | import java.util.regex.Matcher; 7 | import java.util.regex.Pattern; 8 | 9 | public class Furniture_01 { 10 | public static void main(String[] args) { 11 | Scanner scanner = new Scanner(System.in); 12 | String regex = ">>(?[A-Za-z]+)<<(?[0-9]+\\.?[0-9]*)!(?[0-9]+)"; //текст на шаблона 13 | Pattern pattern = Pattern.compile(regex); //шаблон 14 | 15 | List furniture = new ArrayList<>(); //списък със закупените мебели 16 | double totalPrice = 0; //общо изхарчена сума за закупените мебели 17 | 18 | String input = scanner.nextLine(); //входни данни 19 | while (!input.equals("Purchase")) { 20 | //input = ">>Sofa<<312.23!3" 21 | //проверка дали входните данни отговарят на шаблона 22 | Matcher matcher = pattern.matcher(input); 23 | //matcher -> съвкупност от текстовете, които отговарят на шаблон 24 | //matcher = [">>(?Sofa)<<(?312.23)!(?3)"] 25 | //find 26 | //true -> input отговарят на шаблона 27 | //false -> input не отговарят на шаблона 28 | if (matcher.find()) { 29 | //input отговаря на шаблона -> валидни входни данни -> информация за закупена мебел 30 | //matcher.find() = ">>(?Sofa)<<(?312.23)!(?3)" 31 | String furnitureName = matcher.group("furnitureName");//мебел -> "Sofa" 32 | double price = Double.parseDouble(matcher.group("price"));//ед. цена -> "312.23" -> 312.23 33 | int quantity = Integer.parseInt(matcher.group("quantity"));//количество -> "3" -> 3 34 | 35 | furniture.add(furnitureName); 36 | double pricePerFurniture = price * quantity; //сума за текуща мебел 37 | totalPrice += pricePerFurniture; 38 | } 39 | input = scanner.nextLine(); 40 | } 41 | 42 | //списък със закупени мебели 43 | System.out.println("Bought furniture:"); 44 | furniture.forEach(System.out::println); 45 | 46 | //обща сума за мебели 47 | System.out.printf("Total money spend: %.2f", totalPrice); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /03. Arrays - Exercise/ArrayModifier_09.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class ArrayModifier_09 { 5 | 6 | public static void main(String[] args) { 7 | 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | int[] numbers = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray(); 11 | 12 | String command = scanner.nextLine(); 13 | while (!command.equals("end")) { 14 | 15 | if (command.contains("swap")) { // Ако командата е swap 16 | // swap 1 3 17 | int firstIndex = Integer.parseInt(command.split(" ")[1]); 18 | int secondIndex = Integer.parseInt(command.split(" ")[2]); 19 | 20 | int firstIndexNumber = numbers[firstIndex]; 21 | int secondIndexNumber = numbers[secondIndex]; 22 | 23 | numbers[firstIndex] = secondIndexNumber; 24 | numbers[secondIndex] = firstIndexNumber; 25 | } else if (command.contains("multiply")) { // Ако командата е multiply 26 | // multiply 1 2 27 | int firstIndex = Integer.parseInt(command.split(" ")[1]); 28 | int secondIndex = Integer.parseInt(command.split(" ")[2]); 29 | 30 | int firstIndexNumber = numbers[firstIndex]; 31 | int secondIndexNumber = numbers[secondIndex]; 32 | 33 | int product = firstIndexNumber * secondIndexNumber; 34 | 35 | numbers[firstIndex] = product; 36 | 37 | } else { // Командата е decrese 38 | for (int position = 0; position <= numbers.length - 1; position++) { 39 | numbers[position]--; 40 | } 41 | } 42 | 43 | command = scanner.nextLine(); 44 | } 45 | 46 | // Начин 1: 47 | // for (int position = 0; position < numbers.length; position++) { 48 | // 49 | // if (position == numbers.length - 1) { 50 | // System.out.print(numbers[position]); 51 | // } else { 52 | // System.out.print(numbers[position] + ", "); 53 | // } 54 | // } 55 | 56 | //Начин 2: 57 | System.out.println( 58 | Arrays.toString(numbers) 59 | .replace("[", "") 60 | .replace("]", "") 61 | ); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /06. Objects and Classes - Lab/stundents2/Main.java: -------------------------------------------------------------------------------- 1 | package stundents2; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Scanner; 6 | 7 | public class Main { 8 | public static void main(String[] args) { 9 | Scanner scanner = new Scanner(System.in); 10 | 11 | List studentsList = new ArrayList<>(); 12 | String input = scanner.nextLine(); 13 | while (!input.equals("end")) { 14 | String[] studentsDataArr = input.split(" "); 15 | String firstName = studentsDataArr[0]; 16 | String lastName = studentsDataArr[1]; 17 | int age = Integer.parseInt(studentsDataArr[2]); 18 | String town = studentsDataArr[3]; 19 | 20 | if (isStudentExisting(studentsList, firstName, lastName)) { 21 | int index = getExistingIndex(studentsList, firstName, lastName); 22 | studentsList.get(index).setAge(age); 23 | studentsList.get(index).setHometown(town); 24 | } else { 25 | Student currentStudent = new Student(firstName, lastName, age, town); 26 | studentsList.add(currentStudent); 27 | } 28 | 29 | input = scanner.nextLine(); 30 | } 31 | 32 | String homeTown = scanner.nextLine(); 33 | for (Student student : studentsList) { 34 | if (homeTown.equals(student.getHometown())) { 35 | System.out.printf("%s %s is %s years old%n", student.getFirstName(), student.getLastName(), student.getAge()); 36 | } 37 | } 38 | } 39 | 40 | public static int getExistingIndex (List studentsList, String firstName, String lastName) { 41 | int index = -1; 42 | for (int i = 0; i < studentsList.size(); i++) { 43 | Student student = studentsList.get(i); 44 | if (student.getFirstName().equals(firstName) && student.getLastName().equals(lastName)) { 45 | index = i; 46 | } 47 | } 48 | return index; 49 | } 50 | 51 | static boolean isStudentExisting(List studentsList, String firstName, String lastName) { 52 | for (Student student : studentsList) { 53 | if (student.getFirstName().equals(firstName) && student.getLastName().equals(lastName)) { 54 | return true; 55 | } 56 | } 57 | return false; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Final Exam Preparation - Part 2/ImitationGame_01.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ImitationGame_01 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String input = scanner.nextLine(); 10 | StringBuilder message = new StringBuilder(input); 11 | 12 | String command = scanner.nextLine(); 13 | while (!command.equals("Decode")) { 14 | 15 | String[] commandParts = command.split("\\|"); 16 | String commandName = commandParts[0]; 17 | 18 | switch (commandName) { 19 | case "Move": 20 | //"Ivan" -> Move|2 21 | //"anIv" 22 | int numberOfLettersToMove = Integer.parseInt(commandParts[1]); 23 | String substringToMove = message.substring(0, numberOfLettersToMove); 24 | message.delete(0, numberOfLettersToMove); 25 | message.append(substringToMove); 26 | break; 27 | case "Insert": 28 | //"Ivan" -> Insert|2|B 29 | //"IvBan" 30 | int index = Integer.parseInt(commandParts[1]); 31 | String value = commandParts[2]; 32 | message.insert(index, value); 33 | break; 34 | case "ChangeAll": 35 | //"Ivan" -> ChangeAll|an|Peter 36 | //"IvPeter" 37 | String textToReplace = commandParts[1]; 38 | String replacement = commandParts[2]; 39 | String currentMessage = message.toString(); 40 | String newMessage = currentMessage.replace(textToReplace, replacement); 41 | message = new StringBuilder(newMessage); 42 | break; 43 | // ТОЗИ КЕЙС НЕ Е ЧАСТ ОТ НАШАТА ЗАДАЧА! ТОВА Е ПРИМЕР ЗА ДОПЪЛНИТЕЛНА ОПЕРАЦИЯ С ТЕКСТОВЕ! 44 | // case "Delete": 45 | // // "Ivan" -> Delete|2 46 | // int numberOfLettersToDelete = Integer.parseInt(commandParts[1]); 47 | // message.delete(0, numberOfLettersToDelete); 48 | // break; 49 | } 50 | 51 | command = scanner.nextLine(); 52 | } 53 | 54 | System.out.println("The decrypted message is: " + message); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Mid Exam Preparation - Part 2/Numbers_03.java: -------------------------------------------------------------------------------- 1 | package ExamPrepartion; 2 | 3 | import java.util.*; 4 | import java.util.stream.Collectors; 5 | 6 | public class Third_Task { 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | //входни данни 11 | List numbers = Arrays.stream(scanner.nextLine() 12 | .split(" ")).map(Integer::parseInt) 13 | .collect(Collectors.toList()); 14 | //{10, 20, 30, 40, 50} 15 | 16 | //1. Средноаритметична стойност 17 | int sum = 0; //сума на елементите в списък 18 | for (int number : numbers) { 19 | sum += number; 20 | } 21 | double average = sum * 1.0 / numbers.size(); //средна стойност в списъка 22 | 23 | //2. Всички числа по-големи от average 24 | List greaterElements = new ArrayList<>(); //числа, по-големи от average 25 | for (int number : numbers) { 26 | if (number > average) { 27 | greaterElements.add(number); 28 | } 29 | } 30 | //greaterElements -> всички числа, по-големи от average 31 | 32 | //3. Сортираме по-големите елементи от average в descending order 33 | //greaterElements = {40, 50} 34 | Collections.sort(greaterElements); //ascending order (нарастващ ред) 35 | Collections.reverse(greaterElements); //descending order (намаляващ ред) 36 | //greaterElements = {50, 40} 37 | 38 | //4. Отпечатваме 39 | //нямаме числа, които да отговарят на условието -> greaterElements = {}; size = 0 40 | if (greaterElements.isEmpty()) { 41 | System.out.println("No"); 42 | } else { 43 | //имаме числа, които да отговарят на условието -> greaterElements.size > 0 44 | //1. брой числа <= 5 -> greaterElements = {40, 50} 45 | if (greaterElements.size() <= 5) { 46 | //отпечатваме всички налични числа 47 | for (int number : greaterElements) { 48 | System.out.print(number + " "); 49 | } 50 | } 51 | else { 52 | //2. брой числа > 5 -> greaterElements = {50, 40, 30 , 24, 12, 6} 53 | //първите 5 числа 54 | for (int position = 0; position <= 4; position++) { 55 | System.out.print(greaterElements.get(position) + " "); 56 | } 57 | } 58 | } 59 | } 60 | } 61 | --------------------------------------------------------------------------------