└── src ├── day40 ├── Names ├── Items ├── StoreSeller.java ├── WriteBytesStream.java ├── TryWithResources.java ├── Assignment3.java └── ReadingInputStream.java ├── day35 ├── I.java ├── CanFly.java ├── I2.java ├── Mammal.java ├── A2.java ├── C.java ├── ChildDemo.java ├── A.java ├── Eagle.java ├── B2.java ├── Car.java ├── Parent.java ├── Animal.java ├── Child.java ├── B.java ├── D.java ├── Audi.java ├── Ox.java ├── BMW.java ├── CarDemo.java ├── PhoneDemo.java ├── Dog.java ├── DogDemo.java ├── BigBox.java ├── NormalBox.java ├── SmallBox.java ├── BoxDemo.java └── Box.java ├── day14 ├── package-info.java ├── DoWhile.java ├── HelloWorld.java ├── PrintLetters.java ├── BreakALoop.java └── Pyramid.java ├── day34 ├── BMW.java ├── USA.java ├── Country.java ├── CountryDemo.java ├── CatDemo.java ├── Car.java ├── CarDemo.java ├── A.java ├── Cat.java ├── Apple.java ├── Ferrari.java └── AppleDemo.java ├── day11 ├── Grade.java ├── StrTrim.java ├── CircleArea.java ├── WarmUp.java ├── StrMethodsReview.java ├── StrContains.java ├── StrEqual.java └── CharCompare.java ├── day27 ├── Rating.java ├── EmployeeDemo.java ├── Student.java ├── CatDemo.java ├── PersonDemo.java ├── BookDemo2.java ├── Person.java ├── Employee.java └── Cat.java ├── day37 ├── I.java ├── C.java ├── E.java ├── D.java ├── Chocolate.java ├── ChocolateDemo.java ├── Report.java ├── TimePractice.java ├── StringToDates.java ├── LocalDateTimePractice.java └── DatePractice.java ├── day33 ├── Animal.java ├── Mammal.java ├── Circle.java ├── Student.java ├── MammalDemo.java ├── Lion.java ├── StudentDemo.java ├── PersonDemo.java └── PersonDemo3.java ├── day36 ├── Bird.java ├── Reptile.java ├── Phone.java ├── Alligator.java ├── Crocodile.java ├── Eagle.java ├── Primate.java ├── Nokia.java ├── CachingBigData.java ├── Lemur.java ├── ZooWorker.java ├── Browser.java ├── Firefox.java └── Chrome.java ├── day23 ├── Environment.java ├── LoopsReview1.java ├── TernaryOperator.java ├── Primitives.java └── LoopsReview.java ├── day26 ├── Dog.java ├── Book.java ├── BookDemo.java ├── Car.java ├── PersonDemo.java ├── Person.java ├── CarDemo2.java ├── CarDemo.java └── ListReview.java ├── day9 ├── School.java ├── CarDemo.java ├── Book.java ├── Table.java ├── WarmUp.java ├── StaticKeyword.java ├── Car.java ├── RandomNumbers.java ├── Calculator.java └── MathClass2.java ├── day4 ├── LocalVariables2.java ├── Addition.java ├── Numbers.java ├── School.java ├── InputFromTerminal1.java ├── RemainderPractice.java ├── InputFromTerminal.java ├── Subtraction.java ├── Book.java ├── Student.java ├── EggBasket.java ├── ArithmeticOperators.java └── InstanceVariable.java ├── day3 ├── JavaIdentifiers.java ├── LogicalVariable.java ├── Box.java ├── Phone.java ├── Swap.java ├── MyName.java ├── CharPractice.java ├── JavaDay2Recap.java ├── MyClass.java ├── VariablesInJava3.java ├── JavaStringConcat.java ├── WholeNumber1.java ├── WholeNumber2.java ├── WholeNumbers.java ├── MilkAndJuce.java ├── FruitsFarmColors.java ├── FloatingNumber.java └── AnimalsFarm.java ├── day8 ├── HelloWorld.java ├── NumToString.java ├── Cat.java ├── Calculator1.java ├── Calculator.java ├── WarmUp.java ├── Grade.java ├── MaxNumber.java ├── AirPressure.java ├── PersonInfo.java ├── Score.java └── Account.java ├── day31 ├── Node.java ├── Node2.java ├── HashTableDemo2.java ├── TreeNode.java ├── LinkedListDemo2.java ├── FixedArray.java └── TreeDemo.java ├── day2 ├── Fruites.java ├── HelloClass.java ├── Names.java ├── ParkingLot.java ├── ProgrammingLan.java ├── Books.java ├── EscapedChars.java ├── ProgramLan.java ├── BondJamesBond.java ├── VariablesInJava1.java ├── VariablesInJava.java ├── VariablesInJava2.java └── CommentsInJava.java ├── day51 ├── CallStack.java ├── Recursion2.java ├── Recursion.java └── ReadInventoryThread.java ├── day38 ├── StoreDemo.java ├── Today.java ├── PersonDemo.java ├── SomeExceptions.java ├── ToUpperCase.java ├── Store.java ├── EvenOdd.java ├── CheckedException.java └── Person.java ├── day5 ├── TypeCasting.java ├── Division.java ├── Multiply.java ├── ArithmeticOperators1.java ├── AssignmentComp.java ├── InputFromTerminal.java ├── InputFromTerminal1.java ├── ArithmeticOperators2.java ├── ConvertStringToPrimitives.java ├── SpecAssignmentOperators.java ├── Project.java └── ArithmeticOperators.java ├── day45 ├── FileUtils.java ├── Person.java └── PersonClient.java ├── day41_2 ├── Hay.java ├── Fish.java ├── Pellets.java ├── Food.java ├── ZooKeeper.java └── FoodFactory.java ├── day6 ├── CustomMethods4.java ├── CustomMethod2.java ├── MethodExample5.java ├── EggBasket.java ├── MethodExample.java ├── Person.java └── MethodExample6.java ├── day13 ├── HelloWorld.java ├── WhileLoop.java ├── BreakAString.java ├── InfiniteLoop.java ├── WhileLoop1.java ├── WarmUp.java ├── ReverseString.java ├── Hundred.java ├── InterestRate.java └── BreakAString1.java ├── day20 ├── Assignmnet1.java ├── MinValue.java ├── MaxValue.java ├── PassByValue1.java ├── SwapValues.java ├── ArrayRecap.java ├── WarmUp.java ├── PassByValue.java ├── StringAndChars.java └── FixedSize.java ├── day17 ├── Scope.java ├── ObjectReferences.java └── Student.java ├── day50 └── Student.java ├── day24 ├── Autoboxing.java ├── ConsoleInput.java ├── String2Demo.java ├── PrefixAgain.java ├── PassByVal.java ├── String2.java ├── Assignment.java └── Varargs.java ├── day44 ├── Swap.java ├── FibonacciNumbers.java └── Words.java ├── day12 ├── TernaryOperator1.java ├── TernaryOperator.java ├── Terminal.java ├── TernaryOperator2.java ├── RGBColors.java ├── Rating.java ├── WarmUp.java ├── MultipleBirths.java └── DayOfWeek.java ├── day39 ├── ExceptionAssignment2.java ├── ExceptionAssigment1.java ├── DeleteHelper.java ├── FilePractice1.java └── FilePractice3.java ├── day10 ├── StrLength.java ├── StrCharAt.java ├── StrCount.java ├── EvenOddStr.java ├── Password.java ├── UpperAndLowerCaseStr.java ├── SecondPart.java └── StrReplace.java ├── day28 ├── BoatDemo.java ├── Boat.java ├── Varargs.java ├── Phone.java ├── PhoneDemo.java ├── SbReview.java └── ValAndRef.java ├── day19 ├── WarmUp1.java ├── Price.java ├── FirstLast.java └── WarmUp.java ├── day41 ├── ShoppingDemo2.java ├── ShoppingDemo.java ├── AnimalBuilder.java ├── AnimalBuilderDemo.java ├── ShoppingBalance.java ├── AnimalDemo.java └── ShoppingBalanceLazy.java ├── day7 ├── TwoNumbers.java ├── EvenOddInt.java ├── ConditionalBranching.java ├── CustomMethods7.java ├── ConditionalBranching1.java ├── Expample.java ├── InRange.java └── LuckyNumbers.java ├── day30 ├── WarmUp.java ├── MapWithCustomObj.java └── JavaStack.java ├── day22 ├── LinearSearch.java ├── BinarySearch.java ├── CustomObjects.java └── Teams.java ├── day25 ├── Fruits.java ├── DaysOfWeek.java ├── Phones.java └── Car.java ├── day32 ├── Student.java ├── StringReview.java ├── CustomMethods.java ├── MethodsDemo.java ├── Report.java └── ReportDemo.java ├── day16 ├── LocalVar.java └── Pyramid.java ├── day18 ├── DoubleChar.java ├── CatDog.java ├── XyzThere.java ├── EndOther.java └── CountHi.java ├── day15 ├── PrintNumbers.java ├── LuckyNumber.java ├── RecapLoops.java └── SumOfEvenNumbers.java ├── day21 └── WarmUp.java ├── day31_2 ├── Interview1.java └── ArrayListInterview.java └── day29 └── City.java /src/day40/Names: -------------------------------------------------------------------------------- 1 | John 2 | Smith 3 | Alex -------------------------------------------------------------------------------- /src/day35/I.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public interface I { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/day14/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Beknazar 3 | * 4 | */ 5 | package day14; -------------------------------------------------------------------------------- /src/day34/BMW.java: -------------------------------------------------------------------------------- 1 | package day34; 2 | 3 | public class BMW extends Car{ 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/day35/CanFly.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public interface CanFly { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/day40/Items: -------------------------------------------------------------------------------- 1 | orange=3.9 2 | banana=1.3 3 | apple=4.5 4 | bread=5.4 5 | kiwi=7.7 6 | -------------------------------------------------------------------------------- /src/day11/Grade.java: -------------------------------------------------------------------------------- 1 | package day11; 2 | 3 | public enum Grade { 4 | A, B, C, F 5 | } 6 | -------------------------------------------------------------------------------- /src/day34/USA.java: -------------------------------------------------------------------------------- 1 | package day34; 2 | 3 | public class USA extends Country { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/day35/I2.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public interface I2 extends I { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/day27/Rating.java: -------------------------------------------------------------------------------- 1 | package day27; 2 | 3 | public enum Rating { 4 | Bad, Good, Excellent 5 | } 6 | -------------------------------------------------------------------------------- /src/day37/I.java: -------------------------------------------------------------------------------- 1 | package day37; 2 | 3 | public interface I { 4 | public abstract void m(); 5 | } 6 | -------------------------------------------------------------------------------- /src/day33/Animal.java: -------------------------------------------------------------------------------- 1 | package day33; 2 | 3 | public class Animal { 4 | public int age; 5 | 6 | } 7 | -------------------------------------------------------------------------------- /src/day36/Bird.java: -------------------------------------------------------------------------------- 1 | package day36; 2 | 3 | public interface Bird { 4 | public abstract void fly(); 5 | } 6 | -------------------------------------------------------------------------------- /src/day23/Environment.java: -------------------------------------------------------------------------------- 1 | package day23; 2 | 3 | public enum Environment { 4 | DEV, TEST, ACPT, PROD 5 | } 6 | -------------------------------------------------------------------------------- /src/day37/C.java: -------------------------------------------------------------------------------- 1 | package day37; 2 | 3 | public abstract class C { 4 | public abstract void doSomething(); 5 | } 6 | -------------------------------------------------------------------------------- /src/day26/Dog.java: -------------------------------------------------------------------------------- 1 | package day26; 2 | 3 | public class Dog { 4 | // public Dog(String str) { 5 | // 6 | // } 7 | } 8 | -------------------------------------------------------------------------------- /src/day34/Country.java: -------------------------------------------------------------------------------- 1 | package day34; 2 | 3 | public class Country { 4 | public long population; 5 | public String capitalCity; 6 | } 7 | -------------------------------------------------------------------------------- /src/day35/Mammal.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public abstract class Mammal extends Animal { 4 | public abstract void drinkMilk(); 5 | } 6 | -------------------------------------------------------------------------------- /src/day36/Reptile.java: -------------------------------------------------------------------------------- 1 | package day36; 2 | 3 | public class Reptile { 4 | public String getName() { 5 | return "Reptile"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/day9/School.java: -------------------------------------------------------------------------------- 1 | package day9; 2 | 3 | public class School { 4 | public long id; 5 | public String name; 6 | public static int year; 7 | } 8 | -------------------------------------------------------------------------------- /src/day36/Phone.java: -------------------------------------------------------------------------------- 1 | package day36; 2 | 3 | public interface Phone { 4 | 5 | public abstract void ring(); 6 | 7 | public abstract String getNumber(); 8 | } 9 | -------------------------------------------------------------------------------- /src/day33/Mammal.java: -------------------------------------------------------------------------------- 1 | package day33; 2 | 3 | public class Mammal extends Animal{ 4 | 5 | public void print() { 6 | System.out.println("something"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/day35/A2.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public abstract class A2 extends A { 4 | 5 | public abstract String str(); 6 | 7 | // BREAK 10 min till 11:16am 8 | } 9 | -------------------------------------------------------------------------------- /src/day4/LocalVariables2.java: -------------------------------------------------------------------------------- 1 | package day4; 2 | 3 | public class LocalVariables2 { 4 | public static void main(String[] args) { 5 | String str = "school"; 6 | } 7 | } -------------------------------------------------------------------------------- /src/day3/JavaIdentifiers.java: -------------------------------------------------------------------------------- 1 | package day3; 2 | 3 | public class JavaIdentifiers { 4 | public static void main(String args[]) { 5 | String str = "Apple"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/day33/Circle.java: -------------------------------------------------------------------------------- 1 | package day33; 2 | 3 | public class Circle { 4 | public static double PI = 3.145345345345; 5 | public int radius; 6 | public int diameter; 7 | } 8 | -------------------------------------------------------------------------------- /src/day36/Alligator.java: -------------------------------------------------------------------------------- 1 | package day36; 2 | 3 | public class Alligator extends Reptile { 4 | @Override 5 | public String getName() { 6 | return "Alligator"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/day36/Crocodile.java: -------------------------------------------------------------------------------- 1 | package day36; 2 | 3 | public class Crocodile extends Reptile { 4 | @Override 5 | public String getName() { 6 | return "Crocodile"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/day37/E.java: -------------------------------------------------------------------------------- 1 | package day37; 2 | 3 | public class E implements I { 4 | 5 | @Override 6 | public void m() { 7 | System.out.println("In E.."); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/day8/HelloWorld.java: -------------------------------------------------------------------------------- 1 | package day8; 2 | 3 | public class HelloWorld { 4 | public static void main(String[] args) { 5 | System.out.println("Hello, World"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/day37/D.java: -------------------------------------------------------------------------------- 1 | package day37; 2 | 3 | public class D extends C { 4 | 5 | @Override 6 | public void doSomething() { 7 | System.out.println("Doing something.."); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/day31/Node.java: -------------------------------------------------------------------------------- 1 | package day31; 2 | 3 | public class Node { 4 | public int value; 5 | public Node next; 6 | 7 | public Node(int value) { 8 | this.value = value; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/day35/C.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public abstract class C { 4 | 5 | public abstract void m(); 6 | 7 | public abstract int m1(); 8 | 9 | public abstract String m2(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/day2/Fruites.java: -------------------------------------------------------------------------------- 1 | package day2; 2 | 3 | public class Fruites { 4 | public static void main(String args[]) { 5 | System.out.println("Apple, banana, orange"); 6 | System.out.println(", kiwi"); 7 | } 8 | } -------------------------------------------------------------------------------- /src/day31/Node2.java: -------------------------------------------------------------------------------- 1 | package day31; 2 | 3 | public class Node2 { 4 | public String value; 5 | public Node2 next; 6 | 7 | public Node2(String value) { 8 | this.value = value; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/day2/HelloClass.java: -------------------------------------------------------------------------------- 1 | package day2; 2 | 3 | public class HelloClass { 4 | public static void main(String args[]) { 5 | System.out.println("Hello, World!"); 6 | System.out.println("Hello, Day 3"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/day2/Names.java: -------------------------------------------------------------------------------- 1 | package day2; 2 | 3 | public class Names { 4 | public static void main(String args[]) { 5 | System.out.println("John"); 6 | System.out.println("Smith"); 7 | System.out.println("Alex"); 8 | } 9 | } -------------------------------------------------------------------------------- /src/day33/Student.java: -------------------------------------------------------------------------------- 1 | package day33; 2 | 3 | public class Student extends Person { 4 | // what Student class will get (inherit) from Person class 5 | // visible variables and methods 6 | public String courseName; 7 | } 8 | -------------------------------------------------------------------------------- /src/day2/ParkingLot.java: -------------------------------------------------------------------------------- 1 | package day2; 2 | 3 | public class ParkingLot { 4 | public static void main(String args[]) { 5 | System.out.println("You said \"Java\" ?"); 6 | System.out.println("Hmm.. It's coffee"); 7 | } 8 | 9 | } -------------------------------------------------------------------------------- /src/day3/LogicalVariable.java: -------------------------------------------------------------------------------- 1 | package day3; 2 | 3 | public class LogicalVariable { 4 | public static void main(String args[]) { 5 | boolean b = true; 6 | boolean b1 = false; 7 | 8 | boolean b3 = 5 > 3; 9 | } 10 | } -------------------------------------------------------------------------------- /src/day35/ChildDemo.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public class ChildDemo { 4 | public static void main(String[] args) { 5 | Child obj = new Child(); 6 | obj.run(); 7 | System.out.println(obj.getDetails()); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/day2/ProgrammingLan.java: -------------------------------------------------------------------------------- 1 | package day2; 2 | 3 | public class ProgrammingLan { 4 | public static void main(String args[]) { 5 | System.out.println("Java is awesome!"); 6 | System.out.println("Python is Not Bad!"); 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /src/day35/A.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public abstract class A { 4 | public String name; 5 | 6 | 7 | public void print() { 8 | System.out.println("Hello"); 9 | } 10 | 11 | public abstract int getNum(int num); 12 | } 13 | -------------------------------------------------------------------------------- /src/day35/Eagle.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public class Eagle implements CanFly { 4 | // 5 | 6 | // 7 | 8 | // 9 | 10 | public static void main(String[] args) { 11 | Eagle obj = new Eagle(); 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/day51/CallStack.java: -------------------------------------------------------------------------------- 1 | package day51; 2 | 3 | public class CallStack { 4 | public static void main(String[] args) { 5 | System.out.println(getNum()); 6 | } 7 | 8 | public static int getNum() { 9 | return 7; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/day3/Box.java: -------------------------------------------------------------------------------- 1 | package day3; 2 | 3 | public class Box { 4 | public static void main(String args[]) { 5 | String box = "flowers"; 6 | System.out.println(box); 7 | 8 | box = "books"; 9 | System.out.println(box); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/day35/B2.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public class B2 extends A2{ 4 | 5 | @Override 6 | public String str() { 7 | return "B2"; 8 | } 9 | 10 | @Override 11 | public int getNum(int num) { 12 | return num * 2; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/day38/StoreDemo.java: -------------------------------------------------------------------------------- 1 | package day38; 2 | 3 | public class StoreDemo { 4 | public static void main(String[] args) { 5 | 6 | Store obj = new Store(5); 7 | obj.addItem(0, "apple"); 8 | obj.addItem(10, "orange"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/day33/MammalDemo.java: -------------------------------------------------------------------------------- 1 | package day33; 2 | 3 | public class MammalDemo { 4 | public static void main(String[] args) { 5 | Mammal mammal = new Mammal(); 6 | 7 | // Every class in Java extends java.lang.Object class 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/day35/Car.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public abstract class Car { 4 | public double speed; 5 | 6 | public abstract void drive(); 7 | 8 | public abstract void stop(); 9 | 10 | public abstract double getSpeed(); 11 | 12 | } 13 | 14 | -------------------------------------------------------------------------------- /src/day35/Parent.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public class Parent { 4 | 5 | public void run() { 6 | System.out.println("Parent class is running"); 7 | } 8 | 9 | public String getDetails() { 10 | return "Parent class"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/day38/Today.java: -------------------------------------------------------------------------------- 1 | package day38; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | public class Today { 6 | public static void main(String[] args) { 7 | LocalDateTime now = LocalDateTime.now(); 8 | System.out.println(now); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/day33/Lion.java: -------------------------------------------------------------------------------- 1 | package day33; 2 | 3 | public class Lion extends Animal { 4 | 5 | 6 | public static void main(String[] args) { 7 | Lion lion = new Lion(); 8 | lion.age = 2; 9 | 10 | System.out.println(lion.age); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/day34/CountryDemo.java: -------------------------------------------------------------------------------- 1 | package day34; 2 | 3 | public class CountryDemo { 4 | public static void main(String[] args) { 5 | USA obj = new USA(); 6 | obj.population = 350000000; 7 | obj.capitalCity = "Washington DC"; 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/day5/TypeCasting.java: -------------------------------------------------------------------------------- 1 | package day5; 2 | 3 | public class TypeCasting { 4 | public static void main(String[] args) { 5 | double dinnerBill = 44.99; 6 | int numberOfDollars = (int) dinnerBill; 7 | System.out.println(numberOfDollars); // 44 8 | } 9 | } -------------------------------------------------------------------------------- /src/day8/NumToString.java: -------------------------------------------------------------------------------- 1 | package day8; 2 | 3 | public class NumToString { 4 | public static void main(String[] args) { 5 | int number = 599; 6 | String strNum = String.valueOf(number); 7 | System.out.println(strNum); 8 | 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/day38/PersonDemo.java: -------------------------------------------------------------------------------- 1 | package day38; 2 | 3 | public class PersonDemo { 4 | public static void main(String[] args) { 5 | Person person = new Person(); 6 | person.setAge(-10); 7 | person.setName(null); 8 | System.out.println(person); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/day4/Addition.java: -------------------------------------------------------------------------------- 1 | package day4; 2 | 3 | public class Addition { 4 | public static void main(String[] args) { 5 | int num1 = 5; 6 | int num2 = 6; 7 | int result = num1 + num2; 8 | 9 | System.out.println("Result is " + result); 10 | 11 | 12 | } 13 | } -------------------------------------------------------------------------------- /src/day45/FileUtils.java: -------------------------------------------------------------------------------- 1 | package day45; 2 | 3 | public class FileUtils { 4 | 5 | public static String readContent(String path) { 6 | return ""; 7 | } 8 | 9 | public static void writeContent(String path, String content) { 10 | 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/day35/Animal.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public abstract class Animal { 4 | public String type; 5 | 6 | public void getDetails() { 7 | System.out.println("Animal: " + type); 8 | } 9 | 10 | public abstract void run(); 11 | public abstract void eat(); 12 | } 13 | -------------------------------------------------------------------------------- /src/day36/Eagle.java: -------------------------------------------------------------------------------- 1 | package day36; 2 | 3 | public class Eagle implements Bird{ 4 | 5 | @Override 6 | public void fly() { 7 | System.out.println("Eagle is flying"); 8 | } 9 | 10 | public void hunt() { 11 | System.out.println("Eagle is hunting"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/day41_2/Hay.java: -------------------------------------------------------------------------------- 1 | package day41_2; 2 | 3 | public class Hay extends Food { 4 | 5 | public Hay(int quantity) { 6 | super(quantity); 7 | } 8 | 9 | @Override 10 | public void consumed() { 11 | System.out.println("Hay eaten: " + getQuantity()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/day3/Phone.java: -------------------------------------------------------------------------------- 1 | package day3; 2 | 3 | public class Phone { 4 | public static void main(String args[]) { 5 | String phone1, phone2; 6 | 7 | phone1 = "iphone"; 8 | phone2 = phone1; 9 | 10 | System.out.println(phone1); 11 | System.out.println(phone2); 12 | } 13 | } -------------------------------------------------------------------------------- /src/day35/Child.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public class Child extends Parent { 4 | @Override 5 | public void run() { 6 | System.out.println("Child class is running"); 7 | } 8 | 9 | @Override 10 | public String getDetails() { 11 | return "Child class"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/day36/Primate.java: -------------------------------------------------------------------------------- 1 | package day36; 2 | 3 | public class Primate { 4 | public String name; 5 | 6 | public void run() { 7 | System.out.println("Primate is running"); 8 | } 9 | 10 | public void eat() { 11 | System.out.println("Primate is eating"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/day41_2/Fish.java: -------------------------------------------------------------------------------- 1 | package day41_2; 2 | 3 | public class Fish extends Food { 4 | 5 | public Fish(int quantity) { 6 | super(quantity); 7 | } 8 | 9 | @Override 10 | public void consumed() { 11 | System.out.println("Fish eaten: " + getQuantity()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/day2/Books.java: -------------------------------------------------------------------------------- 1 | package day2; 2 | 3 | public class Books { 4 | public static void main(String[] args) { 5 | 6 | System.out.println("The 7 habits of highly effective people\nMan's search for meaning\nGetting Things Done\nThe Last Lecture\nThe 10X rule"); 7 | 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/day36/Nokia.java: -------------------------------------------------------------------------------- 1 | package day36; 2 | 3 | public class Nokia implements Phone { 4 | 5 | @Override 6 | public void ring() { 7 | System.out.println("Nokia is ringing"); 8 | } 9 | 10 | @Override 11 | public String getNumber() { 12 | return "7745126472"; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/day6/CustomMethods4.java: -------------------------------------------------------------------------------- 1 | package day6; 2 | 3 | public class CustomMethods4 { 4 | public static void main(String[] args) { 5 | String str = getAloha(); 6 | System.out.println(str); 7 | } 8 | 9 | public static String getAloha() { 10 | return "Aloha Friends!"; 11 | } 12 | } -------------------------------------------------------------------------------- /src/day41_2/Pellets.java: -------------------------------------------------------------------------------- 1 | package day41_2; 2 | 3 | public class Pellets extends Food { 4 | 5 | public Pellets(int quantity) { 6 | super(quantity); 7 | } 8 | 9 | @Override 10 | public void consumed() { 11 | System.out.println("Pellets eaten: " + getQuantity()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/day6/CustomMethod2.java: -------------------------------------------------------------------------------- 1 | package day6; 2 | 3 | public class CustomMethod2 { 4 | public static void main(String[] args) { 5 | sayAloha(); 6 | } 7 | 8 | public static void sayAloha() { 9 | System.out.println("Aloha Friends!"); 10 | } 11 | 12 | // Break till 8:14 PM EST 13 | } 14 | -------------------------------------------------------------------------------- /src/day2/EscapedChars.java: -------------------------------------------------------------------------------- 1 | package day2; 2 | 3 | public class EscapedChars { 4 | public static void main(String args[]) { 5 | System.out.println("Source Code.\nCompiler.\nJVM."); 6 | 7 | System.out.println("Source Code.\tCompiler.\tJVM."); 8 | } 9 | } 10 | 11 | // 10 min break till 8:10 PM EST -------------------------------------------------------------------------------- /src/day9/CarDemo.java: -------------------------------------------------------------------------------- 1 | package day9; 2 | 3 | public class CarDemo { 4 | public static void main(String[] args) { 5 | Car bmw = new Car(); 6 | //bmw.color = "white"; 7 | bmw.model = "bmw 325"; 8 | bmw.price = 39000.99; 9 | bmw.name = "X5"; 10 | bmw.turnLeft(); 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/day34/CatDemo.java: -------------------------------------------------------------------------------- 1 | package day34; 2 | 3 | public class CatDemo { 4 | public static void main(String[] args) { 5 | Cat cat1 = new Cat(); 6 | cat1.name = "Barsik"; 7 | 8 | Cat cat2 = new Cat(); 9 | cat2.name = "Barsik"; 10 | 11 | System.out.println(cat1.equals(cat2)); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/day35/B.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public class B extends A { 4 | 5 | @Override 6 | public int getNum(int num) { 7 | return num * num; 8 | } 9 | 10 | 11 | public static void main(String[] args) { 12 | B obj = new B(); 13 | obj.print(); 14 | 15 | obj.getNum(2); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/day35/D.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public class D extends C{ 4 | 5 | @Override 6 | public void m() { 7 | System.out.println("D"); 8 | } 9 | 10 | @Override 11 | public int m1() { 12 | return 1; 13 | } 14 | 15 | @Override 16 | public String m2() { 17 | return "D"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/day2/ProgramLan.java: -------------------------------------------------------------------------------- 1 | package day2; 2 | 3 | public class ProgramLan { 4 | public static void main(String args[]) { 5 | System.out.println("Java"); 6 | System.out.println("Python"); 7 | System.out.println("JavaScript"); 8 | System.out.println("Ruby"); 9 | System.out.println("C++"); 10 | } 11 | } -------------------------------------------------------------------------------- /src/day41_2/Food.java: -------------------------------------------------------------------------------- 1 | package day41_2; 2 | 3 | public abstract class Food { 4 | private int quantity; 5 | 6 | public Food(int quantity) { 7 | this.quantity = quantity; 8 | } 9 | 10 | public int getQuantity() { 11 | return quantity; 12 | } 13 | 14 | public abstract void consumed(); 15 | } 16 | -------------------------------------------------------------------------------- /src/day31/HashTableDemo2.java: -------------------------------------------------------------------------------- 1 | package day31; 2 | 3 | public class HashTableDemo2 { 4 | public static void main(String[] args) { 5 | HashTable names = new HashTable(); 6 | names.add("John"); 7 | names.add("Alex"); 8 | names.add("Kuzzat"); 9 | 10 | System.out.println(names); 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/day4/Numbers.java: -------------------------------------------------------------------------------- 1 | package day4; 2 | 3 | public class Numbers { 4 | public static void main(String args[]) { 5 | int num1 = Integer.parseInt(args[0]); 6 | int num2 = Integer.parseInt(args[1]); 7 | int result = num1 * num2; 8 | 9 | System.out.println(num1 + " * " + num2 + " = " + result); 10 | } 11 | } -------------------------------------------------------------------------------- /src/day5/Division.java: -------------------------------------------------------------------------------- 1 | package day5; 2 | 3 | public class Division { 4 | public static void main(String[] args) { 5 | int numOne = Integer.parseInt(args[0]); 6 | int numTwo = Integer.parseInt(args[1]); 7 | int res = numOne / numTwo; 8 | 9 | System.out.println(numOne + " / " + numTwo + " = " + res); 10 | } 11 | } -------------------------------------------------------------------------------- /src/day4/School.java: -------------------------------------------------------------------------------- 1 | package day4; 2 | 3 | public class School { 4 | public String name = "TLA"; 5 | public int students = 30; 6 | public String street = "101 Main St"; 7 | 8 | // extra code 9 | public static void main(String[] args) { 10 | School obj = new School(); 11 | System.out.println(obj.name); 12 | } 13 | } -------------------------------------------------------------------------------- /src/day13/HelloWorld.java: -------------------------------------------------------------------------------- 1 | package day13; 2 | 3 | public class HelloWorld { 4 | // Write a program that prints "Hello, World!" 100 times 5 | public static void main(String[] args) { 6 | int count = 1; 7 | while(count <= 100) { 8 | System.out.println(count + ") Hello, World!"); 9 | count++; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/day20/Assignmnet1.java: -------------------------------------------------------------------------------- 1 | package day20; 2 | 3 | public class Assignmnet1 { 4 | public static void main(String[] args) { 5 | char[] arr = {'a', 'b', 'c'}; 6 | 7 | String str = ""; 8 | 9 | for(char ch : arr) { 10 | str = str + ch; 11 | } 12 | 13 | System.out.println(str); // "abc" 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/day31/TreeNode.java: -------------------------------------------------------------------------------- 1 | package day31; 2 | 3 | public class TreeNode { 4 | public int value; 5 | 6 | public TreeNode leftChild; 7 | public TreeNode rightChild; 8 | 9 | public TreeNode(int value) { 10 | this.value = value; 11 | } 12 | 13 | public String toString() { 14 | return "Value: " + value; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/day3/Swap.java: -------------------------------------------------------------------------------- 1 | package day3; 2 | 3 | public class Swap { 4 | public static void main(String args[]) { 5 | String sky = "yellow"; 6 | String sun = "blue"; 7 | 8 | String tmp = sky; 9 | sky = sun; 10 | sun = tmp; 11 | 12 | System.out.println("Sky is " + sky); 13 | System.out.println("Sun is " + sun); 14 | } 15 | } -------------------------------------------------------------------------------- /src/day5/Multiply.java: -------------------------------------------------------------------------------- 1 | package day5; 2 | 3 | public class Multiply { 4 | public static void main(String[] args) { 5 | int numOne = Integer.parseInt(args[0]); 6 | int numTwo = Integer.parseInt(args[1]); 7 | int result = numOne * numTwo; 8 | 9 | System.out.println(numOne + " * " + numTwo + " = " + result); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/day3/MyName.java: -------------------------------------------------------------------------------- 1 | package day3; 2 | 3 | public class MyName { 4 | public static void main(String args[]) { 5 | String firstName = "Beknazar"; 6 | String lastName = "Suranchiyev"; 7 | String fullName = firstName + " " + lastName; 8 | 9 | System.out.println("Hi there, my name is " + fullName); 10 | } 11 | } 12 | // Break 10 min. Till 11:10AM -------------------------------------------------------------------------------- /src/day31/LinkedListDemo2.java: -------------------------------------------------------------------------------- 1 | package day31; 2 | 3 | public class LinkedListDemo2 { 4 | public static void main(String[] args) { 5 | LinkdList2 listNums = new LinkdList2(); 6 | listNums.add(4); 7 | listNums.add(7); 8 | listNums.add(8); 9 | listNums.add(3); 10 | listNums.add(1); 11 | 12 | System.out.println(listNums); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/day17/Scope.java: -------------------------------------------------------------------------------- 1 | package day17; 2 | 3 | public class Scope { 4 | public static void main(String[] args) { 5 | String one, two; 6 | 7 | one = new String("a"); 8 | two = new String("a"); 9 | System.out.println(one == two); 10 | 11 | String three = "a"; 12 | String four = "a"; 13 | System.out.println(three == four); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/day5/ArithmeticOperators1.java: -------------------------------------------------------------------------------- 1 | package day5; 2 | 3 | public class ArithmeticOperators1 { 4 | public static void main(String[] args) { 5 | int number = 15; 6 | int result = number / 2; 7 | System.out.println(result); // 7 8 | 9 | double dNumber = 48.0; 10 | double dResult = dNumber / 7; 11 | System.out.println(dResult); // 6.8 12 | } 13 | } -------------------------------------------------------------------------------- /src/day2/BondJamesBond.java: -------------------------------------------------------------------------------- 1 | package day2; 2 | 3 | public class BondJamesBond { 4 | public static void main(String args[]) { 5 | System.out.println("James Bond - \"I admire your courage, Miss...?\""); 6 | System.out.println("Sylvia Trench - \"Trench. Sylvia Trench. I admire your luck, Mr...?\""); 7 | System.out.println("James Bond - \"Bond. James Bond.\""); 8 | } 9 | } -------------------------------------------------------------------------------- /src/day33/StudentDemo.java: -------------------------------------------------------------------------------- 1 | package day33; 2 | 3 | public class StudentDemo { 4 | public static void main(String[] args) { 5 | Student student = new Student(); 6 | student.firstName = "Smith"; 7 | student.lastName = "Doe"; 8 | student.courseName = "Java"; 9 | 10 | System.out.println(student.firstName); 11 | student.printDetails(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/day50/Student.java: -------------------------------------------------------------------------------- 1 | package day50; 2 | 3 | public class Student extends Person { 4 | // what do you know about Object class? 5 | // Object class is parent of all the java classes 6 | 7 | 8 | public void code() { 9 | System.out.println("Coding"); 10 | } 11 | 12 | @Override 13 | public String getName() { 14 | return "Student: "; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/day3/CharPractice.java: -------------------------------------------------------------------------------- 1 | package day3; 2 | 3 | public class CharPractice { 4 | public static void main(String args[]) { 5 | char ch = 'H'; 6 | char ch1 = 'I'; 7 | 8 | System.out.println(ch); 9 | System.out.println(ch1); 10 | 11 | System.out.println(ch + 0); 12 | System.out.println(ch1 + 0); 13 | System.out.println("Chars: " + ch + ch1); 14 | } 15 | } -------------------------------------------------------------------------------- /src/day2/VariablesInJava1.java: -------------------------------------------------------------------------------- 1 | package day2; 2 | 3 | public class VariablesInJava1 { 4 | public static void main(String args[]) { 5 | String firstName = "John"; 6 | String lastName = "Doe"; 7 | 8 | System.out.println(firstName + " " + lastName); 9 | 10 | 11 | String fullName = firstName + " " + lastName; 12 | System.out.println(fullName); 13 | 14 | } 15 | } -------------------------------------------------------------------------------- /src/day20/MinValue.java: -------------------------------------------------------------------------------- 1 | package day20; 2 | 3 | public class MinValue { 4 | public static void main(String[] args) { 5 | int[] arr = {45, 2, 1, 100, 60, 78, 290, 3, 5, -1, 9, -8}; 6 | int min = arr[0]; 7 | 8 | for(int number : arr) { 9 | if(number < min) { 10 | min = number; 11 | } 12 | } 13 | 14 | System.out.println(min); // -1 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/day35/Audi.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public class Audi extends Car { 4 | 5 | @Override 6 | public void drive() { 7 | System.out.println("Audi is driving."); 8 | } 9 | 10 | @Override 11 | public void stop() { 12 | System.out.println("Audi is stopped."); 13 | } 14 | 15 | @Override 16 | public double getSpeed() { 17 | return speed; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/day36/CachingBigData.java: -------------------------------------------------------------------------------- 1 | package day36; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | public class CachingBigData { 7 | public static void main(String[] args) { 8 | Set data = new HashSet2(); 9 | 10 | data.add("sdfsd"); 11 | 12 | // .. 13 | // .. 14 | // more code 15 | // 16 | 17 | data.clear(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/day24/Autoboxing.java: -------------------------------------------------------------------------------- 1 | package day24; 2 | 3 | public class Autoboxing { 4 | public static void main(String[] args) { 5 | char ch = 'o'; 6 | 7 | // Autoboxing - primitive char to Character object 8 | Character chW = ch; 9 | 10 | int num = 992; 11 | Integer num1 = num; 12 | 13 | // Unboxing 14 | Integer num2 = 100; 15 | int num3 = num2; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/day26/Book.java: -------------------------------------------------------------------------------- 1 | package day26; 2 | 3 | public class Book { 4 | public String title; 5 | public int numberOfPages; 6 | 7 | public Book(String title) { 8 | this.title = title; 9 | } 10 | 11 | public Book(String title, int numberOfPages) { 12 | this.title = title; 13 | this.numberOfPages = numberOfPages; 14 | } 15 | 16 | public Book() { 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/day35/Ox.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public class Ox extends Mammal { 4 | @Override 5 | public void run() { 6 | System.out.println("Ox is running"); 7 | } 8 | 9 | @Override 10 | public void eat() { 11 | System.out.println("Ox is eating"); 12 | } 13 | 14 | @Override 15 | public void drinkMilk() { 16 | System.out.println("drinking.."); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/day36/Lemur.java: -------------------------------------------------------------------------------- 1 | package day36; 2 | 3 | public class Lemur extends Primate { 4 | public void climb() { 5 | System.out.println("Lemur is climbing"); 6 | } 7 | 8 | @Override 9 | public void run() { 10 | System.out.println("Lemur is running"); 11 | } 12 | 13 | @Override 14 | public void eat() { 15 | System.out.println("Lemur is eating"); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/day37/Chocolate.java: -------------------------------------------------------------------------------- 1 | package day37; 2 | 3 | public class Chocolate { 4 | public static String ch1; 5 | public String ch2; 6 | 7 | static { 8 | System.out.println("inside static block"); 9 | } 10 | 11 | { 12 | System.out.println("inside initializer block"); 13 | } 14 | 15 | public Chocolate() { 16 | System.out.println("inside constractor"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/day41_2/ZooKeeper.java: -------------------------------------------------------------------------------- 1 | package day41_2; 2 | 3 | public class ZooKeeper { 4 | public static void main(String[] args) { 5 | Food food = FoodFactory.getFood("polar bear"); 6 | food.consumed(); 7 | 8 | Food food1 = FoodFactory.getFood("zebra"); 9 | food1.consumed(); 10 | 11 | // Food food2 = FoodFactory.getFood("tiger"); 12 | // food2.consumed(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/day51/Recursion2.java: -------------------------------------------------------------------------------- 1 | package day51; 2 | 3 | public class Recursion2 { 4 | public static void main(String[] args) { 5 | System.out.println(fact(15)); 6 | } 7 | 8 | public static int fact(int num) { 9 | // Base case 10 | if(num == 1) { 11 | return 1; 12 | 13 | }else { 14 | 15 | // recursion case 16 | return num * fact(num - 1); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/day8/Cat.java: -------------------------------------------------------------------------------- 1 | package day8; 2 | 3 | import day9.Car; 4 | 5 | public class Cat { 6 | public String name; 7 | public int age; 8 | 9 | public static void main(String[] args) { 10 | Car car = new Car(); 11 | car.model = "audi"; 12 | car.drive(); 13 | 14 | //car.turnLeft(); 15 | //car.name = "Q6"; 16 | //car.year = 2020; 17 | //car.price = 39000.99; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/day20/MaxValue.java: -------------------------------------------------------------------------------- 1 | package day20; 2 | 3 | public class MaxValue { 4 | public static void main(String[] args) { 5 | int[] arr = {45, 2, 1, 100, 60, 78, 290, 3, 5, 1, 9, 8}; 6 | int max = arr[0]; 7 | 8 | for(int num : arr) { 9 | // 8 > 290 10 | if(num > max) { 11 | // 290 12 | max = num; 13 | } 14 | } 15 | 16 | System.out.println(max); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/day34/Car.java: -------------------------------------------------------------------------------- 1 | package day34; 2 | 3 | public class Car{ 4 | public String model; 5 | public double price; 6 | 7 | protected void drive() { 8 | System.out.println("Car(" + model + ") is driving"); 9 | } 10 | 11 | public Car(String model) { 12 | System.out.println("Inside parent const"); 13 | this.model = model; 14 | } 15 | 16 | public Car() { 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/day44/Swap.java: -------------------------------------------------------------------------------- 1 | package day44; 2 | 3 | public class Swap { 4 | public static void main(String[] args) { 5 | int i = 10; 6 | int j = 15; 7 | 8 | j = j - i; // j = 15 - 10 -> j = 5 9 | i = i + j; // i = 10 + 5 -> i = 15 10 | j = i - j; // j = 15 - 5 -> j = 10 11 | 12 | System.out.println("i = " + i); // 15 13 | System.out.println("j = " + j); // 10 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/day24/ConsoleInput.java: -------------------------------------------------------------------------------- 1 | package day24; 2 | import java.util.Scanner; 3 | 4 | public class ConsoleInput { 5 | private Scanner scanner; 6 | 7 | public ConsoleInput() { 8 | scanner = new Scanner(System.in); 9 | } 10 | 11 | public String getStr() { 12 | return scanner.next(); 13 | } 14 | 15 | public String next() { 16 | return scanner.next(); 17 | } 18 | 19 | //.. 20 | } 21 | -------------------------------------------------------------------------------- /src/day26/BookDemo.java: -------------------------------------------------------------------------------- 1 | package day26; 2 | 3 | public class BookDemo { 4 | public static void main(String[] args) { 5 | Book oca = new Book("OCA"); 6 | System.out.println(oca.title); // OCA 7 | 8 | Book ocp = new Book("OCP", 500); 9 | System.out.println(ocp.title); // OCP 10 | System.out.println(ocp.numberOfPages); // 500 11 | 12 | Book obj = new Book(); 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/day3/JavaDay2Recap.java: -------------------------------------------------------------------------------- 1 | package day3; 2 | 3 | public class JavaDay2Recap { 4 | public static void main(String args[]){ 5 | System.out.println("1. SOURCE CODE -> COMPILER -> JAVA BYTE CODE"); 6 | System.out.println("2. javac fileName.java to compile source code. it will produce java byte code (with .class extension)"); 7 | System.out.println("3. java fileName to execute java byte code"); 8 | } 9 | } -------------------------------------------------------------------------------- /src/day35/BMW.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public class BMW extends Car{ 4 | // implement - override 5 | 6 | @Override 7 | public void drive() { 8 | System.out.println("BMW is driving"); 9 | } 10 | 11 | @Override 12 | public void stop() { 13 | System.out.println("BMW is stopped"); 14 | } 15 | 16 | @Override 17 | public double getSpeed() { 18 | return speed; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/day4/InputFromTerminal1.java: -------------------------------------------------------------------------------- 1 | package day4; 2 | 3 | public class InputFromTerminal1 { 4 | public static void main(String[] args) { 5 | String name = args[0]; 6 | //int age = args[1]; 7 | int age = Integer.parseInt(args[1]); 8 | 9 | // make him older by 1 year 10 | age = age + 1; 11 | 12 | System.out.println("Name: " + name); 13 | System.out.println("Age: " + age); 14 | } 15 | } -------------------------------------------------------------------------------- /src/day12/TernaryOperator1.java: -------------------------------------------------------------------------------- 1 | package day12; 2 | 3 | public class TernaryOperator1 { 4 | public static void main(String[] args) { 5 | boolean isEven = isEven(4); 6 | 7 | String str = isEven ? "Number is even" : "Number is odd"; 8 | 9 | System.out.println(str); // Number is odd 10 | } 11 | 12 | public static boolean isEven(int number) { 13 | return number % 2 == 0; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/day39/ExceptionAssignment2.java: -------------------------------------------------------------------------------- 1 | package day39; 2 | 3 | import java.io.IOException; 4 | 5 | public class ExceptionAssignment2 { 6 | public static void main(String[] args) { 7 | try { 8 | m(); 9 | }catch(IOException e) { 10 | System.out.println("Exception is handled"); 11 | } 12 | } 13 | 14 | public static void m() throws IOException { 15 | throw new IOException(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/day4/RemainderPractice.java: -------------------------------------------------------------------------------- 1 | package day4; 2 | 3 | public class RemainderPractice { 4 | public static int num; 5 | 6 | public static void main(String[] args) { 7 | 8 | num = 3; 9 | System.out.println(7 % num); // 1 10 | System.out.println(19 % num); // 1 11 | System.out.println(12 % num); // 0 12 | System.out.println(99 % num); // 0 13 | System.out.println(47 % num); // 2 14 | } 15 | } -------------------------------------------------------------------------------- /src/day5/AssignmentComp.java: -------------------------------------------------------------------------------- 1 | package day5; 2 | 3 | public class AssignmentComp { 4 | public static void main(String[] args) { 5 | // byte -> short -> int -> long -> float -> double 6 | 7 | byte b = 25; 8 | // auto casting 9 | short sh = b; 10 | int num = sh; 11 | long l = num; 12 | 13 | double d1 = l; 14 | 15 | 16 | long lNum = 100; 17 | int num2 = (int)lNum; 18 | 19 | 20 | } 21 | } -------------------------------------------------------------------------------- /src/day12/TernaryOperator.java: -------------------------------------------------------------------------------- 1 | package day12; 2 | 3 | public class TernaryOperator { 4 | public static void main(String[] args) { 5 | int y = 10; 6 | int x; 7 | 8 | if(y > 5) { 9 | x = y * 2; 10 | }else { 11 | x = y * 3; 12 | } 13 | System.out.println(x); 14 | 15 | // F ? 10 * 2 : 10 * 3 16 | x = (y > 5) ? (y * 2) : (y * 3); 17 | System.out.println(x); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/day45/Person.java: -------------------------------------------------------------------------------- 1 | package day45; 2 | 3 | public class Person { 4 | String name; 5 | int age; 6 | 7 | public Person(String name, int age) { 8 | this.name = name; 9 | this.age = age; 10 | } 11 | 12 | public Person() {} 13 | 14 | public void increaseAgeBy(int by) { 15 | age = age + by; 16 | } 17 | 18 | public String nameAsUpperCase() { 19 | return name.toUpperCase(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/day10/StrLength.java: -------------------------------------------------------------------------------- 1 | package day10; 2 | 3 | public class StrLength { 4 | public static void main(String[] args) { 5 | // .length() method returns number of letters in the word(string) 6 | 7 | String str = "Invaluable"; 8 | 9 | int strLength = str.length(); 10 | 11 | System.out.println(strLength); 12 | 13 | str = "Car"; 14 | System.out.println(str.length()); 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/day2/VariablesInJava.java: -------------------------------------------------------------------------------- 1 | package day2; 2 | 3 | public class VariablesInJava { 4 | public static void main(String args[]) { 5 | String firstName; 6 | 7 | firstName = "John"; 8 | // concatenation 9 | System.out.println("Hello " + firstName); 10 | 11 | firstName = "Beknazar"; 12 | System.out.println(firstName); 13 | 14 | firstName = "Alex"; 15 | System.out.println(firstName); 16 | 17 | } 18 | } -------------------------------------------------------------------------------- /src/day28/BoatDemo.java: -------------------------------------------------------------------------------- 1 | package day28; 2 | 3 | public class BoatDemo { 4 | public static void main(String[] args) { 5 | Boat boat = new Boat(); 6 | boat.setName("Yamaha"); 7 | boat.setColor("Red"); 8 | 9 | // String str = boat.getName() + "Hellp"; 10 | 11 | System.out.println(boat.getName()); 12 | System.out.println(boat.getColor()); 13 | 14 | // BREAK 10 min till 2:12 PM 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/day3/MyClass.java: -------------------------------------------------------------------------------- 1 | package day3; 2 | 3 | public class MyClass { 4 | public static void main(String args[]) { 5 | String student1 = "Anna"; 6 | String student2 = "Ari"; 7 | String student3 = "Rocio"; 8 | String student4 = "Selvin"; 9 | String student5 = "Frank"; 10 | 11 | String javaClass = student1 + student2 + student3 + student4 + student5; 12 | 13 | System.out.println(javaClass); 14 | } 15 | } -------------------------------------------------------------------------------- /src/day34/CarDemo.java: -------------------------------------------------------------------------------- 1 | package day34; 2 | 3 | public class CarDemo { 4 | public static void main(String[] args) { 5 | BMW car1 = new BMW(); 6 | car1.model = "325i"; 7 | car1.price = 30000.0; 8 | car1.drive(); 9 | 10 | System.out.println("-------"); 11 | Ferrari car2 = new Ferrari(); 12 | car2.model = "812 GTS"; 13 | car2.price = 380000; 14 | car2.drive(); 15 | car2.test(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/day3/VariablesInJava3.java: -------------------------------------------------------------------------------- 1 | package day3; 2 | 3 | public class VariablesInJava3 { 4 | public static void main(String args[]) { 5 | String str = "book"; 6 | System.out.println(str); 7 | 8 | str = "phone"; 9 | System.out.println(str); 10 | 11 | // "phone - iphone" 12 | str = str + " - iphone"; 13 | System.out.println(str); 14 | 15 | str = str +" "+ str; 16 | System.out.println(str); 17 | } 18 | } -------------------------------------------------------------------------------- /src/day35/CarDemo.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public class CarDemo { 4 | public static void main(String[] args) { 5 | // Car car = new Car(); we cannot create object from abstract 6 | // class directly 7 | 8 | Audi car = new Audi(); 9 | car.drive(); 10 | car.stop(); 11 | car.getSpeed(); 12 | 13 | Car car1 = new Audi(); 14 | car1.drive(); 15 | car1.stop(); 16 | car1.getSpeed(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/day4/InputFromTerminal.java: -------------------------------------------------------------------------------- 1 | package day4; 2 | 3 | public class InputFromTerminal { 4 | public static void main(String[] args) { 5 | String name = args[0]; 6 | String age = args[1]; 7 | String country = args[2]; 8 | 9 | System.out.println("Hello, " + name + "!"); 10 | System.out.println("Name: " + name); 11 | System.out.println("Age: " + age); 12 | System.out.println("Country: " + country); 13 | } 14 | } -------------------------------------------------------------------------------- /src/day4/Subtraction.java: -------------------------------------------------------------------------------- 1 | package day4; 2 | 3 | public class Subtraction { 4 | public static void main(String[] args) { 5 | int num1 = 78; 6 | int num2 = 43; 7 | int result = num1 - num2; 8 | 9 | System.out.println("Result is " + result); 10 | 11 | 12 | 13 | // // 76 = 38 * 2 14 | // result = result * 2; 15 | // System.out.println(result); 16 | 17 | // Break till 10:10 AM EST 18 | } 19 | } -------------------------------------------------------------------------------- /src/day19/WarmUp1.java: -------------------------------------------------------------------------------- 1 | package day19; 2 | 3 | public class WarmUp1 { 4 | public static void main(String[] args) { 5 | // 012345 6 | String str = "Status"; 7 | 8 | String strRev = ""; 9 | // -1 >= 0 10 | for(int i = str.length() - 1; i >= 0 ; i--) { 11 | //sutatS 12 | strRev = strRev + str.charAt(i); 13 | } 14 | 15 | System.out.println(strRev); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/day35/PhoneDemo.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public class PhoneDemo { 4 | public static void main(String[] args) { 5 | Phone obj = new Phone(); 6 | obj.setName1("Iphone"); 7 | obj.setName2("Nokia"); 8 | 9 | StringBuilder sb = new StringBuilder("apple"); 10 | 11 | sb.append("a").append("absfsd").append("sdfsd"); 12 | 13 | // .... 14 | 15 | 16 | sb.append("sdfsd").append("sdf"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/day36/ZooWorker.java: -------------------------------------------------------------------------------- 1 | package day36; 2 | 3 | public class ZooWorker { 4 | public static void main(String[] args) { 5 | Reptile r = new Reptile(); 6 | feed(r); 7 | 8 | Crocodile c = new Crocodile(); 9 | feed(c); 10 | 11 | Alligator a = new Alligator(); 12 | feed(a); 13 | } 14 | 15 | public static void feed(Reptile reptile) { 16 | System.out.println("Feeding " + reptile.getName()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/day40/StoreSeller.java: -------------------------------------------------------------------------------- 1 | package day40; 2 | 3 | public class StoreSeller { 4 | public static void main(String[] args) { 5 | Store seller = new Store(); 6 | System.out.println(seller.getItems()); 7 | 8 | seller.addItem("apple", 4.5); 9 | seller.addItem("orange", 3.9); 10 | seller.addItem("banana", 1.3); 11 | System.out.println(seller.getItems()); 12 | 13 | seller.addItem("kiwi", 7.7); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/day14/DoWhile.java: -------------------------------------------------------------------------------- 1 | package day14; 2 | 3 | public class DoWhile { 4 | public static void main(String[] args) { 5 | int count = 0; 6 | 7 | while (count < 100) { 8 | System.out.print(count + " "); 9 | count++; 10 | } 11 | 12 | System.out.println("\n"); 13 | 14 | int count1 = 0; 15 | do { 16 | System.out.print(count1 + " "); 17 | count1++; 18 | 19 | } while(count1 < 100); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/day39/ExceptionAssigment1.java: -------------------------------------------------------------------------------- 1 | package day39; 2 | 3 | public class ExceptionAssigment1 { 4 | public static void main(String[] args) { 5 | // Use try catch statement to handle the exc 6 | try { 7 | m(); 8 | }catch(IllegalArgumentException e) { 9 | System.out.println("Exception is handled!"); 10 | } 11 | 12 | } 13 | 14 | public static void m() { 15 | throw new IllegalArgumentException(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/day28/Boat.java: -------------------------------------------------------------------------------- 1 | package day28; 2 | 3 | // Beans or POJO 4 | public class Boat { 5 | private String name; 6 | private String color; 7 | 8 | public String getName() { 9 | return name; 10 | } 11 | 12 | public void setName(String name) { 13 | this.name = name; 14 | } 15 | 16 | public String getColor() { 17 | return color; 18 | } 19 | 20 | public void setColor(String color) { 21 | this.color = color; 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /src/day37/ChocolateDemo.java: -------------------------------------------------------------------------------- 1 | package day37; 2 | 3 | public class ChocolateDemo { 4 | public static void main(String[] args) { 5 | // String str = Chocolate.ch1; 6 | 7 | Chocolate obj = new Chocolate(); 8 | 9 | Chocolate obj1 = new Chocolate(); 10 | 11 | // Chocolate obj2= new Chocolate(); 12 | 13 | // static block 14 | // init block 15 | // constructor 16 | // init block 17 | // constructor 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/day41/ShoppingDemo2.java: -------------------------------------------------------------------------------- 1 | package day41; 2 | 3 | public class ShoppingDemo2 { 4 | public static void main(String[] args) { 5 | ShoppingBalanceLazy wife = ShoppingBalanceLazy.getInstance(); 6 | wife.buy("head phone", 300.00); 7 | 8 | ShoppingBalanceLazy husband = ShoppingBalanceLazy.getInstance(); 9 | husband.buy("phone", 500.00); 10 | husband.buy("charger", 40.00); 11 | 12 | wife.buy("phone case", 25.00); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/day7/TwoNumbers.java: -------------------------------------------------------------------------------- 1 | package day7; 2 | 3 | public class TwoNumbers { 4 | public static void main(String[] args) { 5 | int numberOne = Integer.parseInt(args[0]); 6 | int numberTwo = Integer.parseInt(args[1]); 7 | 8 | if( numberOne == numberTwo) { 9 | System.out.println(numberOne + " and " + numberTwo + " are equal"); 10 | } else { 11 | System.out.println(numberOne + " and " + numberTwo + " are not equal"); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /src/day2/VariablesInJava2.java: -------------------------------------------------------------------------------- 1 | package day2; 2 | 3 | public class VariablesInJava2 { 4 | public static void main(String args[]) { 5 | String firstName, lastName, fullName; 6 | 7 | firstName = "John"; 8 | lastName = "Doe"; 9 | fullName = firstName + " " + lastName; 10 | 11 | System.out.println("First name: " + firstName); 12 | System.out.println("Last name: " + lastName); 13 | System.out.println("Full name: " + fullName); 14 | } 15 | } -------------------------------------------------------------------------------- /src/day31/FixedArray.java: -------------------------------------------------------------------------------- 1 | package day31; 2 | 3 | public class FixedArray { 4 | public static void main(String[] args) { 5 | int[] nums = new int[3]; 6 | nums[0] = 1; 7 | nums[1] = 2; 8 | nums[2] = 3; 9 | // ... 10 | 11 | 12 | int[] nums1 = new int[4]; 13 | 14 | for(int i = 0; i < nums.length; i++) { 15 | nums1[i] = nums[i]; 16 | } 17 | 18 | nums1[3] = 4; 19 | 20 | nums = nums1; 21 | 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/day5/InputFromTerminal.java: -------------------------------------------------------------------------------- 1 | package day5; 2 | 3 | public class InputFromTerminal { 4 | public static void main(String[] args) { 5 | // java InputFromTerminal 34 90 6 | // 34 + 90 = 124 7 | 8 | int numberOne = Integer.parseInt(args[0]); 9 | int numberTwo = Integer.parseInt(args[1]); 10 | int sum = numberOne + numberTwo; 11 | 12 | System.out.println(numberOne + " + " + numberTwo + " = " + sum); 13 | // BREAK 10 min 9:10 PM EST 14 | } 15 | } -------------------------------------------------------------------------------- /src/day27/EmployeeDemo.java: -------------------------------------------------------------------------------- 1 | package day27; 2 | 3 | public class EmployeeDemo { 4 | public static void main(String[] args) { 5 | Employee emp1 = new Employee(); 6 | 7 | emp1.setFirstname("John"); 8 | emp1.setLastname("Doe"); 9 | 10 | //emp1.age = -100; 11 | 12 | emp1.setAge(-100); 13 | 14 | System.out.println(emp1.getFirstname()); 15 | System.out.println(emp1.getAge()); 16 | System.out.println(emp1.getFirstname()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/day28/Varargs.java: -------------------------------------------------------------------------------- 1 | package day28; 2 | 3 | public class Varargs { 4 | public static void main(String[] args) { 5 | printLines("Hello"); 6 | 7 | printLines("Good", "Morning"); 8 | 9 | printLines("A", "B", "C"); 10 | 11 | printLines("1", "2", "3"); 12 | 13 | } 14 | 15 | public static void printLines(String ... strings) { 16 | for(int i = 0; i < strings.length; i++) { 17 | System.out.println(strings[i]); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/day3/JavaStringConcat.java: -------------------------------------------------------------------------------- 1 | package day3; 2 | 3 | public class JavaStringConcat { 4 | public static void main(String args[]) { 5 | String str = "Hello"; 6 | String str1 = "World"; 7 | String str2 = str + str1; 8 | 9 | System.out.println(str2); // HelloWorld 10 | 11 | str2 = str1; 12 | System.out.println(str2); // World 13 | 14 | // "World" + "Hello 15 | str1 = str2 + str; 16 | System.out.println(str1); // WorldHello 17 | } 18 | } -------------------------------------------------------------------------------- /src/day3/WholeNumber1.java: -------------------------------------------------------------------------------- 1 | package day3; 2 | 3 | public class WholeNumber1 { 4 | public static void main(String args[]) { 5 | byte b = 13; 6 | int num = b; 7 | // 13 8 | System.out.println(num); 9 | 10 | int num1 = 12; 11 | byte b2 = (byte)num1; 12 | System.out.println(b2); 13 | 14 | // for whole numbers we have 15 | // byte -> short -> int -> long 16 | 17 | short num2 = 1234; 18 | 19 | long l = 413434; 20 | } 21 | } -------------------------------------------------------------------------------- /src/day30/WarmUp.java: -------------------------------------------------------------------------------- 1 | package day30; 2 | 3 | public class WarmUp { 4 | public static void main(String[] args) { 5 | String str = "John"; 6 | str = reverseStr(str); 7 | 8 | System.out.println(str); // olleh 9 | } 10 | 11 | public static String reverseStr(String str) { 12 | String rev = ""; 13 | 14 | // hello 15 | for(int i = str.length() - 1; i >= 0; i--) { 16 | rev += str.charAt(i); 17 | } 18 | 19 | return rev; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/day2/CommentsInJava.java: -------------------------------------------------------------------------------- 1 | package day2; 2 | 3 | public class CommentsInJava { 4 | public static void main(String args[]) { 5 | 6 | // this code will be connection to db 7 | System.out.println("Very complicated code starting.."); 8 | 9 | 10 | // disconect from db 11 | 12 | // System.out.println("hi"); 13 | 14 | /** 15 | Some more comments here.. 16 | **/ 17 | 18 | /* 19 | 20 | System.out.println("hi"); 21 | 22 | */ 23 | 24 | } 25 | } -------------------------------------------------------------------------------- /src/day14/HelloWorld.java: -------------------------------------------------------------------------------- 1 | package day14; 2 | 3 | public class HelloWorld { 4 | 5 | public static void main(String[] args) { 6 | // write a program that will print "Hello World" 10 times, each in new line 7 | // use for loop 8 | // send me your code in the slack 9 | 10 | // i++ -> increase value by 1 11 | // i = i + 1; 12 | 13 | // 10 < 10 14 | for(int i = 0; i < 10; i++) { 15 | System.out.println("Hello World"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/day45/PersonClient.java: -------------------------------------------------------------------------------- 1 | package day45; 2 | 3 | import java.util.Arrays; 4 | 5 | public class PersonClient { 6 | public static void main(String[] args) { 7 | String person = "name: John, age: 7"; 8 | 9 | Person perObj = new Person("John", 7); 10 | perObj.increaseAgeBy(10); 11 | 12 | Person perTwo = new Person(); 13 | perTwo.name = "Alex"; 14 | perTwo.age = 10; 15 | 16 | FileUtils.readContent("Dsesktop/test.txt"); 17 | 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/day3/WholeNumber2.java: -------------------------------------------------------------------------------- 1 | package day3; 2 | 3 | public class WholeNumber2 { 4 | public static void main(String args[]) { 5 | int num = 100; 6 | 7 | System.out.println("Number: " + num); 8 | 9 | // your code goes here 10 | num = 200; 11 | System.out.println("Number: " + num); 12 | 13 | // your code goes here. Increase num by 30 14 | 15 | num = num + 30; 16 | // 230 17 | System.out.println("Number: " + num); 18 | 19 | //BREAK 10 MIN. TILL 2:18 20 | } 21 | } -------------------------------------------------------------------------------- /src/day13/WhileLoop.java: -------------------------------------------------------------------------------- 1 | package day13; 2 | 3 | public class WhileLoop { 4 | public static void main(String[] args) { 5 | int count = 1; 6 | 7 | // 10 >= 11 -> false 8 | while(10 >= count) { 9 | // 10 10 | System.out.println(count); 11 | count++; // count = count + 1; 12 | 13 | } 14 | 15 | System.out.println("Here: "+count); // 11 16 | 17 | // while(boolean_expression) { 18 | // body of the loop 19 | // } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/day27/Student.java: -------------------------------------------------------------------------------- 1 | package day27; 2 | 3 | public class Student { 4 | private long studentId; 5 | private String department; 6 | 7 | public long getStudentId() { 8 | return studentId; 9 | } 10 | 11 | public void setStudentId(long studentId) { 12 | this.studentId = studentId; 13 | } 14 | 15 | public String getDepartment() { 16 | return department; 17 | } 18 | 19 | public void setDepartment(String department) { 20 | this.department = department; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/day35/Dog.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public class Dog { 4 | public String name; 5 | public String ownerName; 6 | 7 | public Dog(String name, String ownerName) { 8 | System.out.println("Inside constructor"); 9 | this.name = name; 10 | this.ownerName = ownerName; 11 | } 12 | 13 | public Dog(String name) { 14 | this.name = name; 15 | } 16 | 17 | public Dog() { 18 | this("Sharik", "John"); 19 | System.out.println("Inside empty constructor"); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/day17/ObjectReferences.java: -------------------------------------------------------------------------------- 1 | package day17; 2 | 3 | public class ObjectReferences { 4 | public static void main(String[] args) { 5 | StringBuilder sbA = new StringBuilder("abc"); 6 | StringBuilder sbB = sbA; 7 | 8 | sbB.append("d"); 9 | System.out.println("sbA: " + sbA); // abcd 10 | System.out.println("sbB: " + sbB); // abcd 11 | 12 | sbA.append("ef"); 13 | System.out.println("sbA: " + sbA); // abcdef 14 | System.out.println("sbB: " + sbB); // abcdef 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/day4/Book.java: -------------------------------------------------------------------------------- 1 | package day4; 2 | 3 | public class Book { 4 | private static String title = "Java OCA"; 5 | private static int numberOfPages = 400; 6 | private static double price = 29.99; 7 | 8 | public static void main(String[] args) { 9 | 10 | System.out.println("Title: " + title); 11 | System.out.println("Pages: " + numberOfPages); 12 | System.out.println("Price: " + price); 13 | 14 | title = "Clean Code"; 15 | numberOfPages = 350; 16 | price = 49.99; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/day9/Book.java: -------------------------------------------------------------------------------- 1 | package day9; 2 | 3 | public class Book { 4 | public long id; 5 | public String title; 6 | public String author; 7 | public int pages; 8 | 9 | public void read() { 10 | System.out.println("Reading.. " + title); 11 | } 12 | 13 | public void printDetails() { 14 | System.out.println("Book ID: " + id); 15 | System.out.println(title); 16 | System.out.println(author); 17 | System.out.println(pages); 18 | System.out.println("------------"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/day22/LinearSearch.java: -------------------------------------------------------------------------------- 1 | package day22; 2 | 3 | public class LinearSearch { 4 | public static void main(String[] args) { 5 | 6 | String[] strNum = {"One", "Two", "Three", "Four", "Five"}; 7 | System.out.println(search("Three", strNum)); 8 | 9 | } 10 | 11 | public static int search(String key, String[] strArr) { 12 | 13 | for(int i = 0; i < strArr.length; i++) { 14 | if(strArr[i].equals(key)) { 15 | return i; 16 | } 17 | } 18 | 19 | return -1; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/day25/Fruits.java: -------------------------------------------------------------------------------- 1 | package day25; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Fruits { 6 | public static void main(String[] args) { 7 | ArrayList fruits = new ArrayList<>(); 8 | fruits.add("Orange"); 9 | fruits.add("Apple"); 10 | fruits.add("Banana"); 11 | fruits.add("Kiwi"); 12 | 13 | System.out.println(fruits.get(0)); 14 | System.out.println(fruits.get(1)); 15 | System.out.println(fruits.get(2)); 16 | System.out.println(fruits.get(3)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/day23/LoopsReview1.java: -------------------------------------------------------------------------------- 1 | package day23; 2 | 3 | public class LoopsReview1 { 4 | public static void main(String[] args) { 5 | 6 | boolean b = false; 7 | 8 | // while loop might have 0 iterations 9 | while(b) { 10 | System.out.println("Hello"); 11 | break; 12 | 13 | // .. 14 | // .. 15 | } 16 | 17 | // do while loop will have at least one iteration 18 | do { 19 | System.out.println("Hello, World!"); 20 | // .. 21 | // .. 22 | } while(b); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/day3/WholeNumbers.java: -------------------------------------------------------------------------------- 1 | package day3; 2 | 3 | public class WholeNumbers { 4 | public static void main(String args[]) { 5 | int age = 30; 6 | System.out.println(age); 7 | 8 | age = 25; 9 | System.out.println(age); 10 | 11 | age = age + 10; 12 | System.out.println(age); 13 | 14 | byte num = 120; 15 | System.out.println(num); 16 | 17 | short num1 = 12321; 18 | System.out.println(num1); 19 | 20 | long bigNumber = 300000000000L; 21 | System.out.println(bigNumber); 22 | } 23 | } -------------------------------------------------------------------------------- /src/day38/SomeExceptions.java: -------------------------------------------------------------------------------- 1 | package day38; 2 | 3 | public class SomeExceptions { 4 | public static void main(String[] args) { 5 | 6 | // NullPointerException will come object is null 7 | // and we are trying to use some methods or instance variables 8 | //String str = null; 9 | String str = "appel"; 10 | str = str.toLowerCase(); 11 | 12 | String strNum = "432hj"; 13 | int num = Integer.parseInt(strNum); 14 | 15 | String str1 = "apple"; 16 | str1.charAt(7); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/day12/Terminal.java: -------------------------------------------------------------------------------- 1 | package day12; 2 | 3 | public class Terminal { 4 | private static final boolean isWindows = System.getProperty("os.name").toLowerCase().contains("windows"); 5 | 6 | public static void main(String[] args) { 7 | // boolean isWindows = true; 8 | 9 | String terminalToUse = isWindows ? "GitBush Terminal" : "Regular Terminal"; 10 | System.out.println(terminalToUse); 11 | 12 | String message = System.getProperty("os.name"); 13 | System.out.println(message); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/day5/InputFromTerminal1.java: -------------------------------------------------------------------------------- 1 | package day5; 2 | 3 | public class InputFromTerminal1 { 4 | public static void main(String[] args) { 5 | String strNumOne = args[0]; 6 | String strNumTwo = args[1]; 7 | // 5.6 <- "5.6" 8 | double numberOne = Double.parseDouble(strNumOne); 9 | double numberTwo = Double.parseDouble(strNumTwo); 10 | double result = numberOne - numberTwo; 11 | 12 | System.out.println(numberOne + " - " + numberTwo + " = " + result); 13 | 14 | } 15 | } -------------------------------------------------------------------------------- /src/day4/Student.java: -------------------------------------------------------------------------------- 1 | package day4; 2 | 3 | public class Student { 4 | 5 | 6 | public static void main(String[] args) { 7 | String name = "John Doe"; 8 | double grade = 70.5; 9 | 10 | System.out.println("Student name is " + name); 11 | System.out.println("Student grade is " + grade); 12 | 13 | double percentToAdd = grade * 8.0 / 100; 14 | grade = grade + percentToAdd; 15 | 16 | System.out.println("Studnet name is " + name); 17 | System.out.println("Student grade is " + grade); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/day7/EvenOddInt.java: -------------------------------------------------------------------------------- 1 | package day7; 2 | 3 | public class EvenOddInt { 4 | public static void main(String[] args) { 5 | // even: 2, 4, 6, 10, 100, 200 6 | // odd: 1, 3, 7, 9, 13 7 | 8 | int number = Integer.parseInt(args[0]); 9 | 10 | // if we use mod opertor by 2 to the number and output is 0 then number is even 11 | if (number % 2 == 0) { 12 | System.out.println(number + " is even"); 13 | }else { 14 | System.out.println(number + " is odd"); 15 | } 16 | 17 | // is even 18 | } 19 | } -------------------------------------------------------------------------------- /src/day20/PassByValue1.java: -------------------------------------------------------------------------------- 1 | package day20; 2 | 3 | import java.util.Arrays; 4 | 5 | public class PassByValue1 { 6 | public static void main(String[] args) { 7 | int[] arr = {1, 2, 3}; 8 | int[] arr1 = arr; 9 | 10 | System.out.println(Arrays.toString(arr)); 11 | System.out.println(Arrays.toString(arr1)); 12 | 13 | arr[0] = 300; 14 | arr1[1] = 200; 15 | 16 | System.out.println(Arrays.toString(arr)); // [300, 200, 3] 17 | System.out.println(Arrays.toString(arr1)); // [300, 200, 3] 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/day3/MilkAndJuce.java: -------------------------------------------------------------------------------- 1 | package day3; 2 | 3 | public class MilkAndJuce { 4 | public static void main(String args[]) { 5 | String milk = "juce"; 6 | String juce = "milk"; 7 | 8 | String tmp; 9 | // juce 10 | tmp = milk; 11 | 12 | // milke 13 | milk = juce; 14 | 15 | // juce 16 | juce = tmp; 17 | 18 | // milk = "milk"; direct assiment not allowed here 19 | // TODO swap the values of milk and juce 20 | 21 | System.out.println("Milk: " + milk); 22 | System.out.println("Juce: " + juce); 23 | } 24 | } -------------------------------------------------------------------------------- /src/day35/DogDemo.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | 4 | public class DogDemo { 5 | public static void main(String[] args) { 6 | // Dog obj = new Dog(); 7 | // obj.name = "Mumu"; 8 | // obj.ownerName = "Alex"; 9 | 10 | // Dog obj1 = new Dog("Mumu", "Alex"); 11 | // System.out.println(obj1.name); 12 | 13 | Dog obj2 = new Dog(); 14 | // Inside constructor 15 | // Inside empty constructor 16 | System.out.println(obj2.name); 17 | System.out.println(obj2.ownerName); 18 | 19 | 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/day6/MethodExample5.java: -------------------------------------------------------------------------------- 1 | package day6; 2 | 3 | public class MethodExample5 { 4 | 5 | public static void main(String[] args) { 6 | 7 | sayHelloTo("John Doe"); 8 | 9 | sayHelloTo("Alex Rodriguez"); 10 | 11 | sayHelloTo("Beknazar"); 12 | 13 | sayHelloTo("Smith"); 14 | } 15 | 16 | public static void sayHelloTo(String name) { 17 | System.out.println("Hello, " + name + "!"); 18 | } 19 | 20 | // Hello, John Doe! 21 | // Hello, Alex Rodriguez! 22 | // Hello, Beknazar! 23 | // Hello, Smith 24 | } 25 | -------------------------------------------------------------------------------- /src/day14/PrintLetters.java: -------------------------------------------------------------------------------- 1 | package day14; 2 | 3 | public class PrintLetters { 4 | public static void main(String[] args) { 5 | // 01234 6 | String str = "Hello World!"; 7 | //System.out.println(str.charAt(0)); // H 8 | 9 | for(int i = 0; i < str.length(); i++) { 10 | if(str.charAt(i) == ' ' || str.charAt(i) == '!') { 11 | continue; 12 | } 13 | System.out.println(str.charAt(i)); 14 | } 15 | 16 | /** 17 | * h 18 | * e 19 | * l 20 | * l 21 | * o 22 | */ 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/day27/CatDemo.java: -------------------------------------------------------------------------------- 1 | package day27; 2 | 3 | public class CatDemo { 4 | public static void main(String[] args) { 5 | Cat obj = new Cat(); 6 | obj.setName("Murka"); 7 | obj.setAge(3); 8 | obj.setSecondName("M"); 9 | 10 | Cat obj2 = new Cat("Tom", 4); 11 | System.out.println(obj2.getName()); 12 | System.out.println(obj2.getAge()); 13 | 14 | System.out.println("------"); 15 | System.out.println(obj.getName()); 16 | System.out.println(obj2.getName()); 17 | 18 | Cat obj3 = new Cat(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/day3/FruitsFarmColors.java: -------------------------------------------------------------------------------- 1 | package day3; 2 | 3 | public class FruitsFarmColors { 4 | public static void main(String args[]) { 5 | String apple = "red"; 6 | String banana = "yellow"; 7 | String orange = "orange"; 8 | String kiwi = "green"; 9 | String pear = "red"; 10 | 11 | System.out.println("Apple is " + apple); 12 | System.out.println("Banana is " + banana); 13 | System.out.println("Orange is " + orange); 14 | System.out.println("Kiwi is " + kiwi); 15 | System.out.println("Pear is " + pear); 16 | } 17 | } -------------------------------------------------------------------------------- /src/day7/ConditionalBranching.java: -------------------------------------------------------------------------------- 1 | package day7; 2 | 3 | public class ConditionalBranching { 4 | public static void main(String[] args) { 5 | int num1 = 5; 6 | int num2 = 7; 7 | // 5 > 7 => false 8 | if (num1 < num2) { 9 | System.out.println("In Line 7"); 10 | }else { 11 | System.out.println("In Line 9"); 12 | } 13 | 14 | 15 | if(5 > 7) { 16 | System.out.println("Line 14"); 17 | System.out.println("LIne 15"); 18 | } else { 19 | System.out.println("Line 17"); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/day8/Calculator1.java: -------------------------------------------------------------------------------- 1 | package day8; 2 | import java.util.Scanner; 3 | 4 | public class Calculator1 { 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | 8 | double numOne = 0.0; 9 | double numTwo = 0.0; 10 | double result = 0.0; 11 | 12 | //TODO your code goes here. To get double input from Scanner and then multiply numOne and numTwo 13 | numOne = scanner.nextDouble(); 14 | 15 | System.out.println(numOne + " * " + numTwo + " = " + result); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/day13/BreakAString.java: -------------------------------------------------------------------------------- 1 | package day13; 2 | 3 | public class BreakAString { 4 | public static void main(String[] args) { 5 | // 012345 6 | String str = "hello"; 7 | 8 | int len = str.length(); // 5 9 | int index = 0; 10 | while(index < len) { 11 | // 5 12 | System.out.println(str.charAt(index)); 13 | index++; 14 | } 15 | 16 | /** 17 | * b 18 | * r 19 | * e 20 | * a 21 | * k 22 | * d 23 | * o 24 | * w 25 | * n 26 | */ 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/day22/BinarySearch.java: -------------------------------------------------------------------------------- 1 | package day22; 2 | 3 | import java.util.Arrays; 4 | 5 | public class BinarySearch { 6 | public static void main(String[] args) { 7 | 8 | int[] num = {6, 3, 2, 10, 0, 7, 5, 10}; 9 | // 1. The data for binary search should be sorted 10 | 11 | Arrays.sort(num); 12 | 13 | System.out.println(Arrays.toString(num)); 14 | int key = 2; 15 | int index = Arrays.binarySearch(num, key); 16 | 17 | System.out.println("Key: " + key); 18 | System.out.println("Index: " + index); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/day9/Table.java: -------------------------------------------------------------------------------- 1 | package day9; 2 | 3 | public class Table { 4 | public long id; 5 | public String color; 6 | public String type; 7 | public int height; 8 | public int width; 9 | public boolean isReserved; 10 | 11 | public void displayDetails() { 12 | System.out.println("Tabe ID: " + id); 13 | System.out.println(color); 14 | System.out.println(type); 15 | System.out.println(height); 16 | System.out.println(width); 17 | System.out.println(isReserved); 18 | System.out.println("-----------"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/day26/Car.java: -------------------------------------------------------------------------------- 1 | package day26; 2 | 3 | public class Car { 4 | public String model; 5 | public String color; 6 | public double price; 7 | 8 | // Blueprint for the objects. We create object/instance from a class. 9 | public Car() { 10 | 11 | } 12 | 13 | public Car(String model) { 14 | // this -> it means this object 15 | this.model = model; 16 | } 17 | 18 | public Car(String model, String color, double price) { 19 | this.model = model; 20 | this.color = color; 21 | this.price = price; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/day4/EggBasket.java: -------------------------------------------------------------------------------- 1 | package day4; 2 | 3 | public class EggBasket { 4 | public static void main(String[] args) { 5 | int numberOfBaskets, eggsPerBasket, totalEggs; 6 | 7 | numberOfBaskets = 10; 8 | eggsPerBasket = 6; 9 | 10 | totalEggs = numberOfBaskets * eggsPerBasket; 11 | 12 | System.out.println("If you have"); 13 | System.out.println(eggsPerBasket + " eggs per basket and"); 14 | System.out.println(numberOfBaskets + " baskets, then"); 15 | System.out.println("the total number of eggs is " + totalEggs); 16 | } 17 | } -------------------------------------------------------------------------------- /src/day7/CustomMethods7.java: -------------------------------------------------------------------------------- 1 | package day7; 2 | 3 | public class CustomMethods7 { 4 | public static void main(String[] args) { 5 | String str = "Hello"; 6 | exPrint(str); 7 | 8 | double numOne = 55.99; 9 | 10 | double numTwo = plus100(numOne); 11 | 12 | System.out.println(numTwo); 13 | } 14 | 15 | public static void exPrint(String word) { 16 | System.out.println(word + "!"); 17 | } 18 | 19 | public static double plus100(double number){ 20 | System.out.println("Hello world"); 21 | return number + 100; 22 | } 23 | } -------------------------------------------------------------------------------- /src/day13/InfiniteLoop.java: -------------------------------------------------------------------------------- 1 | package day13; 2 | 3 | public class InfiniteLoop { 4 | public static void main(String[] args) { 5 | boolean b = true; 6 | 7 | // true 8 | while(b) { 9 | //System.out.println("Hello, World!"); 10 | b = true; 11 | b = false; 12 | } 13 | 14 | 15 | int number = 2; 16 | int number1 = 0; 17 | 18 | // 2 > 0 -> t 19 | while(number > number1) { 20 | System.out.println("Hello, World"); 21 | number1++; 22 | } 23 | 24 | System.out.println("The End"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/day38/ToUpperCase.java: -------------------------------------------------------------------------------- 1 | package day38; 2 | 3 | public class ToUpperCase { 4 | public static void main(String[] args) { 5 | String str = null; 6 | str = makeItUpperCase(str); 7 | System.out.println(str); 8 | } 9 | 10 | public static String makeItUpperCase(String str) { 11 | // TODO catch exception for the null str - print "Invalid input" and return "" 12 | try { 13 | return str.toUpperCase(); 14 | }catch (NullPointerException e) { 15 | System.out.println("Invalid input"); 16 | return ""; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/day13/WhileLoop1.java: -------------------------------------------------------------------------------- 1 | package day13; 2 | import java.util.Scanner; 3 | 4 | public class WhileLoop1 { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | 8 | System.out.println("Enter number: "); 9 | int number = sc.nextInt(); 10 | 11 | // 6 12 | // 1 2 3 4 5 6 13 | int count = 1; 14 | 15 | // 7 <= 6 -> false 16 | while(count <= number) { 17 | System.out.print(count + " "); 18 | Thread.sleep(1000); 19 | count++; 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/day32/Student.java: -------------------------------------------------------------------------------- 1 | package day32; 2 | 3 | public class Student { 4 | public String name; 5 | public int age; 6 | 7 | public void code() { 8 | System.out.println(name + " is coding"); 9 | } 10 | 11 | 12 | public static void main(String[] args) { 13 | Student s1 = new Student(); 14 | s1.name = "John"; 15 | s1.code(); 16 | 17 | Student s2 = new Student(); 18 | 19 | // == to compare references if they are pointing to the same object 20 | s1 = s2; 21 | System.out.println(s1 == s2); 22 | 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/day10/StrCharAt.java: -------------------------------------------------------------------------------- 1 | package day10; 2 | 3 | public class StrCharAt { 4 | public static void main(String[] args) { 5 | /** 6 | * .charAt(index); -> get specific char by index 7 | */ 8 | 9 | // 0123 10 | String str = "home"; 11 | char ch = str.charAt(1); 12 | System.out.println(ch); // o 13 | 14 | // 012345 15 | str = "Public"; 16 | char ch2 = str.charAt(5); 17 | System.out.println(ch2); 18 | 19 | // 0123456 20 | str = "Pricing"; 21 | System.out.println(str.charAt(6)); // g 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/day14/BreakALoop.java: -------------------------------------------------------------------------------- 1 | package day14; 2 | 3 | public class BreakALoop { 4 | public static void main(String[] args) { 5 | 6 | for(int i = 0; i < 10; i++) { 7 | if(i == 3) { 8 | // when break keyword is used the program will exit from the loop 9 | break; 10 | } 11 | System.out.print(i + " "); 12 | } 13 | 14 | System.out.println("\n"); 15 | int count = 0; 16 | while(count < 10) { 17 | if(count == 7) { 18 | break; 19 | } 20 | 21 | System.out.print(count + " "); 22 | count++; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/day25/DaysOfWeek.java: -------------------------------------------------------------------------------- 1 | package day25; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class DaysOfWeek { 6 | public static void main(String[] args) { 7 | ArrayList daysOfWeek = new ArrayList<>(); 8 | daysOfWeek.add("Mon"); 9 | daysOfWeek.add("Tue"); 10 | daysOfWeek.add("Wed"); 11 | daysOfWeek.add("Thur"); 12 | daysOfWeek.add("Fri"); 13 | daysOfWeek.add("Sat"); 14 | daysOfWeek.add("Sun"); 15 | 16 | for(int i = daysOfWeek.size() - 1; i >= 0; i--) { 17 | System.out.println(daysOfWeek.get(i)); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/day24/String2Demo.java: -------------------------------------------------------------------------------- 1 | package day24; 2 | 3 | public class String2Demo { 4 | public static void main(String[] args) { 5 | ConsoleInput input = new ConsoleInput(); 6 | System.out.println("Enter Name:"); 7 | String name = input.getStr(); 8 | System.out.println(name); 9 | 10 | String2 str = new String2("apple"); 11 | System.out.println(str); 12 | 13 | System.out.println(str.length()); 14 | 15 | char ch = str.charAt(0); 16 | System.out.println(ch); 17 | 18 | str = str.reverse(); 19 | System.out.println(str); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/day34/A.java: -------------------------------------------------------------------------------- 1 | package day34; 2 | 3 | import java.util.List; 4 | 5 | public class A { 6 | 7 | public String reverseStr(String str) { 8 | return null; 9 | } 10 | 11 | // We cannot override final methods 12 | // public final void printHello() { 13 | // 14 | // } 15 | 16 | public void printHello() { 17 | 18 | } 19 | 20 | public double sum(double[] dArr) { 21 | return 0.0; 22 | } 23 | 24 | public int getMin(int[] numArr) { 25 | return 0; 26 | } 27 | 28 | public int getMax(List numList) { 29 | return 0; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/day41/ShoppingDemo.java: -------------------------------------------------------------------------------- 1 | package day41; 2 | 3 | public class ShoppingDemo { 4 | public static void main(String[] args) { 5 | ShoppingBalance member1 = ShoppingBalance.getInstance(); 6 | member1.buy("head phone", 300.00); 7 | System.out.println("--------"); 8 | 9 | ShoppingBalance member2 = ShoppingBalance.getInstance(); 10 | member2.buy("phone", 500.00); 11 | System.out.println("--------"); 12 | 13 | member2.buy("charger", 40.00); 14 | System.out.println("--------"); 15 | 16 | member1.buy("phone case", 25.0); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/day6/EggBasket.java: -------------------------------------------------------------------------------- 1 | package day6; 2 | 3 | public class EggBasket { 4 | public static void main(String[] args) { 5 | 6 | int numberOfBaskets, eggsPerBasket, totalEggs; 7 | 8 | numberOfBaskets = Integer.parseInt(args[0]); 9 | eggsPerBasket = 6; 10 | totalEggs = numberOfBaskets * eggsPerBasket; 11 | 12 | System.out.println("If you have"); 13 | System.out.println(eggsPerBasket + " eggs per basket and"); 14 | System.out.println(numberOfBaskets + " baskets, then"); 15 | System.out.println("the total number of eggs is " + totalEggs); 16 | 17 | } 18 | } -------------------------------------------------------------------------------- /src/day13/WarmUp.java: -------------------------------------------------------------------------------- 1 | package day13; 2 | 3 | public class WarmUp { 4 | public static void main(String[] args) { 5 | boolean res = isOddLength("apple"); // true 6 | System.out.println(res); 7 | } 8 | 9 | // Create a static method isOddLength that will accept one String as an argument 10 | // If the length of the argument string is odd return true otherwise return false 11 | 12 | public static boolean isOddLength(String str) { 13 | int len = str.length(); 14 | if(len % 2 == 0) { 15 | return false; 16 | }else { 17 | return true; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/day6/MethodExample.java: -------------------------------------------------------------------------------- 1 | package day6; 2 | 3 | public class MethodExample { 4 | 5 | public static void main(String[] args) { 6 | printHello(); 7 | 8 | printHello(); 9 | 10 | saySomething(); 11 | 12 | justAMethod(); 13 | 14 | } 15 | 16 | public static void printHello() { 17 | String word = "Hello"; 18 | System.out.println(word); 19 | System.out.println(word); 20 | } 21 | 22 | public static void saySomething() { 23 | System.out.println("Something"); 24 | } 25 | 26 | public static void justAMethod() { 27 | String str = "apple"; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/day9/WarmUp.java: -------------------------------------------------------------------------------- 1 | package day9; 2 | 3 | public class WarmUp { 4 | public static void main(String[] args) { 5 | String str = getNumStr(5); 6 | System.out.println(str); 7 | } 8 | 9 | public static String getNumStr(int number) { 10 | if(number == 1) { 11 | return "One"; 12 | }else if(number == 2) { 13 | return "Two"; 14 | }else if(number == 3) { 15 | return "Three"; 16 | }else if(number == 4) { 17 | return "Four"; 18 | }else if(number == 5) { 19 | return "Five"; 20 | }else { 21 | return String.valueOf(number); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/day10/StrCount.java: -------------------------------------------------------------------------------- 1 | package day10; 2 | import java.util.Scanner; 3 | 4 | public class StrCount { 5 | public static void main(String[] args) { 6 | /** 7 | * Program should ask a user to type any word 8 | * It will print the number of letters in the given word 9 | */ 10 | 11 | Scanner scanner = new Scanner(System.in); 12 | 13 | System.out.println("Enter any word: "); 14 | String word = scanner.next(); 15 | 16 | int count = word.length(); 17 | 18 | System.out.println("Your word has " + count + " letters inside"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/day12/TernaryOperator2.java: -------------------------------------------------------------------------------- 1 | package day12; 2 | 3 | public class TernaryOperator2 { 4 | public static void main(String[] args) { 5 | // F T 6 | int number = (5 > 6) ? (4) : (6 > 5 ? 7 : 8) ; 7 | 8 | System.out.println(number); // 7 9 | 10 | System.out.println( (7 > 6) ? "Hello" : 99.99 ); 11 | 12 | // it will not compile 13 | // String str = 7 > 6 ? "Hello" : 99.99; 14 | 15 | // F 16 | int number1 = (8 > 9) ? (7 < 100 ? 20 : 30) : (80 > 79 ? 25 : 35); 17 | System.out.println(number1); // 25 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/day27/PersonDemo.java: -------------------------------------------------------------------------------- 1 | package day27; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | public class PersonDemo { 7 | public static void main(String[] args) { 8 | Person p = new Person(); 9 | p.setName("John"); 10 | 11 | Person p1 = new Person(); 12 | p1.setName("John"); 13 | 14 | System.out.println(p == p1); 15 | System.out.println(p.equals(p1)); 16 | 17 | Set set = new HashSet<>(); 18 | set.add(p); 19 | set.add(p1); 20 | System.out.println(set); 21 | 22 | // Object: 23 | // equals 24 | // hashCode 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/day30/MapWithCustomObj.java: -------------------------------------------------------------------------------- 1 | package day30; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class MapWithCustomObj { 7 | public static void main(String[] args) { 8 | // Map 9 | Map students = new HashMap<>(); 10 | 11 | Student s1 = new Student("Kuba", 98.0, "Java"); 12 | System.out.println(s1); 13 | 14 | students.put(1, s1); 15 | 16 | students.put(2, new Student("John", 50.0, "Java")); 17 | students.put(3, new Student("Vijay", 100.0, "Java")); 18 | 19 | System.out.println(students); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/day11/StrTrim.java: -------------------------------------------------------------------------------- 1 | package day11; 2 | 3 | public class StrTrim { 4 | public static void main(String[] args) { 5 | // .trim() is used to remove the spaces around the string 6 | // it will return string with no spaces 7 | 8 | // "$100.00 USD " 9 | String actualAmount = " $100.00 USD "; 10 | String expectedAmount = "$100.00 USD"; 11 | 12 | //actualAmount = actualAmount.trim(); 13 | 14 | if(actualAmount.trim().equals(expectedAmount)) { 15 | System.out.println("TEST PASS"); 16 | }else { 17 | System.out.println("TEST FAILED"); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/day24/PrefixAgain.java: -------------------------------------------------------------------------------- 1 | package day24; 2 | 3 | public class PrefixAgain { 4 | public static void main(String[] args) { 5 | boolean res = prefixAgain("abXYabc", 1); 6 | System.out.println(res); 7 | } 8 | 9 | public static boolean prefixAgain(String str, int n) { 10 | // 1. get prefix ! 11 | // 2. get rest of the string 12 | // 3. if rest of the string contains prefix 13 | 14 | String prefix = str.substring(0, n); 15 | String rest = str.substring(n); 16 | 17 | return rest.contains(prefix); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/day28/Phone.java: -------------------------------------------------------------------------------- 1 | package day28; 2 | 3 | public class Phone { 4 | public String model; 5 | public double price; 6 | 7 | 8 | // When class does not have any constructors, 9 | //java will provide default empty constructor. 10 | 11 | public Phone(String model, double price) { 12 | this.model = model; 13 | this.price = price; 14 | } 15 | 16 | public Phone(String model) { 17 | System.out.println("Here"); 18 | this.model = model; 19 | } 20 | 21 | public Phone(double price) { 22 | this.price = price; 23 | } 24 | 25 | public Phone() { 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/day28/PhoneDemo.java: -------------------------------------------------------------------------------- 1 | package day28; 2 | 3 | public class PhoneDemo { 4 | public static void main(String[] args) { 5 | Phone phone1 = new Phone("Nokia", 300.00); 6 | System.out.println(phone1.model); 7 | System.out.println(phone1.price); 8 | 9 | Phone phone2 = new Phone("Iphone"); 10 | Phone phone3 = new Phone(100.99); 11 | 12 | Phone phone4 = new Phone(); 13 | phone4.price = -999; 14 | phone4.model = "????"; 15 | 16 | System.out.println(phone4.price); 17 | 18 | String str = new String("Hello"); 19 | System.out.println(str); 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/day5/ArithmeticOperators2.java: -------------------------------------------------------------------------------- 1 | package day5; 2 | 3 | public class ArithmeticOperators2 { 4 | public static void main(String[] args) { 5 | // * / % + - 6 | int result = 2 + 3 * 2; 7 | int result1 = (2 + 3) * 2; 8 | 9 | System.out.println(result); // 8 10 | System.out.println(result1); // 10 11 | 12 | System.out.println("--------------"); 13 | // 17 / 10 = 1 -> 7 14 | System.out.println(1010 % 10); // 0 15 | System.out.println(12 % 3); // 0 16 | System.out.println(19 % 10); // 9 17 | 18 | 19 | // BREAK 10 min till 8:12 PM 20 | 21 | } 22 | } -------------------------------------------------------------------------------- /src/day25/Phones.java: -------------------------------------------------------------------------------- 1 | package day25; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Phones { 6 | public static void main(String[] args) { 7 | ArrayList phones = new ArrayList<>(); 8 | phones.add("iphone"); 9 | phones.add("nokia"); 10 | phones.add("hp"); 11 | phones.add("samsung"); 12 | 13 | for(int i = 0; i < phones.size(); i++) { 14 | System.out.println(phones.get(i)); 15 | } 16 | 17 | phones.remove(1); 18 | 19 | System.out.println("---------"); 20 | for(String phone : phones) { 21 | System.out.println(phone); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/day44/FibonacciNumbers.java: -------------------------------------------------------------------------------- 1 | package day44; 2 | 3 | public class FibonacciNumbers { 4 | public static void main(String[] args) { 5 | printFib(30); 6 | } 7 | 8 | /* 9 | * Write a method that will accept int n 10 | * Method will print n Fibonacci numbers 11 | * Time Complexity: O(n) 12 | */ 13 | public static void printFib(int n) { 14 | int numOne = 0; 15 | int numTwo = 1; 16 | 17 | for(int i = 0; i < n; i++) { 18 | System.out.print(numOne + " "); 19 | int sum = numOne + numTwo; 20 | numOne = numTwo; 21 | numTwo = sum; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/day8/Calculator.java: -------------------------------------------------------------------------------- 1 | package day8; 2 | import java.util.Scanner; 3 | 4 | public class Calculator { 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | 8 | int numOne; 9 | int numTwo; 10 | int result; 11 | 12 | System.out.println("Provide first whole number:"); 13 | numOne = scanner.nextInt(); 14 | 15 | System.out.println("Provide second whole number:"); 16 | numTwo = scanner.nextInt(); 17 | 18 | result = numOne + numTwo; 19 | System.out.println(numOne + " + " + numTwo + " = " + result); 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/day3/FloatingNumber.java: -------------------------------------------------------------------------------- 1 | package day3; 2 | 3 | public class FloatingNumber { 4 | public static void main(String args[]) { 5 | float num = 4.5F; 6 | float num2 = 6.132423F; 7 | float num3 = 9.99F; 8 | 9 | double d = 14223.99; 10 | 11 | d = d * 4; 12 | System.out.println(d); 13 | 14 | double d1 = 1.5; 15 | String res = "Value is " + d1; 16 | System.out.println(res); 17 | 18 | double d2 = 5.3; 19 | //String res1 = "Result " + (d2 + 4); 20 | // "Result 9.3" 21 | String res1 = "Result " + (d2 + 4); 22 | 23 | System.out.println(res1); // 9.3 24 | } 25 | } -------------------------------------------------------------------------------- /src/day36/Browser.java: -------------------------------------------------------------------------------- 1 | package day36; 2 | 3 | public interface Browser { 4 | /* 5 | - open() 6 | - goTo(String url) 7 | - click(String on) 8 | - navigateForward() 9 | - navigaetBack() 10 | - close() 11 | - getBrowserName() 12 | */ 13 | 14 | public abstract void open(); 15 | 16 | public abstract void goTo(String url); 17 | 18 | public abstract void click(String on); 19 | 20 | public abstract void navigateForward(); 21 | 22 | public abstract void navigateBack(); 23 | 24 | public abstract void close(); 25 | 26 | public abstract String getBrowserName(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/day16/LocalVar.java: -------------------------------------------------------------------------------- 1 | package day16; 2 | 3 | public class LocalVar { 4 | public static String name; 5 | public static int age; 6 | public static boolean isHuman; 7 | 8 | public static void main(String[] args) { 9 | // local variables don't have default values 10 | String str = ""; 11 | System.out.println(str); 12 | 13 | // default value for object is null 14 | System.out.println(name); 15 | 16 | // default value for primitive numbers is 0 17 | System.out.println(age); 18 | 19 | // default value of boolean is false 20 | System.out.println(isHuman); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/day38/Store.java: -------------------------------------------------------------------------------- 1 | package day38; 2 | 3 | public class Store { 4 | public String[] items; 5 | 6 | public Store(int itemSize) { 7 | items = new String[itemSize]; 8 | } 9 | 10 | public void addItem(int index, String item) { 11 | try { 12 | items[index] = item; 13 | }catch (ArrayIndexOutOfBoundsException e) { 14 | System.out.println("Invalid index: " + index + ". For size: " + items.length); 15 | } 16 | } 17 | 18 | public static void main(String[] args) { 19 | Store obj = new Store(5); 20 | obj.addItem(0, "apple"); 21 | obj.addItem(10, "orange"); 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/day41_2/FoodFactory.java: -------------------------------------------------------------------------------- 1 | package day41_2; 2 | 3 | public class FoodFactory { 4 | 5 | public static Food getFood(String animalName) { 6 | 7 | switch(animalName) { 8 | case "zebra": 9 | return new Hay(100); 10 | 11 | case "rabbit": 12 | return new Pellets(5); 13 | 14 | case "goat": 15 | return new Pellets(30); 16 | 17 | case "polar bear": 18 | return new Fish(10); 19 | 20 | case "flamingo": 21 | return new Fish(1); 22 | 23 | default: 24 | throw new IllegalArgumentException("Unsupported animal: " + animalName); 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/day6/Person.java: -------------------------------------------------------------------------------- 1 | package day6; 2 | 3 | public class Person { 4 | 5 | public static void main(String[] args) { 6 | String name = "John Doe"; 7 | int age = 9; 8 | 9 | displayDetails(name, age); 10 | 11 | //age = age + 10; 12 | age += 10; 13 | 14 | displayDetails(name, age); 15 | 16 | //age = age + 1; 17 | age++; 18 | 19 | displayDetails(name, age); 20 | } 21 | 22 | public static void displayDetails(String name, int age) { 23 | System.out.println("Name: " + name); 24 | System.out.println("Age: " + age); 25 | System.out.println("--------------"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/day44/Words.java: -------------------------------------------------------------------------------- 1 | package day44; 2 | 3 | public class Words { 4 | public static void main(String[] args) { 5 | String str = "apple"; 6 | String str1 = "apple"; 7 | 8 | // string pool is not used 9 | String str2 = new String("apple"); 10 | 11 | // == when used with references(objects) if they are pointing to the same object 12 | System.out.println(str == str1); // true. It means they point to the same object 13 | System.out.println(str == str2); // false. new String("apple") get new object 14 | System.out.println(str.equals(str2)); // true. equals() compares actual content 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/day37/Report.java: -------------------------------------------------------------------------------- 1 | package day37; 2 | 3 | public class Report { 4 | private String name; 5 | private String department; 6 | private int pages; 7 | 8 | public String getName() { 9 | return name; 10 | } 11 | 12 | public void setName(String name) { 13 | this.name = name; 14 | } 15 | 16 | public String getDepartment() { 17 | return department; 18 | } 19 | 20 | public void setDepartment(String department) { 21 | this.department = department; 22 | } 23 | 24 | public int getPages() { 25 | return pages; 26 | } 27 | 28 | public void setPages(int pages) { 29 | this.pages = pages; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/day51/Recursion.java: -------------------------------------------------------------------------------- 1 | package day51; 2 | 3 | public class Recursion { 4 | public static void main(String[] args) { 5 | //printReg(5); 6 | 7 | printRec(3); 8 | } 9 | 10 | public static void printReg(int num) { 11 | for(int i = 0; i < num; i++) { 12 | System.out.println("Hello"); 13 | } 14 | } 15 | 16 | public static void printRec(int num) { 17 | // Base case to exit the recursion 18 | if(num <= 0) { 19 | return; 20 | } 21 | 22 | System.out.println("Hello"); 23 | 24 | // Recursion case - when we call a method itself with different arg value 25 | printRec(num - 1); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/day12/RGBColors.java: -------------------------------------------------------------------------------- 1 | package day12; 2 | 3 | public class RGBColors { 4 | public static void main(String[] args) { 5 | String color = "black"; 6 | String hexNumber; 7 | // black 8 | switch(color) { 9 | case "white": 10 | System.out.println("Getting RGB hex number for white"); 11 | hexNumber = "FFFFFF"; 12 | break; 13 | case "red": 14 | System.out.println("Getting RGB hex number for red"); 15 | hexNumber = "FF0000"; 16 | break; 17 | default: 18 | System.out.println("Color is not found"); 19 | hexNumber = ""; 20 | break; 21 | } 22 | 23 | System.out.println(hexNumber); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/day27/BookDemo2.java: -------------------------------------------------------------------------------- 1 | package day27; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class BookDemo2 { 7 | public static void main(String[] args) { 8 | Book b1 = new Book("7 Habits Of Highly Effective People", "R. Covey", 350, Rating.Excellent); 9 | 10 | Book b2 = new Book("7 Habits Of Highly Effective People", "R. Covey", 350, Rating.Excellent); 11 | 12 | System.out.println(b1.equals(b2)); 13 | 14 | List l1 = new ArrayList<>(); 15 | l1.add(b1); 16 | 17 | List l2 = new ArrayList<>(); 18 | l2.add(b2); 19 | 20 | System.out.println(l1.equals(l2)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/day26/PersonDemo.java: -------------------------------------------------------------------------------- 1 | package day26; 2 | 3 | public class PersonDemo { 4 | public static void main(String[] args) { 5 | Person person = new Person(); 6 | //person.name = "John Doe"; 7 | //person.age = -3; 8 | 9 | person.setName("John Doe"); 10 | person.setAge(3); 11 | 12 | System.out.println("Name: " + person.getName()); 13 | System.out.println("Age: " + person.getAge()); 14 | 15 | Person person1 = new Person(); 16 | person1.setName("Smith"); 17 | person1.setAge(15); 18 | System.out.println("Name: " +person1.getName()); 19 | System.out.println("Age: " +person1.getAge()); 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/day19/Price.java: -------------------------------------------------------------------------------- 1 | package day19; 2 | 3 | public class Price { 4 | public static void main(String[] args) { 5 | // array of type double of size 3 6 | // 0 , 1 , 2 7 | double[] price = {14.99, 9.99, 1.50}; 8 | 9 | // double[] price = new double[3]; 10 | // price[0] = 14.99; 11 | // price[1] = 9.99; 12 | // price[2] = 1.50; 13 | 14 | // 0 1 2 15 | // [14.99][9.99][1.50] 16 | double priceSum = price[0] + price[1] + price[2]; 17 | System.out.println("Sum of all elements: " + priceSum); 18 | 19 | // String[] strArr = {"abc", "bca", "qwe"}; 20 | // System.out.println(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/day5/ConvertStringToPrimitives.java: -------------------------------------------------------------------------------- 1 | package day5; 2 | 3 | public class ConvertStringToPrimitives { 4 | public static void main(String[] args) { 5 | String numStr = "99"; 6 | // convert String number to int 7 | int num = Integer.parseInt(numStr); 8 | System.out.println(num + 10); // 109 9 | 10 | 11 | String numStr2 = "10.99"; 12 | double dNumber = Double.parseDouble(numStr2); 13 | System.out.println(dNumber + 0.01); // 11.0 14 | 15 | int num2 = Integer.parseInt("77"); 16 | System.out.println(num2); 17 | 18 | String bStr = "false"; 19 | boolean b = Boolean.parseBoolean(bStr); 20 | System.out.println(b); 21 | } 22 | } -------------------------------------------------------------------------------- /src/day5/SpecAssignmentOperators.java: -------------------------------------------------------------------------------- 1 | package day5; 2 | 3 | public class SpecAssignmentOperators { 4 | public static void main(String[] args) { 5 | int num = 70; 6 | num = num + 10; // 80 7 | num += 10; // 90 8 | 9 | System.out.println(num); 10 | 11 | num = num - 10; // 80 12 | num -= 10; // 70 13 | System.out.println(num); // 70 14 | 15 | num = num * 2; 16 | num *= 2; 17 | 18 | 19 | int num2 = 1; 20 | System.out.println(num2 + 1); // 2 21 | System.out.println(num2); // 1 22 | num2 += 5; 23 | // num2 = num2 + 5; 24 | System.out.println(num2); // 6 25 | 26 | num2 /= 2; 27 | // num2 = num2 / 2; 28 | } 29 | } -------------------------------------------------------------------------------- /src/day18/DoubleChar.java: -------------------------------------------------------------------------------- 1 | package day18; 2 | 3 | public class DoubleChar { 4 | public static void main(String[] args) { 5 | String res = doubleChar("The"); 6 | System.out.println(res); 7 | } 8 | 9 | // doubleChar("The") -> "TThhee" 10 | public static String doubleChar(String str) { 11 | // empty string 12 | // loop to go throw each char in the str 13 | // keep adding to empty string in the loop each char two times 14 | 15 | String res = ""; 16 | for(int i = 0; i < str.length(); i++) { 17 | // = "" + 'T' + 'T' 18 | res = res + str.charAt(i) + str.charAt(i); 19 | } 20 | 21 | return res; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/day20/SwapValues.java: -------------------------------------------------------------------------------- 1 | package day20; 2 | import java.util.Arrays; 3 | 4 | public class SwapValues { 5 | public static void main(String[] args) { 6 | 7 | String[] city = {"Aldie", "Arlington", "Tysons", "Chantilly", "DC"}; 8 | System.out.println(Arrays.toString(city)); 9 | 10 | // swap values of first and last element of the array city 11 | 12 | // [Aldie, Arlington, Tysons, Chantilly, DC] 13 | // [DC, Arlington, Tysons, Chantilly, Aldie] 14 | 15 | String tempVar = city[0]; 16 | city[0] = city[city.length - 1]; 17 | city[city.length - 1] = tempVar; 18 | 19 | System.out.println(Arrays.toString(city)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/day26/Person.java: -------------------------------------------------------------------------------- 1 | package day26; 2 | 3 | public class Person { 4 | private String name; 5 | private int age; 6 | 7 | public void setName(String name) { 8 | if(name.length() == 0 || name == null) { 9 | System.out.println("Error: Invalid name"); 10 | }else { 11 | this.name = name; 12 | } 13 | } 14 | 15 | public String getName() { 16 | return name; 17 | } 18 | 19 | public void setAge(int age) { 20 | if(age < 1) { 21 | // throw exception here 22 | System.out.println("Error: Invalid age input"); 23 | }else { 24 | this.age = age; 25 | } 26 | } 27 | 28 | public int getAge() { 29 | return age; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/day32/StringReview.java: -------------------------------------------------------------------------------- 1 | package day32; 2 | 3 | public class StringReview { 4 | public static void main(String[] args) { 5 | String str = "apple"; 6 | String str1 = new String("apple"); 7 | String str2 = "apple"; 8 | 9 | String str3 = "banana"; 10 | 11 | String str4 = "applle"; 12 | 13 | str2 = "applee"; 14 | 15 | // == to compare references if they are pointing to the same object 16 | 17 | 18 | System.out.println(str == str1); // false 19 | System.out.println(str == str2); // true 20 | 21 | // equals method always checks the content 22 | System.out.println(str.equals(str1)); // true 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/day41/AnimalBuilder.java: -------------------------------------------------------------------------------- 1 | package day41; 2 | 3 | import java.util.List; 4 | 5 | public class AnimalBuilder { 6 | private String name; 7 | private int age; 8 | private List favoriteFood; 9 | 10 | public AnimalBuilder setName(String name) { 11 | this.name = name; 12 | return this; 13 | } 14 | 15 | public AnimalBuilder setAge(int age) { 16 | this.age = age; 17 | return this; 18 | } 19 | 20 | public AnimalBuilder setFavoriteFood(List favoriteFood) { 21 | this.favoriteFood = favoriteFood; 22 | return this; 23 | } 24 | 25 | public Animal build() { 26 | return new Animal(name, age, favoriteFood); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/day8/WarmUp.java: -------------------------------------------------------------------------------- 1 | package day8; 2 | 3 | public class WarmUp { 4 | public static void main(String[] args) { 5 | String evenOddStr = getEvenOdd(12); 6 | System.out.println(evenOddStr); 7 | 8 | evenOddStr = getEvenOdd(10); 9 | System.out.println(evenOddStr); 10 | 11 | evenOddStr = getEvenOdd(3); 12 | System.out.println(evenOddStr); 13 | } 14 | 15 | public static String getEvenOdd(int number) { 16 | // except if number is 10 then return "ten" 17 | if(number == 10) { 18 | return "ten"; 19 | } 20 | 21 | if(number % 2 == 0) { 22 | return "even"; 23 | }else { 24 | return "odd"; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/day38/EvenOdd.java: -------------------------------------------------------------------------------- 1 | package day38; 2 | 3 | import java.util.Scanner; 4 | 5 | public class EvenOdd { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | System.out.println("Enter number: "); 9 | String numStr = sc.next(); 10 | 11 | try { 12 | 13 | int number = Integer.parseInt(numStr); 14 | if(number % 2 == 0) { 15 | System.out.println("Even number"); 16 | } else { 17 | System.out.println("Odd number"); 18 | } 19 | 20 | } catch(NumberFormatException e) { 21 | System.out.println("Invalid input."); 22 | } 23 | 24 | System.out.println("Completed."); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/day13/ReverseString.java: -------------------------------------------------------------------------------- 1 | package day13; 2 | 3 | public class ReverseString { 4 | public static void main(String[] args) { 5 | // 012345 6 | String str = "abcdef"; 7 | String strReversed = ""; 8 | 9 | // 5 = 6 - 1 10 | int index = str.length() - 1; 11 | 12 | // -1 >= 0 13 | while(index >= 0) { 14 | // "fedcba" = "fedcd" + 'a' 15 | strReversed = strReversed + String.valueOf(str.charAt(index)); 16 | 17 | 18 | 19 | // -1 20 | index--; 21 | } 22 | 23 | System.out.println(strReversed); // 24 | System.out.println(index); // -1 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/day40/WriteBytesStream.java: -------------------------------------------------------------------------------- 1 | package day40; 2 | 3 | import java.io.File; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | import java.io.OutputStream; 7 | 8 | public class WriteBytesStream { 9 | public static void main(String[] args) throws IOException { 10 | File file = new File("C:/Users/Beknazar/Desktop/test.txt"); 11 | 12 | if(!file.exists()) { 13 | file.createNewFile(); 14 | } 15 | 16 | try(OutputStream out = new FileOutputStream(file)) { 17 | 18 | out.write(72); // H 19 | out.write(73); // I 20 | 21 | }catch(IOException e) { 22 | System.out.println(e.getMessage()); 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/day7/ConditionalBranching1.java: -------------------------------------------------------------------------------- 1 | package day7; 2 | 3 | public class ConditionalBranching1 { 4 | public static void main(String[] args) { 5 | // == equal to. We use this operator to compare primitives 6 | 7 | double d = 8.1; 8 | double d1 = 8.1; 9 | // true 10 | boolean isEqual = d == d1; 11 | 12 | if(isEqual) { 13 | System.out.println("Yes, they are equal"); 14 | } else { 15 | System.out.println("No, they are not equal"); 16 | } 17 | 18 | // != not equal to (1 != 5) => true, (1 != 1) => false 19 | if(d != d1) { 20 | System.out.println("Not Equal"); 21 | } else { 22 | System.out.println("Equal"); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/day38/CheckedException.java: -------------------------------------------------------------------------------- 1 | package day38; 2 | 3 | 4 | public class CheckedException { 5 | public static void main(String[] args) { 6 | 7 | for(int i = 1; i <= 10; i++) { 8 | System.out.println(i); 9 | 10 | wait(1); 11 | 12 | 13 | //waitMin(2); 14 | } 15 | } 16 | 17 | public static void wait(int seconds) { 18 | try { 19 | Thread.sleep(seconds * 1000); 20 | }catch(InterruptedException e ) { 21 | e.printStackTrace(); 22 | System.out.println("Exception is here, do something.."); 23 | } 24 | } 25 | 26 | public static void waitMin(int min) throws InterruptedException { 27 | Thread.sleep(min * 60 * 1000); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/day19/FirstLast.java: -------------------------------------------------------------------------------- 1 | package day19; 2 | 3 | public class FirstLast { 4 | public static void main(String[] args) { 5 | // 0 1 2 3 4 5 6 7 6 | double[] temp = {32, 30, 25.7, 26, 34, 31.5, 29, 31}; 7 | 8 | int size = temp.length; 9 | System.out.println("Number of elements: " + size); 10 | System.out.println("Last element: " + temp[temp.length - 1]); 11 | 12 | double sumOfFAndL = firstLast(temp); 13 | System.out.println("First and Last: " + sumOfFAndL); // 63.0 14 | } 15 | 16 | public static double firstLast(double[] numArr) { 17 | double res = numArr[0] + numArr[numArr.length - 1]; 18 | return res; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/day8/Grade.java: -------------------------------------------------------------------------------- 1 | package day8; 2 | 3 | public class Grade { 4 | public static void main(String[] args) { 5 | int score = 70; 6 | char grade = getGrade(score); 7 | 8 | System.out.println("Score = " + score); 9 | System.out.println("Grade = " + grade); 10 | } 11 | 12 | public static char getGrade(int score) { 13 | char grade; 14 | 15 | if(score > 90) { 16 | grade = 'A'; 17 | }else if(score > 80 && score < 90) { 18 | grade = 'B'; 19 | }else if(score > 70 && score < 80) { 20 | grade = 'C'; 21 | }else if (score > 60 && score < 70) { 22 | grade = 'D'; 23 | }else { 24 | grade = 'F'; 25 | } 26 | 27 | return grade; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/day26/CarDemo2.java: -------------------------------------------------------------------------------- 1 | package day26; 2 | 3 | public class CarDemo2 { 4 | public static void main(String[] args) { 5 | Car car = new Car(); 6 | 7 | Car car1 = new Car("BMW"); 8 | System.out.println(car1.model); 9 | 10 | System.out.println("---------"); 11 | 12 | Car car2 = new Car("Honda", "Silver", 23000.0); 13 | System.out.println(car2.model); 14 | System.out.println(car2.color); 15 | System.out.println(car2.price); 16 | 17 | Car car3 = new Car("Mazda", "white", 25000.0); 18 | // car3.price = -9999; 19 | System.out.println(car3.model); 20 | System.out.println(car3.color); 21 | System.out.println(car3.price); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/day9/StaticKeyword.java: -------------------------------------------------------------------------------- 1 | package day9; 2 | 3 | public class StaticKeyword { 4 | public static void main(String[] args) { 5 | 6 | School objOne = new School(); 7 | objOne.id = 1; 8 | objOne.name = "Shool #13"; 9 | objOne.year = 2020; 10 | printDetails(objOne); 11 | 12 | 13 | School objTwo = new School(); 14 | printDetails(objTwo); 15 | 16 | //printDetails(objOne); 17 | 18 | } 19 | 20 | public static void printDetails(School school) { 21 | System.out.println("School id: " + school.id); 22 | System.out.println("Name: " + school.name); 23 | System.out.println("Year: " + school.year); 24 | System.out.println("------------"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/day20/ArrayRecap.java: -------------------------------------------------------------------------------- 1 | package day20; 2 | 3 | public class ArrayRecap { 4 | public static void main(String[] args) { 5 | int[] num = new int[3]; 6 | // 0 1 2 7 | // [6][19][21] 8 | 9 | num[0] = 6; 10 | num[1] = 19; 11 | num[2] = 21; 12 | 13 | int[] num1 = {1, 2, 3, 4, 5, 6}; 14 | 15 | int[] num2 = new int[] {1, 2, 3, 4, 5, 6}; 16 | // 0 1 2 3 4 5 17 | // [1][2][3][4][5][6] 18 | 19 | for(int i = 0; i < num1.length; i++) { 20 | System.out.println(num1[i]); 21 | } 22 | 23 | String[] cities = {"Aldie"}; 24 | // ["Aldie"] 25 | System.out.println(cities[0]); 26 | // System.out.println(cities[1]); Index out of bound 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/day35/BigBox.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public class BigBox implements Box { 4 | private String[] box = new String[100]; 5 | private int numberOfItems; 6 | 7 | @Override 8 | public void putInside(String item) { 9 | for(int i = 0; i < box.length; i++) { 10 | if(box[i] == null) { 11 | box[i] = item; 12 | numberOfItems++; 13 | return; 14 | } 15 | } 16 | } 17 | 18 | @Override 19 | public String getItem(int index) { 20 | return box[index]; 21 | } 22 | 23 | @Override 24 | public int getFreeSpace() { 25 | return box.length - numberOfItems; 26 | } 27 | 28 | @Override 29 | public int getNumberOfItems() { 30 | return numberOfItems; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/day7/Expample.java: -------------------------------------------------------------------------------- 1 | package day7; 2 | 3 | public class Expample { 4 | public static void main(String[] args) { 5 | 6 | boolean b = false; 7 | boolean b1 = true; 8 | 9 | // false || true 10 | if( b && b1 || true ) { 11 | System.out.println("Yes, true. Im here"); 12 | } else { 13 | System.out.println("No, False."); 14 | } 15 | 16 | // f && t && t 17 | // f || f && t && t 18 | boolean b3 = 5 > 8 || 9 > 10 && true && 1 < 4; 19 | System.out.println(b3); // false 20 | 21 | // t f 22 | boolean b4 = 7 > 6 || 5 > 6; 23 | System.out.println(b4); // true 24 | } 25 | } -------------------------------------------------------------------------------- /src/day10/EvenOddStr.java: -------------------------------------------------------------------------------- 1 | package day10; 2 | 3 | public class EvenOddStr { 4 | public static void main(String[] args) { 5 | // create a method isEven that accepts one String argument 6 | // if the length of the argument is even return true 7 | // otherwise return false 8 | 9 | System.out.println(isEven("Johns")); 10 | } 11 | 12 | public static boolean isEven(String str) { 13 | // how do we know if number is even 14 | // we can use mod or remainder % 15 | // number % 2 == 0 -> number is even 16 | 17 | int len = str.length(); 18 | if(len % 2 == 0) { 19 | return true; 20 | }else { 21 | return false; 22 | } 23 | 24 | //return len % 2 == 0; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/day15/PrintNumbers.java: -------------------------------------------------------------------------------- 1 | package day15; 2 | 3 | public class PrintNumbers { 4 | public static void main(String[] args) { 5 | // printEvenNumbers(10); 6 | printEvenNumbers(1000); 7 | } 8 | 9 | public static void printEvenNumbers(int number) { 10 | // number - 10 11 | // only even number from 1 to 10 inclusive 12 | // 2, 4, 6, 8, 10 13 | 14 | // number - 100 15 | // 2, 4, 6, 8, 10, 12, 14 ..... 16 | 17 | // for loop (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) 18 | // i % 2 == 0 -> true; to figure out if number is even 19 | 20 | for(int i = 1; i <= number; i++) { 21 | if(i % 2 == 0) { 22 | System.out.println(i); 23 | } 24 | } 25 | 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/day20/WarmUp.java: -------------------------------------------------------------------------------- 1 | package day20; 2 | 3 | public class WarmUp { 4 | public static void main(String[] args) { 5 | int[] nums = {3, 2, 4, 2}; 6 | System.out.println(isSeven(nums)); // false 7 | 8 | int[] nums1 = {3, 2, 4, 2, 7, 8, 9}; 9 | System.out.println(isSeven(nums1)); // true 10 | 11 | } 12 | 13 | /** 14 | * Method will accept int[] number 15 | * it will return true if array contains 7 16 | * otherwise it will return false 17 | * 18 | * [3, 2, 4, 2, 8, 9] 19 | */ 20 | public static boolean isSeven(int[] num) { 21 | for(int i = 0; i < num.length; i++) { 22 | if(num[i] == 7) { 23 | return true; 24 | } 25 | } 26 | return false; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/day21/WarmUp.java: -------------------------------------------------------------------------------- 1 | package day21; 2 | 3 | public class WarmUp { 4 | public static void main(String[] args) { 5 | // 0 1 2 3 4 5 6 6 | int[] numArr = {0, 8, 6, 5, 2, -1, 4}; 7 | 8 | int index = getSmallestIndex(numArr); 9 | System.out.println(index); // 5 10 | 11 | int[] numArr1 = {3, 5 ,7}; 12 | System.out.println(getSmallestIndex(numArr1)); // 0 13 | } 14 | 15 | public static int getSmallestIndex(int[] num) { 16 | int min = num[0]; 17 | int minIndex = 0; 18 | 19 | for(int i = 0; i < num.length; i++) { 20 | if(min > num[i]) { 21 | min = num[i]; 22 | minIndex = i; 23 | } 24 | } 25 | 26 | return minIndex; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/day28/SbReview.java: -------------------------------------------------------------------------------- 1 | package day28; 2 | 3 | public class SbReview { 4 | public static void main(String[] args) { 5 | StringBuilder sb = new StringBuilder("Good"); 6 | sb.append("Morning"); 7 | 8 | // Some of the String methods we can use in StringBuilder 9 | System.out.println(sb); 10 | System.out.println(sb.getClass()); 11 | 12 | // Convert StringBuilder to String 13 | String str = sb.toString(); 14 | System.out.println(str); 15 | System.out.println(str.getClass()); 16 | 17 | // Convert String to StringBuilder 18 | StringBuilder sb1 = new StringBuilder(str); 19 | System.out.println(sb1); 20 | 21 | sb1.reverse(); 22 | sb1.delete(0, 2); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/day35/NormalBox.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public class NormalBox implements Box { 4 | private String[] box = new String[15]; 5 | private int numberOfItems; 6 | 7 | @Override 8 | public void putInside(String item) { 9 | for(int i = 0; i < box.length; i++) { 10 | if(box[i] == null) { 11 | box[i] = item; 12 | numberOfItems++; 13 | return; 14 | } 15 | } 16 | } 17 | 18 | @Override 19 | public String getItem(int index) { 20 | return box[index]; 21 | } 22 | 23 | @Override 24 | public int getFreeSpace() { 25 | return box.length - numberOfItems; 26 | } 27 | 28 | @Override 29 | public int getNumberOfItems() { 30 | return numberOfItems; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/day35/SmallBox.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public class SmallBox implements Box{ 4 | private String[] box = new String[5]; 5 | private int numberOfItems; 6 | 7 | @Override 8 | public void putInside(String item) { 9 | for(int i = 0; i < box.length; i++) { 10 | if(box[i] == null) { 11 | box[i] = item; 12 | numberOfItems++; 13 | return; 14 | } 15 | } 16 | } 17 | 18 | @Override 19 | public String getItem(int index) { 20 | return box[index]; 21 | } 22 | 23 | @Override 24 | public int getFreeSpace() { 25 | return box.length - numberOfItems; 26 | } 27 | 28 | @Override 29 | public int getNumberOfItems() { 30 | return numberOfItems; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/day11/CircleArea.java: -------------------------------------------------------------------------------- 1 | package day11; 2 | import java.util.Scanner; 3 | 4 | public class CircleArea { 5 | public static final double PI = 3.14159; 6 | 7 | public static void main(String[] args) { 8 | //double pi = 3.14159; // we gonna use constant PI 9 | double radius; 10 | double area; 11 | 12 | //PI = 4.14; // We cannot change the value of final variables 13 | 14 | Scanner sc = new Scanner(System.in); 15 | 16 | System.out.println("Enter the radius of a circle: "); 17 | radius = sc.nextDouble(); 18 | area = PI * (radius * radius); 19 | 20 | System.out.println("A circle of radius " + radius); 21 | System.out.println("has an area of " + area); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/day16/Pyramid.java: -------------------------------------------------------------------------------- 1 | package day16; 2 | import java.util.Scanner; 3 | 4 | public class Pyramid { 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | System.out.println("Provide a number:"); 8 | 9 | int number = scanner.nextInt(); 10 | 11 | outer: 12 | for(int j = 0; j < number; j++) { 13 | String block = "#"; 14 | innerOne: 15 | for (int i = 0; i < number; i++) { 16 | System.out.println(block); 17 | block = block + "#"; 18 | } 19 | 20 | innerTwo: 21 | for (int i = 0; i <= number; i++) { 22 | System.out.println(block.substring(0, block.length() - i)); 23 | } 24 | } 25 | // nested loops 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/day23/TernaryOperator.java: -------------------------------------------------------------------------------- 1 | package day23; 2 | 3 | public class TernaryOperator { 4 | public static void main(String[] args) { 5 | // true false 6 | // booleanCondition ? expression : expression; 7 | 8 | int grade = 190; 9 | 10 | String name = grade > 100? "John" : "Smith"; 11 | System.out.println(name); 12 | 13 | // if(grade > 100) { 14 | // name = "John"; 15 | // } else { 16 | // name = "Smith"; 17 | // } 18 | 19 | 20 | // bool ? exp : (bool ? exp : exp) 21 | 22 | int num = 7 > 8 ? 100 : ( 9 > 8 ? 150 : 200); 23 | 24 | System.out.println(num); 25 | 26 | System.out.println(8 > 9 ? "Hello" : 12345); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/day17/Student.java: -------------------------------------------------------------------------------- 1 | package day17; 2 | 3 | public class Student { 4 | public String name; 5 | public int age; 6 | 7 | public static void main(String[] args) { 8 | Student s = new Student(); 9 | s.name = "Akylbek"; 10 | s.age = 31; 11 | 12 | Student s1 = new Student(); 13 | s1.name = "Mark"; 14 | s1.age = 27; 15 | 16 | s = s1; 17 | Student s2 = s1; 18 | System.out.println(s2.name); // Mark 3, Akylbek 1 19 | 20 | // when == operator is used with references it will return true if they refer two the same object 21 | 22 | System.out.println(s == s1); // true 23 | 24 | Student s3 = new Student(); 25 | 26 | System.out.println(s3 == s); // false 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/day39/DeleteHelper.java: -------------------------------------------------------------------------------- 1 | package day39; 2 | 3 | import java.io.File; 4 | 5 | public class DeleteHelper { 6 | public static void main(String[] args) { 7 | deleteAll("C:/Users/Beknazar/Desktop/tmp"); 8 | } 9 | 10 | public static void deleteAll(String path) { 11 | File dir = new File(path); 12 | 13 | // if we delete non empty folder it will return false 14 | if(!dir.delete()) { 15 | File[] files = dir.listFiles(); 16 | for(File file : files) { 17 | deleteAll(file.getAbsolutePath()); 18 | } 19 | 20 | // in the end we need to delete directory as well 21 | dir.delete(); 22 | } 23 | 24 | System.out.println(dir.getAbsolutePath() + " : DELETED."); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/day10/Password.java: -------------------------------------------------------------------------------- 1 | package day10; 2 | import java.util.Scanner; 3 | 4 | public class Password { 5 | public static void main(String[] args) { 6 | // .length(); returns number of letters in the String 7 | 8 | Scanner sc = new Scanner(System.in); 9 | System.out.println("Type new password: "); 10 | 11 | String password = sc.next(); 12 | int passwordLen = password.length(); 13 | 14 | if(passwordLen < 5) { 15 | System.out.println("Rejected - Weak Password"); 16 | }else if(passwordLen >= 5 && passwordLen <= 10) { 17 | // 5 - 10 18 | System.out.println("Accepted - Good Password!"); 19 | }else { 20 | System.out.println("Rejected - Password to forget"); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/day7/InRange.java: -------------------------------------------------------------------------------- 1 | package day7; 2 | 3 | public class InRange { 4 | public static void main(String[] args) { 5 | int numberFormTerminal = Integer.parseInt(args[0]); 6 | System.out.println(inRange(numberFormTerminal)); 7 | } 8 | 9 | // Write method that accepts one int number 10 | // if the number is within a range from 10 to 20 inclusive return true 11 | // otherwise return false 12 | 13 | public static boolean inRange(int number) { 14 | // and 15 | if(number >= 10 && number <= 20) { 16 | return true; 17 | // if(number <= 20) { 18 | // return true; 19 | // }else { 20 | // return false; 21 | // } 22 | } else { 23 | return false; 24 | } 25 | } 26 | 27 | 28 | } -------------------------------------------------------------------------------- /src/day4/ArithmeticOperators.java: -------------------------------------------------------------------------------- 1 | package day4; 2 | 3 | public class ArithmeticOperators { 4 | public static void main(String[] args) { 5 | // + - * / 6 | // % mod/remainder 7 | int num = 7; 8 | int num2 = 2; 9 | 10 | // 7 / 2 = 3 -> because int can hold only whole numbers 11 | System.out.println(num / num2); // 3 12 | 13 | // even you store value into double output is 3. Because both num and num2 are int (whole numbers) 14 | double res = num / num2; 15 | System.out.println(res); // 3 16 | 17 | double d1 = 7.0; 18 | double d2 = 2.0; 19 | System.out.println("d1 / d2 : "+d1 / d2); 20 | 21 | int i = 7; 22 | double d3 = i; 23 | System.out.println("d3 : "+d3); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/day31/TreeDemo.java: -------------------------------------------------------------------------------- 1 | package day31; 2 | 3 | public class TreeDemo { 4 | public static void main(String[] args) { 5 | // TreeNode root = new TreeNode(8); 6 | // 7 | // TreeNode node = new TreeNode(50); 8 | // 9 | // if(root.value >= node.value) { 10 | // root.leftChild = node; 11 | // }else { 12 | // root.rightChild = node; 13 | // } 14 | 15 | Tree treeNums = new Tree(); 16 | treeNums.add(8); 17 | treeNums.add(4); 18 | treeNums.add(50); 19 | treeNums.add(2); 20 | treeNums.add(7); 21 | treeNums.add(30); 22 | treeNums.add(189); 23 | treeNums.add(1); 24 | treeNums.add(25); 25 | treeNums.add(49); 26 | treeNums.add(456); 27 | 28 | treeNums.display(); 29 | 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/day32/CustomMethods.java: -------------------------------------------------------------------------------- 1 | package day32; 2 | 3 | public class CustomMethods { 4 | String wordToPrint; 5 | // void 6 | // return methods 7 | // arguments 8 | 9 | public void print10() { 10 | for(int i = 0; i < 10; i++) { 11 | System.out.println(wordToPrint); 12 | } 13 | } 14 | 15 | public void print10(String str) { 16 | for(int i = 0; i < 10; i++) { 17 | System.out.println(str); 18 | } 19 | } 20 | 21 | public String copy3(String str) { 22 | //System.out.println("Hello"); 23 | return str + str + str; 24 | } 25 | 26 | public int getMax(int[] nums) { 27 | return 0; 28 | } 29 | 30 | public static void sayHelloToWorld() { 31 | System.out.println("Hello, World!"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/day34/Cat.java: -------------------------------------------------------------------------------- 1 | package day34; 2 | 3 | public class Cat { 4 | public String name; 5 | 6 | @Override 7 | public int hashCode() { 8 | final int prime = 31; 9 | int result = 1; 10 | result = prime * result + ((name == null) ? 0 : name.hashCode()); 11 | return result; 12 | } 13 | 14 | @Override 15 | public boolean equals(Object obj) { 16 | if (this == obj) 17 | return true; 18 | if (obj == null) 19 | return false; 20 | if (getClass() != obj.getClass()) 21 | return false; 22 | Cat other = (Cat) obj; 23 | if (name == null) { 24 | if (other.name != null) 25 | return false; 26 | } else if (!name.equals(other.name)) 27 | return false; 28 | return true; 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/day38/Person.java: -------------------------------------------------------------------------------- 1 | package day38; 2 | 3 | public class Person { 4 | private String name; 5 | private int age; 6 | 7 | public String getName() { 8 | return name; 9 | } 10 | 11 | public void setName(String name) { 12 | 13 | if(name == null) { 14 | throw new RuntimeException("Invalid input for Person name"); 15 | } 16 | 17 | this.name = name; 18 | } 19 | 20 | public int getAge() { 21 | return age; 22 | } 23 | 24 | public void setAge(int age) { 25 | if(age < 1) { 26 | throw new RuntimeException("Invalid age"); 27 | } 28 | 29 | this.age = age; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "Person [name=" + name + ", age=" + age + "]"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/day40/TryWithResources.java: -------------------------------------------------------------------------------- 1 | package day40; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | 8 | public class TryWithResources { 9 | public static void main(String[] args) { 10 | File file = new File("C:/Users/Beknazar/Desktop/notes.txt"); 11 | 12 | // try catch statement with resources try(resource declaration) 13 | // it will automatically close the resource 14 | try(InputStream in = new FileInputStream(file)) { 15 | 16 | int b; 17 | while((b = in.read()) != -1) { 18 | System.out.print((char)b); 19 | } 20 | 21 | }catch(IOException e) { 22 | System.out.println(e.getMessage()); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/day51/ReadInventoryThread.java: -------------------------------------------------------------------------------- 1 | package day51; 2 | 3 | public class ReadInventoryThread implements Runnable { 4 | 5 | @Override 6 | public void run() { 7 | for(int i = 1; i < 5; i++) { 8 | System.out.println(i); 9 | } 10 | } 11 | 12 | public static void main(String[] args) { 13 | // 1. extends Thread class 14 | // 2. implement Runnable interface 15 | // 3. By using ServerWorkers interface API (task) 16 | 17 | Thread thread1 = new Thread(new ReadInventoryThread()); 18 | Thread thread2 = new Thread(new ReadInventoryThread()); 19 | 20 | thread1.start(); 21 | thread2.start(); 22 | 23 | // 1 24 | // 1 25 | // 2 26 | // 3 27 | // 4 28 | // 2 29 | // 3 30 | // 4 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/day9/Car.java: -------------------------------------------------------------------------------- 1 | package day9; 2 | 3 | public class Car { 4 | // public - can be used from any class 5 | // private - can be used only inside same class 6 | // protected - can be used in the same package or in subclasses 7 | // default access - can be used only in the same package 8 | 9 | public String model; 10 | int year; 11 | protected double price; 12 | private String color; 13 | String name; 14 | 15 | public void drive() { 16 | color = "black"; 17 | } 18 | 19 | private void stop() { 20 | System.out.println("Stop!"); 21 | } 22 | 23 | protected void turnLeft() { 24 | System.out.println("Turning left"); 25 | } 26 | 27 | void reverse() { 28 | System.out.println("Reversing.."); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/day15/LuckyNumber.java: -------------------------------------------------------------------------------- 1 | package day15; 2 | import java.util.Scanner; 3 | 4 | public class LuckyNumber { 5 | public static void main(String[] args) { 6 | // assume seven (7) is lucky number 7 | // Keep asking from a user a number 8 | // If provided number is 7 stop asking and print: 9 | // "Jackpot! It took steps to get it." 10 | // otherwise keep asking a number 11 | 12 | Scanner input = new Scanner(System.in); 13 | int userNumber; 14 | int steps = 0; 15 | do { 16 | steps++; 17 | System.out.println("Provide number:"); 18 | userNumber = input.nextInt(); 19 | 20 | }while(userNumber != 7); 21 | 22 | System.out.println("Jackpot! It took " + steps + " steps to get it."); 23 | } 24 | } -------------------------------------------------------------------------------- /src/day19/WarmUp.java: -------------------------------------------------------------------------------- 1 | package day19; 2 | 3 | public class WarmUp { 4 | public static void main(String[] args) { 5 | String str = new String("apple"); // String Pool: 6 | // ["apple"] ["john"] 7 | String str1 = "apple"; 8 | String name = "john"; 9 | String str2 = "apple"; 10 | 11 | 12 | System.out.println(str.equals(str1)); // true 13 | System.out.println(str == str1); // false 14 | System.out.println(str1.equals(str2)); // true 15 | System.out.println(str1 == str2); // true 16 | 17 | // Can you tell what's the output from this program? 18 | 19 | // == to compare if they are pointing to the same object 20 | // String Pool 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/day23/Primitives.java: -------------------------------------------------------------------------------- 1 | package day23; 2 | 3 | public class Primitives { 4 | public static void main(String[] args) { 5 | byte bNum = 5; 6 | short shNum = 88; 7 | int num = 100; 8 | long lNum = 1000; 9 | 10 | float fNum = 5.6f; 11 | double dNum = 8.99; 12 | 13 | char ch = 'U'; 14 | boolean bFlag = false; 15 | 16 | // byte -> short -> int -> long -> float -> double 17 | byte bNum1 = 99; 18 | int num1 = bNum1; // auto casting here. byte is smaller than int so it will be auto casting 19 | 20 | short shNum1 = (short)num1; // casting from int to short 21 | 22 | char ch1 = 'a'; 23 | char ch2 = 'b'; 24 | System.out.println((int)ch1); 25 | System.out.println((int)ch2); 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/day24/PassByVal.java: -------------------------------------------------------------------------------- 1 | package day24; 2 | 3 | public class PassByVal { 4 | public static void main(String[] args) { 5 | // all the primitives are pass by value 6 | // String is pass by value because its immutable 7 | 8 | int num = 9; 9 | changeVal(num); 10 | System.out.println(num); 11 | 12 | 13 | String str = "orange"; 14 | changeVal(str); 15 | System.out.println(str); 16 | 17 | char ch = 'a'; 18 | chaneVal(ch); 19 | System.out.println(ch); 20 | } 21 | 22 | public static void chaneVal(char ch) { 23 | ch = 'b'; 24 | } 25 | 26 | public static void changeVal(int num) { 27 | num = 10; 28 | } 29 | 30 | public static void changeVal(String str) { 31 | str = "apple"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/day13/Hundred.java: -------------------------------------------------------------------------------- 1 | package day13; 2 | 3 | public class Hundred { 4 | public static void main(String[] args) { 5 | // Write a program that will print numbers from 1 to 10 in the same line with space separator 6 | // ex: 1 2 3 4 5 6 7 8 9 10 7 | // Use while loop 8 | 9 | int index = 1; 10 | while(index <= 10) { 11 | System.out.print(index+" "); 12 | index++; 13 | } 14 | 15 | System.out.println(); 16 | 17 | int indexTwo = 10; 18 | while(indexTwo >= 1) { 19 | System.out.print(indexTwo+" "); 20 | indexTwo--; 21 | } 22 | 23 | // Write a program that will print number from 10 to 1 in the same line with space separator 24 | // ex: 10 9 8 7 6 5 4 3 2 1 25 | // Use while loop 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/day37/TimePractice.java: -------------------------------------------------------------------------------- 1 | package day37; 2 | 3 | import java.time.LocalTime; 4 | import java.time.format.DateTimeFormatter; 5 | 6 | public class TimePractice { 7 | public static void main(String[] args) { 8 | // LocalDate class for Date 9 | // LocalTime class for Time 10 | // LocalDateTime class this is for both 11 | 12 | LocalTime now = LocalTime.now(); 13 | System.out.println("TIME: " + now); 14 | 15 | LocalTime afterOneHour = now.plusHours(1).plusMinutes(30); 16 | System.out.println("TIME: " + afterOneHour); 17 | 18 | DateTimeFormatter f = DateTimeFormatter.ofPattern("HH:mm"); 19 | String hoursAndMinOnly = f.format(afterOneHour); 20 | System.out.println(hoursAndMinOnly); 21 | 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/day41/AnimalBuilderDemo.java: -------------------------------------------------------------------------------- 1 | package day41; 2 | 3 | import java.util.Arrays; 4 | 5 | public class AnimalBuilderDemo { 6 | public static void main(String[] args) { 7 | //Animal animal = new Animal("Cat", 0, null, null null null null null null); 8 | //Animal animal0 = new Animal("Cat"); 9 | 10 | AnimalBuilder aBuilder = new AnimalBuilder(); 11 | aBuilder.setName("Cat").setAge(2); 12 | Animal animal = aBuilder.build(); 13 | System.out.println(animal); 14 | 15 | 16 | Animal animal2 = new AnimalBuilder().setName("dog").setAge(4).build(); 17 | System.out.println(animal2); 18 | 19 | Animal animal3 = new AnimalBuilder().setName("flamingo").setFavoriteFood(Arrays.asList("fish", "sugar")).build(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/day15/RecapLoops.java: -------------------------------------------------------------------------------- 1 | package day15; 2 | 3 | public class RecapLoops { 4 | public static void main(String[] args) { 5 | // while loops 6 | 7 | int count = 0; 8 | while(count < 10) 9 | { 10 | System.out.print(count + " "); 11 | count++; 12 | } 13 | 14 | int count1 = 0; 15 | do { 16 | System.out.println(count1); 17 | count1++; 18 | }while(count1 < 10); 19 | 20 | 21 | // for loop 22 | for(int i = 0, g = 3 ; i < 1000 || g < 4 ; i++, g++) 23 | { 24 | int num = 4; 25 | boolean b = false; 26 | 27 | continue; 28 | // some code 29 | } 30 | // System.out.println(num); 31 | 32 | for(;;) 33 | { 34 | System.out.println("Hello!"); 35 | break; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/day18/CatDog.java: -------------------------------------------------------------------------------- 1 | package day18; 2 | 3 | public class CatDog { 4 | public static void main(String[] args) { 5 | 6 | boolean res = catDog("catdocat"); 7 | System.out.println(res); 8 | } 9 | 10 | public static boolean catDog(String str) { 11 | // count cat 12 | // count dog 13 | int catCount = 0; 14 | int dogCount = 0; 15 | 16 | for(int i = 0; i < str.length() - 2; i++) { 17 | // f && 18 | if(str.charAt(i) == 'c' && str.charAt(i + 1) == 'a' && str.charAt(i + 2) == 't') { 19 | catCount++; 20 | } 21 | 22 | if(str.charAt(i) == 'd' && str.charAt(i + 1) == 'o' && str.charAt(i + 2) == 'g') { 23 | dogCount++; 24 | } 25 | } 26 | 27 | return catCount == dogCount; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/day28/ValAndRef.java: -------------------------------------------------------------------------------- 1 | package day28; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class ValAndRef { 7 | public static void main(String[] args) { 8 | int num = 5; 9 | 10 | System.out.println(num); 11 | changeVal(num); 12 | 13 | System.out.println(num); 14 | 15 | List list = new ArrayList<>(); 16 | list.add("orange"); 17 | System.out.println(list); 18 | 19 | changeVal(list); 20 | 21 | System.out.println(list); 22 | } 23 | 24 | public static void changeVal(List list) { 25 | list.set(0, "apple"); 26 | // list = new ArrayList<>(); 27 | // list.add("apple"); 28 | } 29 | 30 | public static void changeVal(int num) { 31 | num = 10; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/day13/InterestRate.java: -------------------------------------------------------------------------------- 1 | package day13; 2 | 3 | public class InterestRate { 4 | public static final double INTEREST_RATE = 1.5; 5 | 6 | public static void main(String[] args) { 7 | double balance = 50000.00; 8 | double initialBalance = balance; 9 | 10 | int months = 36; 11 | 12 | int count = 0; 13 | while(months > count) { 14 | balance = balance + (balance * INTEREST_RATE / 100); 15 | count++; 16 | } 17 | 18 | balance = Math.round(balance); 19 | 20 | System.out.println("Total balance: " + balance); 21 | System.out.println("Initial balance: " + initialBalance); 22 | System.out.println("Iterest earned: " + (balance - initialBalance)); 23 | System.out.println("Period(Months): " + months); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/day8/MaxNumber.java: -------------------------------------------------------------------------------- 1 | package day8; 2 | 3 | public class MaxNumber { 4 | public static void main(String[] args) { 5 | System.out.println(getMax(1, 2)); // 2 6 | System.out.println(getMax(5, 3)); // 5 7 | System.out.println(getMax(9, 11, 3, 6)); // 11 8 | System.out.println(getMax(9, 11, 3, 16)); // 16 9 | } 10 | 11 | public static int getMax(int numOne, int numTwo) { 12 | if (numOne > numTwo) { 13 | return numOne; 14 | }else { 15 | return numTwo; 16 | } 17 | } 18 | 19 | public static int getMax(int numOne, int numTwo, int numThree, int numFour) { 20 | int maxOne = getMax(numOne, numTwo); 21 | int maxTwo = getMax(numThree, numFour); 22 | int max = getMax(maxOne, maxTwo); 23 | return max; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/day9/RandomNumbers.java: -------------------------------------------------------------------------------- 1 | package day9; 2 | import java.util.Random; 3 | 4 | 5 | public class RandomNumbers { 6 | public static void main(String[] args) { 7 | Random random = new Random(); 8 | 9 | // 0 -> 5 10 | int rNumber = random.nextInt(6); 11 | System.out.println(rNumber); 12 | 13 | if(rNumber == 0) { 14 | System.out.println("Vladyslav"); 15 | }else if(rNumber == 1) { 16 | System.out.println("Grigore"); 17 | }else if(rNumber == 2) { 18 | System.out.println("Jildiz"); 19 | }else if(rNumber == 3) { 20 | System.out.println("Cristina"); 21 | }else if(rNumber == 4) { 22 | System.out.println("Andrei"); 23 | }else { 24 | System.out.println("Boris"); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/day12/Rating.java: -------------------------------------------------------------------------------- 1 | package day12; 2 | 3 | public class Rating { 4 | enum MovieRating {EXCELLENT, AVERAGE, BAD}; 5 | 6 | public static void main(String[] args) { 7 | String message = getRatingMessage(MovieRating.EXCELLENT); 8 | System.out.println(message); 9 | } 10 | 11 | public static String getRatingMessage(MovieRating rating) { 12 | String message; 13 | 14 | switch(rating) { 15 | case EXCELLENT: 16 | message = "You must see this movie!"; 17 | break; 18 | case AVERAGE: 19 | message = "This movie is OK, but not great."; 20 | break; 21 | case BAD: 22 | message = "Skip it!"; 23 | break; 24 | default: 25 | message = "Something is wrong"; 26 | break; 27 | } 28 | 29 | return message; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/day12/WarmUp.java: -------------------------------------------------------------------------------- 1 | package day12; 2 | 3 | public class WarmUp { 4 | public static void main(String[] args) { 5 | System.out.println(removeSpaces(" ap ple")); // "apple" 6 | System.out.println(removeSpaces(" orange ")); // "orange" 7 | System.out.println(removeSpaces("b anana ")); // "banana" 8 | System.out.println(removeSpaces("ki wi")); //"kiwi" 9 | } 10 | 11 | public static String removeSpaces(String str) { 12 | // return str.replace(" ", ""); 13 | 14 | str = str.trim(); 15 | 16 | if(str.contains(" ")) { 17 | String firstPart = str.substring(0, str.indexOf(" ")); 18 | String secondPart = str.substring(str.indexOf(" ") + 1); 19 | return firstPart + secondPart; 20 | } 21 | 22 | return str; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/day11/WarmUp.java: -------------------------------------------------------------------------------- 1 | package day11; 2 | 3 | public class WarmUp { 4 | public static void main(String[] args) { 5 | System.out.println(isValidAmount("$200.01 USD")); // false 6 | System.out.println(isValidAmount("$1200.00 USD")); // true 7 | System.out.println(isValidAmount("$900.99 USD")); // false 8 | System.out.println(isValidAmount("$100000.00 USD")); // true 9 | } 10 | 11 | public static boolean isValidAmount(String amount) { 12 | amount = amount.substring(1, amount.indexOf(" ")); 13 | // amount = amount.replace("$", ""); 14 | // amount = amount.replace("USD", ""); 15 | 16 | double dAmount = Double.parseDouble(amount); 17 | if(dAmount >= 1000.00) { 18 | return true; 19 | }else { 20 | return false; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/day18/XyzThere.java: -------------------------------------------------------------------------------- 1 | package day18; 2 | 3 | public class XyzThere { 4 | public static void main(String[] args) { 5 | boolean res = xyzThere("xyz.abc"); 6 | System.out.println(res); 7 | } 8 | 9 | public static boolean xyzThere(String str) { 10 | for(int i = 0; i < str.length() - 2; i++) { 11 | char one = str.charAt(i); 12 | char two = str.charAt(i + 1); 13 | char three = str.charAt(i + 2); 14 | 15 | if(one == 'x' && two == 'y' && three == 'z') { 16 | if(i == 0) { 17 | return true; 18 | } 19 | 20 | if(str.charAt(i - 1) != '.') { 21 | return true; 22 | } 23 | } 24 | } 25 | 26 | return false; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/day33/PersonDemo.java: -------------------------------------------------------------------------------- 1 | package day33; 2 | 3 | public class PersonDemo { 4 | public static void main(String[] args) { 5 | Person john = new Person(); 6 | //System.out.println(john); 7 | john.firstName = "John"; 8 | john.lastName = "Doe"; 9 | 10 | String fullName = john.getFullName(); 11 | //System.out.println(fullName); 12 | john.printDetails(); 13 | 14 | System.out.println("--------"); 15 | 16 | Person obj = new Person(); 17 | obj.printDetails(); 18 | 19 | System.out.println("--------"); 20 | 21 | //john = obj; 22 | obj = john; 23 | john.printDetails(); 24 | 25 | obj.firstName = "Bob"; 26 | 27 | System.out.println("--------"); 28 | john.printDetails(); 29 | 30 | 31 | 32 | 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/day18/EndOther.java: -------------------------------------------------------------------------------- 1 | package day18; 2 | 3 | public class EndOther { 4 | public static void main(String[] args) { 5 | // 01234 012 6 | boolean res = endOther("Hiabc", "abc"); 7 | System.out.println(res); 8 | } 9 | 10 | // endOther('abc', 'abXabc') 11 | public static boolean endOther(String a, String b) { 12 | a = a.toLowerCase(); 13 | b = b.toLowerCase(); 14 | 15 | int aLength = a.length(); 16 | int bLength = b.length(); 17 | 18 | if(aLength > bLength) { 19 | return a.substring(aLength - bLength).equals(b); 20 | }else { 21 | return b.substring(bLength - aLength).equals(a); 22 | } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/day22/CustomObjects.java: -------------------------------------------------------------------------------- 1 | package day22; 2 | 3 | public class CustomObjects { 4 | public static void main(String[] args) { 5 | Student[] javaClass = new Student[4]; 6 | 7 | Student s1 = new Student(1, "John"); 8 | javaClass[0] = s1; 9 | 10 | Student s2 = new Student(2, "Smith"); 11 | javaClass[1] = s2; 12 | 13 | javaClass[2] = new Student(3, "Alex"); 14 | javaClass[3] = new Student(4, "Kuba"); 15 | 16 | for(Student student : javaClass) { 17 | System.out.println(student.name + ", id: " + student.id); 18 | } 19 | 20 | 21 | } 22 | } 23 | 24 | class Student{ 25 | long id; 26 | String name; 27 | 28 | public Student(long idFromUser, String nameFromUser) { 29 | id = idFromUser; 30 | name = nameFromUser; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/day40/Assignment3.java: -------------------------------------------------------------------------------- 1 | package day40; 2 | 3 | import java.io.BufferedWriter; 4 | import java.io.File; 5 | import java.io.FileWriter; 6 | import java.io.IOException; 7 | 8 | public class Assignment3 { 9 | public static void main(String[] args) throws IOException{ 10 | 11 | // 1. Create file under package 40 with name Numbers 12 | // 2. Write to file number from 1 to 1000 13 | 14 | File file = new File("src/day40/Numbers"); 15 | 16 | try(BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { 17 | for(int i = 1; i <= 1000; i++) { 18 | writer.write(String.valueOf(i)); 19 | writer.newLine(); 20 | } 21 | }catch(IOException e) { 22 | System.out.println(e.getMessage()); 23 | } 24 | 25 | } 26 | } 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/day8/AirPressure.java: -------------------------------------------------------------------------------- 1 | package day8; 2 | 3 | public class AirPressure { 4 | public static void main(String[] args) { 5 | // create a method to calculate air pressure message 6 | // if pressure is from 13.5 to 15.5 then it's "normal pressure" 7 | // if pressure is less then 13.5 then it's "low pressure" 8 | // if pressure is greater then 15.5 then it's "high pressure" 9 | 10 | double pressure = 14.5; 11 | 12 | // pressure >= 13.5 and pressure <= 15.5 13 | if(pressure >= 13.5 && pressure <= 15.5) { 14 | System.out.println("normal pressure"); 15 | } 16 | 17 | if(pressure < 13.5) { 18 | System.out.println("low pressure"); 19 | } 20 | 21 | if(pressure > 15.5) { 22 | System.out.println("high pressure"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/day8/PersonInfo.java: -------------------------------------------------------------------------------- 1 | package day8; 2 | import java.util.Scanner; 3 | 4 | public class PersonInfo { 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | 8 | String name; 9 | int age; 10 | String city; 11 | 12 | System.out.println("What's your name?"); 13 | name = scanner.next(); 14 | 15 | System.out.println("What's your age " + name + "?"); 16 | age = scanner.nextInt(); 17 | 18 | System.out.println("Where are you from?"); 19 | city = scanner.next(); 20 | 21 | System.out.println("-- Submitted --"); 22 | System.out.println("Name: " + name); 23 | System.out.println("Age: " + age); 24 | System.out.println("City: " + city); 25 | System.out.println("---------------"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/day37/StringToDates.java: -------------------------------------------------------------------------------- 1 | package day37; 2 | 3 | import java.time.DayOfWeek; 4 | import java.time.LocalDate; 5 | import java.time.format.DateTimeFormatter; 6 | 7 | public class StringToDates { 8 | public static void main(String[] args) { 9 | String someDate = "2002-02-08"; // this is default format so converting directly 10 | LocalDate dateToCheck = LocalDate.parse(someDate); 11 | System.out.println(dateToCheck.getDayOfWeek()); 12 | System.out.println(dateToCheck.getDayOfWeek().equals(DayOfWeek.MONDAY)); 13 | 14 | String someDate2 = "June 19 1996"; 15 | DateTimeFormatter f = DateTimeFormatter.ofPattern("MMMM dd uuuu"); 16 | LocalDate date2ToCheck = LocalDate.parse(someDate2, f); 17 | System.out.println(date2ToCheck.getDayOfWeek()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/day5/Project.java: -------------------------------------------------------------------------------- 1 | package day5; 2 | 3 | public class Project { 4 | public static void main (String[] args) { 5 | int amount = Integer.parseInt(args[0]); 6 | int cents = amount; 7 | 8 | int quarters = amount / 25; 9 | amount = amount % 25; 10 | 11 | int dimes = amount / 10; 12 | amount = amount % 10; 13 | 14 | int nickels = amount / 5; 15 | amount = amount % 5; 16 | 17 | int pennies = amount; 18 | 19 | System.out.println(cents + " cents in coins:"); 20 | System.out.println(quarters + " quarters"); 21 | System.out.println(dimes + " dimes"); 22 | System.out.println(nickels + " nickels"); 23 | System.out.println(pennies + " pennies"); 24 | } 25 | } -------------------------------------------------------------------------------- /src/day10/UpperAndLowerCaseStr.java: -------------------------------------------------------------------------------- 1 | package day10; 2 | 3 | public class UpperAndLowerCaseStr { 4 | public static void main(String[] args) { 5 | // .toUpperCase() returns string in upper cases 6 | // .toLowerCase() returns string in lower cases 7 | // String is immutable. it means you cannot change existing one. 8 | 9 | String word = "apple"; 10 | System.out.println(word); 11 | 12 | word = word.toUpperCase(); 13 | System.out.println(word); 14 | 15 | String str = "orange"; 16 | System.out.println(str.toUpperCase()); // 16 ORANGE 17 | System.out.println(str); // 17 orange 18 | 19 | word = "BLOG"; 20 | System.out.println(word); 21 | System.out.println(word.toLowerCase()); 22 | 23 | //BREAK 10 min. Till 8:14 PM 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/day15/SumOfEvenNumbers.java: -------------------------------------------------------------------------------- 1 | package day15; 2 | 3 | public class SumOfEvenNumbers { 4 | public static void main(String[] args) { 5 | int res = getSumOfEvenNum(100); 6 | System.out.println(res); // 30 7 | } 8 | 9 | public static int getSumOfEvenNum(int number) { 10 | // number is 10 11 | // 2, 4, 6, 8, 10 12 | // return 30; 13 | 14 | // number is 5 15 | // 2, 4 16 | // return 6; 17 | 18 | // 1) create a variable of type int to store sum of all even numbers 19 | // 2) for loop to get all the even numbers 20 | // 3) if i is even add to sum 21 | // 4) return sum 22 | 23 | int sum = 0; 24 | for(int i = 1; i <= number; i++) { 25 | if(i % 2 == 0) { 26 | sum = sum + i; 27 | } 28 | } 29 | 30 | return sum; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/day11/StrMethodsReview.java: -------------------------------------------------------------------------------- 1 | package day11; 2 | 3 | public class StrMethodsReview { 4 | public static void main(String[] args) { 5 | String str = "Java"; 6 | String str1 = "java"; 7 | System.out.println(str.equals(str1)); // false 8 | System.out.println(str.equalsIgnoreCase(str1)); // true 9 | 10 | String word = null; 11 | //int len = word.length(); 12 | //System.out.println(len); 13 | 14 | word = ""; 15 | 16 | System.out.println(word.length()); 17 | if(word.length() < 1) { 18 | System.out.println("It's empty"); 19 | }else { 20 | System.out.println("No, its not empty"); 21 | } 22 | 23 | if(word.isEmpty()) { 24 | System.out.println("It's empty"); 25 | }else { 26 | System.out.println("No, its not empty"); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/day24/String2.java: -------------------------------------------------------------------------------- 1 | package day24; 2 | 3 | public class String2 { 4 | private String str; 5 | 6 | public String2(String strInput) { 7 | str = strInput; 8 | } 9 | 10 | public String2 reverse() { 11 | String res = ""; 12 | for(int i = str.length() - 1; i >= 0; i--) { 13 | res += str.charAt(i); 14 | } 15 | 16 | return new String2(res); 17 | } 18 | 19 | public int length() { 20 | return str.length(); 21 | } 22 | 23 | public char charAt(int index) { 24 | return str.charAt(index); 25 | } 26 | 27 | public int indexOf(String ch) { 28 | return str.indexOf(ch); 29 | } 30 | 31 | public int indexOf(char ch) { 32 | return str.indexOf(ch); 33 | } 34 | 35 | //... 36 | 37 | 38 | public String toString() { 39 | return str; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/day33/PersonDemo3.java: -------------------------------------------------------------------------------- 1 | package day33; 2 | 3 | public class PersonDemo3 { 4 | public static void main(String[] args) { 5 | Person p1 = new Person(); 6 | p1.printDetails(); // null null 0 7 | System.out.println("-------"); 8 | 9 | p1.firstName = "Alex"; 10 | p1.lastName = "Rodriguez"; 11 | // Person.age = 40; 12 | p1.age = 40; 13 | 14 | Person p2 = new Person(); 15 | p2.printDetails(); // null null 40 16 | System.out.println("-------"); 17 | 18 | p2.firstName = "Ramesh"; 19 | p2.lastName = "Kanery"; 20 | p2.age = 45; 21 | 22 | p2.printDetails(); // Ramesh Kanery 45 23 | System.out.println("-------"); 24 | 25 | Person p3 = new Person(); 26 | p3.printDetails(); // null null 45 27 | System.out.println("-------"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/day39/FilePractice1.java: -------------------------------------------------------------------------------- 1 | package day39; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | public class FilePractice1 { 7 | public static void main(String[] args) throws IOException { 8 | // MAC: "/Users//Desktop/test.txt" 9 | 10 | File file = new File("C:/Users/Beknazar/Desktop/test.txt"); 11 | 12 | if(file.exists()) { 13 | System.out.println("File is exist"); 14 | System.out.println(file.getParent() + " : " + file.length() + " BYTES"); 15 | }else { 16 | file.createNewFile(); 17 | System.out.println("File is created: " + file.getName()); 18 | } 19 | 20 | // we can delete files as well 21 | // if file is deleted it will return true 22 | // otherwise false 23 | boolean isDeleted = file.delete(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/day39/FilePractice3.java: -------------------------------------------------------------------------------- 1 | package day39; 2 | 3 | import java.io.File; 4 | 5 | public class FilePractice3 { 6 | public static void main(String[] args) { 7 | File dir = new File("C:/Users/Beknazar/Desktop/sdet"); 8 | 9 | if(dir.isDirectory()) { 10 | // listFiles will return the files inside directory as File[] array 11 | File[] filesInside = dir.listFiles(); 12 | 13 | for(File file : filesInside) { 14 | if(file.isFile()) { 15 | System.out.println(file.getName()); 16 | }else { 17 | 18 | File[] filesInside2 = file.listFiles(); 19 | for(File file2 : filesInside2) { 20 | if(file2.isFile()) { 21 | System.out.println(file2.getName()); 22 | } 23 | } 24 | 25 | } 26 | 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/day27/Person.java: -------------------------------------------------------------------------------- 1 | package day27; 2 | 3 | public class Person { 4 | private String name; 5 | 6 | public String getName() { 7 | return name; 8 | } 9 | 10 | public void setName(String name) { 11 | this.name = name; 12 | } 13 | 14 | @Override 15 | public int hashCode() { 16 | final int prime = 31; 17 | int result = 1; 18 | result = prime * result + ((name == null) ? 0 : name.hashCode()); 19 | return result; 20 | } 21 | 22 | @Override 23 | public boolean equals(Object obj) { 24 | Person person = (Person)obj; 25 | if(person.getName().equals(this.name)) { 26 | return true; 27 | } 28 | 29 | return false; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "Person [name=" + name + "]"; 35 | } 36 | 37 | 38 | 39 | } 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/day32/MethodsDemo.java: -------------------------------------------------------------------------------- 1 | package day32; 2 | 3 | public class MethodsDemo { 4 | 5 | public static void main(String[] args) { 6 | CustomMethods obj = new CustomMethods(); 7 | obj.wordToPrint = "Java"; 8 | 9 | obj.print10(); 10 | 11 | obj.print10("Orange"); 12 | 13 | String res = obj.copy3("Aaa"); 14 | System.out.println(res); 15 | 16 | int[] arr = {1, 2, 3, 4, 88, 7}; 17 | obj.getMax(arr); 18 | 19 | 20 | 21 | String str = "hello"; 22 | str = str.toUpperCase(); 23 | 24 | String str1 = new String("APPLE"); 25 | str1 = str1.toLowerCase(); 26 | 27 | // ======================== 28 | 29 | int i = Integer.parseInt("234"); 30 | 31 | String num = String.valueOf(342); 32 | 33 | CustomMethods.sayHelloToWorld(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/day35/BoxDemo.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public class BoxDemo { 4 | public static void main(String[] args) { 5 | //Box box = new Box(); it will not compile 6 | // We cannot create object from interface directly 7 | 8 | Box box = new SmallBox(); 9 | box.putInside("orange"); 10 | box.putInside("apple"); 11 | System.out.println("Free space: " + box.getFreeSpace()); 12 | 13 | System.out.println("--------"); 14 | Box box1 = new NormalBox(); 15 | box1.putInside("orange"); 16 | box1.putInside("apple"); 17 | System.out.println("Free space: " + box1.getFreeSpace()); 18 | 19 | Box box2 = new BigBox(); // size 100 20 | box2.putInside("pen"); 21 | box2.putInside("book"); 22 | System.out.println("Free space: " + box2.getFreeSpace()); 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/day12/MultipleBirths.java: -------------------------------------------------------------------------------- 1 | package day12; 2 | import java.util.Scanner; 3 | 4 | public class MultipleBirths { 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | int numberOfBabies; 8 | System.out.println("Enter number of babies:"); 9 | numberOfBabies = sc.nextInt(); 10 | 11 | switch(numberOfBabies) { 12 | case 1: 13 | System.out.println("Congratulations!"); 14 | break; 15 | case 2: 16 | System.out.println("Wow. Twins"); 17 | break; 18 | case 3: 19 | System.out.println("Wow. Triplets"); 20 | break; 21 | case 4: 22 | case 5: 23 | System.out.println("Unbelievable! " + numberOfBabies + " babies"); 24 | break; 25 | default: 26 | System.out.println("I don't believe you"); 27 | break; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/day5/ArithmeticOperators.java: -------------------------------------------------------------------------------- 1 | package day5; 2 | 3 | public class ArithmeticOperators { 4 | public static void main(String[] args) { 5 | // Data type output from expressions 6 | // byte -> short -> int -> long -> float -> double 7 | 8 | int num = 66; 9 | double dNum = 4.9; 10 | // (int)(int + double) 11 | int res = (int) (num + dNum); 12 | System.out.println(res); 13 | 14 | int lNum = 999999; 15 | //float fNum = 423.5F; 16 | short shNum = 5; 17 | // int * short 18 | int res2 = lNum * shNum; 19 | 20 | 21 | byte bNum = 5; 22 | short sh1 = 14; 23 | // short 24 | int num2 = sh1 - bNum; 25 | 26 | // b = (byte) int 27 | byte b = (byte) (num2 + bNum); 28 | System.out.println(b); 29 | 30 | } 31 | } -------------------------------------------------------------------------------- /src/day24/Assignment.java: -------------------------------------------------------------------------------- 1 | package day24; 2 | 3 | public class Assignment { 4 | public static void main(String[] args) { 5 | /* 6 | * Create a method that will accept diffrent number of String arguments 7 | * and return them as one String (joining) 8 | */ 9 | 10 | String str = join("hello", "abc"); 11 | System.out.println(str); // helloabc 12 | 13 | String str1 = join("a", "b", "c", "d"); 14 | System.out.println(str1); // abcd 15 | 16 | String[] arrStr = {"John", "Smith", "Alex"}; 17 | String str2 = join(arrStr); 18 | System.out.println(str2); // JohnSmithAlex 19 | } 20 | 21 | public static String join(String... strs) { 22 | String res = ""; 23 | 24 | for(String str : strs) { 25 | res += str; 26 | } 27 | 28 | return res; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/day8/Score.java: -------------------------------------------------------------------------------- 1 | package day8; 2 | 3 | public class Score { 4 | public static void main(String[] args) { 5 | char grade = 'C'; 6 | String scoreMessage; 7 | 8 | if(grade == 'A') { 9 | scoreMessage = "Your score more than 90"; 10 | }else if(grade == 'B') { 11 | scoreMessage = "Your score within 80 - 90 range"; 12 | }else if(grade == 'C') { 13 | scoreMessage = "Your score within 70 - 80 range"; 14 | }else if(grade == 'D') { 15 | scoreMessage = "Your score within 60 - 70"; 16 | }else if(grade == 'F') { 17 | scoreMessage = "You score is less than 60"; 18 | }else { 19 | scoreMessage = "NOT VALID GRADE(it can be: A, B, C, D, F)"; 20 | } 21 | 22 | System.out.println("Grade = " + grade); 23 | System.out.println("Score Message = " + scoreMessage); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/day10/SecondPart.java: -------------------------------------------------------------------------------- 1 | package day10; 2 | import java.util.*; 3 | 4 | public class SecondPart { 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | System.out.println("Provide a word with even length:"); 8 | 9 | String word = sc.next(); 10 | 11 | if(word.length() % 2 == 0) { 12 | String secondPart = word.substring(word.length() / 2); 13 | System.out.println(secondPart); 14 | 15 | }else { 16 | System.out.println("Not valid input"); 17 | } 18 | } 19 | 20 | /** 21 | * Ask from user string with even length 22 | * if the word length is not even print 'Not valid input' 23 | * split word in the middle and print second part 24 | * 25 | * 26 | * 0123 -> 23 27 | * qwertyui -> tyui 28 | * 1234567891 -> 67891 29 | */ 30 | } 31 | -------------------------------------------------------------------------------- /src/day4/InstanceVariable.java: -------------------------------------------------------------------------------- 1 | package day4; 2 | 3 | public class InstanceVariable { 4 | private String name = "John"; 5 | private int age = 65; 6 | private String city = "Aldie"; 7 | public String street = "101 Main St"; 8 | 9 | public static void main(String[] args) { 10 | // it will not compile because we cannot use non static member(variables) inside static method 11 | //name = "Smith"; 12 | 13 | // creating an object from InstanceVariable class to use it's instance variables 14 | InstanceVariable obj = new InstanceVariable(); 15 | System.out.println(obj.name); 16 | System.out.println(obj.age); 17 | System.out.println(obj.city); 18 | System.out.println(obj.street); 19 | 20 | obj.name = "Smith"; 21 | } 22 | 23 | public void doSomething(){ 24 | name = "Smith"; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/day12/DayOfWeek.java: -------------------------------------------------------------------------------- 1 | package day12; 2 | 3 | public class DayOfWeek { 4 | public static void main(String[] args) { 5 | /* 6 | * 0 - Sun 1 - Mon 2 - Tue 3 - Wed 4 - Thur 5 - Fri 6 - Sat 7 | */ 8 | 9 | int dayOfWeek = 0; 10 | switch (dayOfWeek) { 11 | case 0: 12 | System.out.println("Sun"); 13 | break; 14 | case 1: 15 | System.out.println("Mon"); 16 | break; 17 | case 2: 18 | System.out.println("Tue"); 19 | break; 20 | case 3: 21 | System.out.println("Wed"); 22 | break; 23 | case 4: 24 | System.out.println("Thur"); 25 | break; 26 | case 5: 27 | System.out.println("Fri"); 28 | break; 29 | case 6: 30 | System.out.println("Sat"); 31 | break; 32 | default: 33 | System.out.println("Invalid day"); 34 | break; 35 | } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/day25/Car.java: -------------------------------------------------------------------------------- 1 | package day25; 2 | 3 | import java.lang.String; 4 | import java.util.ArrayList; 5 | 6 | public class Car { 7 | public static void main(String[] args) { 8 | String str = ""; 9 | 10 | ArrayList cars = new ArrayList<>(); 11 | cars.add("BMW"); 12 | cars.add("Ford"); 13 | cars.add("Volvo"); 14 | System.out.println(cars); 15 | 16 | // Print 3th element 17 | System.out.println(cars.get(2)); 18 | System.out.println(cars.get(1)); 19 | System.out.println(cars.get(0)); 20 | 21 | cars.add("Mazda"); 22 | System.out.println(cars); 23 | 24 | cars.remove(0); // by index 25 | System.out.println(cars); 26 | 27 | cars.remove("Ford"); // by value 28 | System.out.println(cars); 29 | 30 | cars.set(1, "Honda"); 31 | System.out.println(cars); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/day23/LoopsReview.java: -------------------------------------------------------------------------------- 1 | package day23; 2 | 3 | import java.util.Scanner; 4 | 5 | public class LoopsReview { 6 | public static void main(String[] args) throws Exception{ 7 | Scanner sc = new Scanner(System.in); 8 | System.out.println("Provide secret word:"); 9 | String secretWord = sc.next(); 10 | boolean isLimit = false; 11 | 12 | int count = 1; 13 | while(!secretWord.equals("apple")) { 14 | 15 | if(count == 3) { 16 | isLimit = true; 17 | break; 18 | } 19 | 20 | System.out.println("Wrong, try one more time:"); 21 | secretWord = sc.next(); 22 | 23 | count++; 24 | } 25 | 26 | if(isLimit) { 27 | System.out.println("Limit is over"); 28 | }else { 29 | System.out.println("Great! You got it in " + count + "th time"); 30 | } 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/day26/CarDemo.java: -------------------------------------------------------------------------------- 1 | package day26; 2 | 3 | public class CarDemo { 4 | public static void main(String[] args) { 5 | Car obj = new Car(); 6 | // ClassName name = new ClassName(); 7 | System.out.println(obj.model); // null 8 | System.out.println(obj.color); // null 9 | System.out.println(obj.price); // 0.0 10 | 11 | System.out.println("--------"); 12 | 13 | Car obj1 = new Car(); 14 | System.out.println(obj1.model); 15 | System.out.println(obj1.color); 16 | System.out.println(obj1.price); 17 | System.out.println("----------"); 18 | 19 | Car obj2 = new Car(); 20 | obj2.model = "Audi Q7"; 21 | obj2.color = "red"; 22 | obj2.price = 59000.99; 23 | 24 | System.out.println(obj2.model); 25 | System.out.println(obj2.color); 26 | System.out.println(obj2.price); 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/day9/Calculator.java: -------------------------------------------------------------------------------- 1 | package day9; 2 | 3 | public class Calculator { 4 | 5 | public static int sum(int numOne, int numTwo) { 6 | return numOne + numTwo; 7 | } 8 | 9 | public static int multiply(int numOne, int numTwo) { 10 | return numOne * numTwo; 11 | } 12 | 13 | public static int division(int numOne, int numTwo) { 14 | return numOne / numTwo; 15 | } 16 | 17 | public static double sum(double numOne, double numTwo) { 18 | return numOne + numTwo; 19 | } 20 | 21 | public static String concat(String str, String str1) { 22 | return str + str1; 23 | } 24 | 25 | public static String makeStr(String word) { 26 | return "<>" + word + ""; 27 | } 28 | 29 | public static String makeStr(String wordOne, String wordTwo) { 30 | return "<"+wordTwo+">" + wordOne + ""; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/day36/Firefox.java: -------------------------------------------------------------------------------- 1 | package day36; 2 | 3 | public class Firefox implements Browser { 4 | 5 | @Override 6 | public void open() { 7 | System.out.println("Open browser in Firefox"); 8 | } 9 | 10 | @Override 11 | public void goTo(String url) { 12 | System.out.println("Open page: " + url); 13 | } 14 | 15 | @Override 16 | public void click(String on) { 17 | System.out.println("Click on: " + on); 18 | } 19 | 20 | @Override 21 | public void navigateForward() { 22 | System.out.println("Navigate forward"); 23 | } 24 | 25 | @Override 26 | public void navigateBack() { 27 | System.out.println("Navigate back"); 28 | } 29 | 30 | @Override 31 | public void close() { 32 | System.out.println("Close"); 33 | } 34 | 35 | @Override 36 | public String getBrowserName() { 37 | return "Firefox"; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/day32/Report.java: -------------------------------------------------------------------------------- 1 | package day32; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Report { 7 | private Map report = new HashMap<>(); 8 | 9 | public Map getReport() { 10 | return report; 11 | } 12 | 13 | public void addReport(String name, Double score) { 14 | report.put(name, score); 15 | } 16 | 17 | public void veiwReport() { 18 | for(String key : report.keySet()) { 19 | System.out.println("Name: " + key +", Score: " + report.get(key)); 20 | } 21 | } 22 | 23 | public static String reportToString(Map report) { 24 | String res = "-------- Report ---------\n"; 25 | for(String key : report.keySet()) { 26 | res += key +" : "+ report.get(key); 27 | } 28 | res += "\n-----------------"; 29 | 30 | return res; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/day26/ListReview.java: -------------------------------------------------------------------------------- 1 | package day26; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | public class ListReview { 8 | public static void main(String[] args) { 9 | List list = new ArrayList<>(); 10 | list.add("apple"); 11 | list.add("banana"); 12 | list.add("orange"); 13 | list.add("kiwi"); 14 | System.out.println(list); 15 | 16 | // reverse using Collections helper class 17 | Collections.reverse(list); 18 | System.out.println(list); 19 | 20 | // sort using Collections helper class 21 | Collections.sort(list); 22 | System.out.println(list); 23 | 24 | // What's the helper class for array? Arrays -> Arrays.sort() 25 | // What's the helper class for collections framework? Collections -> Collections.sort(list), Collections.reverse(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/day6/MethodExample6.java: -------------------------------------------------------------------------------- 1 | package day6; 2 | 3 | public class MethodExample6 { 4 | public static void main(String[] args) { 5 | int myNumber = 23; 6 | 7 | myNumber = negativeFive(myNumber); 8 | 9 | System.out.println(myNumber); // 18 10 | 11 | 12 | int numberOne = 2; 13 | int numberTwo = 4; 14 | int output = plusMethod(numberOne, numberTwo); 15 | System.out.println(output); 16 | 17 | System.out.println(plusMethod(5,5)); 18 | 19 | printConcat("Java", "Cool"); 20 | } 21 | 22 | public static int negativeFive(int num) { 23 | int number = num - 5; 24 | return number; 25 | } 26 | 27 | public static int plusMethod(int numOne, int numTwo) { 28 | return numOne + numTwo; 29 | } 30 | 31 | public static void printConcat(String wordOne, String wordTwo) { 32 | System.out.println(wordOne + " " + wordTwo); 33 | } 34 | } -------------------------------------------------------------------------------- /src/day11/StrContains.java: -------------------------------------------------------------------------------- 1 | package day11; 2 | 3 | public class StrContains { 4 | public static void main(String[] args) { 5 | // .contains(string) is used to check if strings contains another string 6 | // it will return boolean 7 | 8 | String topic = "Variables, assignment operator, arithmetic operator, input from terminal"; 9 | boolean isThere = topic.contains("input"); 10 | System.out.println(isThere); 11 | 12 | System.out.println(topic.contains("java")); // false 13 | System.out.println(topic.contains("terminal")); // true 14 | 15 | System.out.println(topic.contains("input from terminal")); 16 | System.out.println(topic.contains("Variables, assignment operator, arithmetic operator, input from terminal")); 17 | 18 | String name = "John"; 19 | System.out.println(topic.contains(name)); // false 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/day31_2/Interview1.java: -------------------------------------------------------------------------------- 1 | package day31_2; 2 | 3 | public class Interview1 { 4 | public static void main(String[] args) { 5 | int[] nums = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; 6 | 7 | // 1. print each number from array one by one 8 | // 2. if number is evenly divisible by 5 print "Java" instead of number 9 | // 3. if number is evenly divisible by 3 print "Great" instead of number 10 | // 4. if number is evenly divisible by 3 and by 5 print "Great Java" instead of number 11 | 12 | for(int num : nums) { 13 | if(num % 5 == 0 && num % 3 == 0) { 14 | System.out.println("Great Java"); 15 | } else if(num % 3 == 0) { 16 | System.out.println("Great"); 17 | } else if(num % 5 == 0) { 18 | System.out.println("Java"); 19 | } else { 20 | System.out.println(num); 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/day9/MathClass2.java: -------------------------------------------------------------------------------- 1 | package day9; 2 | 3 | public class MathClass2 { 4 | public static void main(String[] args) { 5 | int res = Calculator.sum(55, 4); 6 | System.out.println(res); 7 | 8 | System.out.println(Calculator.multiply(5, 6)); 9 | System.out.println(Calculator.division(15, 5)); 10 | 11 | System.out.println(Calculator.sum(1.99, 2.88)); 12 | 13 | String str = Calculator.concat("apple", "banana"); 14 | System.out.println(str); // applebanana 15 | 16 | String str1 = Calculator.makeStr("apple"); 17 | System.out.println(str1); // <>hello 18 | 19 | String str2 = Calculator.makeStr("hello", "p"); 20 | System.out.println(str2); //

hello

21 | 22 | System.out.println(Calculator.makeStr("apple","x")); 23 | // apple 24 | 25 | System.out.println(Calculator.makeStr("car","LOL")); 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/day24/Varargs.java: -------------------------------------------------------------------------------- 1 | package day24; 2 | 3 | public class Varargs { 4 | public static void main(String[] args) { 5 | int num = sum(2, 3); 6 | System.out.println("Sum 1: " + num); 7 | 8 | int num1 = sum(7, 8, 3); 9 | System.out.println("Sum 2: " + num1); 10 | 11 | int num2 = sum(9, 8, 9, 5); 12 | 13 | int[] arr = {5, 6, 3, 2, 6, 7, 3}; 14 | int num3 = sum(arr); 15 | } 16 | 17 | public static int sum(int num, int num1) { 18 | return num + num1; 19 | } 20 | 21 | public static int sum(int num, int num1, int num2) { 22 | return num + num1 + num2; 23 | } 24 | 25 | public static int sum(int num, int num1, int num2, int num3) { 26 | return num + num1 + num2 + num3; 27 | } 28 | 29 | public static int sum(int[] numArr) { 30 | int sum = 0; 31 | for(int num : numArr) { 32 | sum += num; 33 | } 34 | return sum; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/day34/Apple.java: -------------------------------------------------------------------------------- 1 | package day34; 2 | 3 | public class Apple { 4 | public String type; 5 | public String color; 6 | 7 | public Apple(String type, String color) { 8 | this.type = type; 9 | this.color = color; 10 | } 11 | 12 | public Apple() { 13 | 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | return "type:" + type + ", color:" + color; 19 | } 20 | 21 | @Override 22 | public int hashCode() { 23 | final int prime = 31; 24 | int result = 1; 25 | result = prime * result + ((color == null) ? 0 : color.hashCode()); 26 | result = prime * result + ((type == null) ? 0 : type.hashCode()); 27 | return result; 28 | } 29 | 30 | @Override 31 | public boolean equals(Object obj) { 32 | Apple objApple = (Apple)obj; 33 | return this.type.equals(objApple.type) && this.color.equals(objApple.color); 34 | } 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/day41/ShoppingBalance.java: -------------------------------------------------------------------------------- 1 | package day41; 2 | 3 | public class ShoppingBalance { 4 | private double balance; 5 | 6 | // With private constructor there is no way to create an object outside of this class 7 | private ShoppingBalance(double balance) { 8 | // super(); 9 | this.balance = balance; 10 | } 11 | 12 | // This is single final object that will be used everywhere 13 | private static final ShoppingBalance instance = new ShoppingBalance(1000.00); 14 | 15 | // This is public method to get single object 16 | public static ShoppingBalance getInstance() { 17 | return instance; 18 | } 19 | 20 | public void buy(String item, double price) { 21 | balance = balance - price; 22 | 23 | System.out.println("Bought: " + item); 24 | System.out.println("Price: " + price); 25 | System.out.println("Remaining balance: " + balance); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/day36/Chrome.java: -------------------------------------------------------------------------------- 1 | package day36; 2 | 3 | public class Chrome implements Browser { 4 | 5 | @Override 6 | public void open() { 7 | System.out.println("Open browser in Chrome"); 8 | //.. 9 | } 10 | 11 | @Override 12 | public void goTo(String url) { 13 | System.out.println("Open page: " + url); 14 | //.. 15 | } 16 | 17 | @Override 18 | public void click(String on) { 19 | System.out.println("Click: " + on); 20 | //.. 21 | } 22 | 23 | @Override 24 | public void navigateForward() { 25 | System.out.println("Navigate forward"); 26 | } 27 | 28 | @Override 29 | public void navigateBack() { 30 | System.out.println("Navigate back"); 31 | } 32 | 33 | @Override 34 | public void close() { 35 | System.out.println("Close"); 36 | } 37 | 38 | @Override 39 | public String getBrowserName() { 40 | return "Chrome"; 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/day3/AnimalsFarm.java: -------------------------------------------------------------------------------- 1 | package day3; 2 | 3 | public class AnimalsFarm { 4 | public static void main(String args[]) { 5 | String cow = "Mumu"; 6 | String cat = "Murka"; 7 | String dog = "Jeko"; 8 | String parrot = "Tut"; 9 | 10 | System.out.println("cow's name is " + cow); 11 | System.out.println("cat's name is " + cat); 12 | System.out.println("dog's name is " + dog); 13 | System.out.println("parrot's name is " + parrot); 14 | 15 | System.out.println("---------------------"); 16 | 17 | cow = "Masha"; 18 | cat = "Ivan"; 19 | dog = "Tarzan"; 20 | parrot = "Kesha"; 21 | 22 | System.out.println("cow's name is " + cow); 23 | System.out.println("cat's name is " + cat); 24 | System.out.println("dog's name is " + dog); 25 | System.out.println("parrot's name is " + parrot); 26 | 27 | cow = "Super cow"; 28 | System.out.println(cow); 29 | 30 | } 31 | } -------------------------------------------------------------------------------- /src/day10/StrReplace.java: -------------------------------------------------------------------------------- 1 | package day10; 2 | 3 | public class StrReplace { 4 | public static void main(String[] args) { 5 | /** 6 | * .replace(oldChar, newChar); It will replace the old char with new char 7 | */ 8 | 9 | String city = "Alma-Ata"; // Alma Ata 10 | System.out.println(city); 11 | city = city.replace("-", " "); 12 | System.out.println(city); 13 | 14 | String str = "Updates=are=available=for=your=software"; 15 | str = str.replace("=", "$"); 16 | System.out.println(str); 17 | 18 | String word = "Hello, World!"; 19 | word = word.replace("Hello", "Aloha"); 20 | System.out.println(word); 21 | 22 | String str2 = "Apple.Banana.Kiwi.Orange"; // "apple, banana, kiwi, orange" 23 | 24 | str2 = str2.toLowerCase(); 25 | str2 = str2.replace(".", ", "); 26 | 27 | System.out.println(str2); // apple, banana, kiwi, orange 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/day20/PassByValue.java: -------------------------------------------------------------------------------- 1 | package day20; 2 | 3 | import java.util.Arrays; 4 | 5 | public class PassByValue { 6 | public static void main(String[] args) { 7 | String[] arrStr = new String[] { "a", "b", "c" }; 8 | 9 | String[] arrStr1 = arrStr; 10 | arrStr1[0] = "e"; 11 | 12 | System.out.println(Arrays.toString(arrStr)); 13 | System.out.println(Arrays.toString(arrStr1)); 14 | 15 | int num = 10; 16 | changeVal(num); 17 | System.out.println(num); 18 | 19 | int[] numArr = { 1, 2, 3 }; 20 | System.out.println("Initial arr: " + Arrays.toString(numArr)); 21 | 22 | changeArrVal(numArr); 23 | System.out.println("After method: " + Arrays.toString(numArr)); 24 | } 25 | 26 | public static void changeArrVal(int[] arr) { 27 | // arr = numArr 28 | arr[0] = 100; 29 | } 30 | 31 | public static void changeVal(int n) { 32 | // n = num; 33 | n = 5; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/day34/Ferrari.java: -------------------------------------------------------------------------------- 1 | package day34; 2 | 3 | public class Ferrari extends Car { 4 | public String model; 5 | 6 | public Ferrari(String model) { 7 | this(); 8 | } 9 | 10 | public Ferrari() { 11 | super("Some model"); 12 | } 13 | 14 | 15 | @Override 16 | public void drive() { 17 | System.out.println("Ferrari("+ model +") is driving"); 18 | } 19 | 20 | public void test() { 21 | System.out.println(model); 22 | System.out.println(super.model); 23 | 24 | drive(); 25 | super.drive(); 26 | 27 | // super.model = "dfsd"; 28 | // super.price = 342.34; 29 | } 30 | 31 | // visibility - access modifiers 32 | // public - visible everywhere 33 | // protected - visible in same package and in child classes 34 | // default - visible only in the same package 35 | // private - visible only inside the class 36 | 37 | // BREAK 10 min. Till 8:15 PM 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/day41/AnimalDemo.java: -------------------------------------------------------------------------------- 1 | package day41; 2 | 3 | import java.util.Arrays; 4 | 5 | public class AnimalDemo { 6 | public static void main(String[] args) { 7 | // Created object from immutable Animal 8 | Animal animal = new Animal("Tiger", 3, Arrays.asList("deer", "goat")); 9 | System.out.println(animal); 10 | 11 | // in order to modify the immutable objects you need to create another object 12 | Animal animal1 = new Animal(animal.getName(), animal.getAge() + 2, animal.getFavoriteFoods()); 13 | System.out.println(animal1); 14 | 15 | System.out.println("-----------"); 16 | 17 | // String is immutable 18 | String str = "hello"; 19 | String str1 = str + ", world!"; 20 | System.out.println(str1); 21 | 22 | // StringBuilder is mutable 23 | StringBuilder sb = new StringBuilder("hello"); 24 | sb.append(", world!"); 25 | System.out.println(sb); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/day34/AppleDemo.java: -------------------------------------------------------------------------------- 1 | package day34; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class AppleDemo { 7 | public static void main(String[] args) { 8 | Apple obj = new Apple(); 9 | obj.type = "Aport"; 10 | obj.color = "red"; 11 | // every class in Java extends Object 12 | 13 | // toString() 14 | System.out.println(obj); 15 | 16 | // getClass(); 17 | System.out.println(obj.getClass()); 18 | 19 | 20 | // equals() 21 | // hashCode() 22 | List list = new ArrayList<>(); 23 | list.add(new Apple("Limon", "green")); 24 | list.add(new Apple("T1", "red")); 25 | 26 | List list2 = new ArrayList<>(); 27 | list2.add(new Apple("Limon", "green")); 28 | list2.add(new Apple("T1", "red")); 29 | 30 | boolean isListsEqual = list.equals(list2); 31 | System.out.println("Are they equal: " + isListsEqual); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/day32/ReportDemo.java: -------------------------------------------------------------------------------- 1 | package day32; 2 | 3 | import java.util.Map; 4 | 5 | public class ReportDemo { 6 | public static void main(String[] args) { 7 | Report javaCourse = new Report(); 8 | javaCourse.addReport("John Doe", 98.9); 9 | javaCourse.addReport("Smith", 72.0); 10 | javaCourse.veiwReport(); 11 | 12 | Map javaRep = javaCourse.getReport(); 13 | 14 | String javaRepStr = Report.reportToString(javaRep); 15 | 16 | System.out.println(javaRepStr); 17 | 18 | // ---- 19 | System.out.println("\n"); 20 | 21 | Report seleniumCourse = new Report(); 22 | seleniumCourse.addReport("Alex", 50.0); 23 | seleniumCourse.addReport("Viktor", 90.0); 24 | seleniumCourse.veiwReport(); 25 | Map selenium = javaCourse.getReport(); 26 | 27 | String seleniumRep = Report.reportToString(selenium); 28 | System.out.println(seleniumRep); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/day37/LocalDateTimePractice.java: -------------------------------------------------------------------------------- 1 | package day37; 2 | 3 | import java.time.LocalDateTime; 4 | import java.time.format.DateTimeFormatter; 5 | import java.time.format.FormatStyle; 6 | 7 | public class LocalDateTimePractice { 8 | public static void main(String[] args) { 9 | // LocalDate 10 | // LocalTime 11 | // LocalDateTime 12 | 13 | // DateTimeFormatter if you want to format something 14 | 15 | LocalDateTime now = LocalDateTime.now().minusWeeks(9).minusHours(3); 16 | System.out.println(now); 17 | 18 | // Print this date time in any other format using DateTimeFormatter class 19 | DateTimeFormatter f = DateTimeFormatter.ofPattern("MM/dd/YYYY HH:mm"); 20 | String fDate = f.format(now); 21 | System.out.println(fDate); 22 | 23 | f = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM); 24 | String fDate1 = f.format(now); 25 | System.out.println(fDate1); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/day8/Account.java: -------------------------------------------------------------------------------- 1 | package day8; 2 | 3 | public class Account { 4 | public static void main(String[] args) { 5 | int savings = 50000; 6 | int salary = 100000; 7 | int expenses = 70000; 8 | 9 | // 50000 , 100000, 70000 10 | myFinance(savings, salary, expenses); 11 | 12 | // Create a method: 13 | // if salary more then expenses or savings more then expenses 14 | // then print "Good! Still Alive!" 15 | // Otherwise print "Bankrupt" 16 | 17 | savings = 90000; 18 | salary = 80000; 19 | expenses = 100000; 20 | // 90000, 80000, 100000 21 | myFinance(savings, salary, expenses); 22 | 23 | } 24 | 25 | public static void myFinance(int savings, int salary, int expenses) { 26 | if(salary > expenses || savings > expenses) { 27 | System.out.println("Good! Still Alive!"); 28 | } else { 29 | System.out.println("Bankrupt"); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/day27/Employee.java: -------------------------------------------------------------------------------- 1 | package day27; 2 | 3 | public class Employee { 4 | private String firstname; 5 | private String lastname; 6 | private int age; 7 | 8 | // public Employee(String fistname, String lastname, int age) { 9 | // this.firstname = fistname; 10 | // } 11 | // 12 | // public Employee() { 13 | // 14 | // } 15 | 16 | public String getFirstname() { 17 | return firstname; 18 | } 19 | 20 | public void setFirstname(String firstname) { 21 | this.firstname = firstname; 22 | } 23 | 24 | public String getLastname() { 25 | return lastname; 26 | } 27 | 28 | public void setLastname(String lastname) { 29 | this.lastname = lastname; 30 | } 31 | 32 | public int getAge() { 33 | return age; 34 | } 35 | 36 | public void setAge(int age) { 37 | if(age < 1) { 38 | System.out.println("Wrong input"); 39 | System.exit(0); 40 | } 41 | 42 | this.age = age; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/day7/LuckyNumbers.java: -------------------------------------------------------------------------------- 1 | package day7; 2 | 3 | public class LuckyNumbers { 4 | public static void main(String[] args) { 5 | 6 | // Get number from a terminal 7 | // Assume that numbers: 7, 13, 99 are lucky numbers 8 | // if users number is lucky number, print "Jackpot!" 9 | // otherwise print "Sorry, Not today. Come tomorrow!"; 10 | 11 | boolean isLucky = isLuckyNumber(Integer.parseInt(args[0])); 12 | if(isLucky) { 13 | System.out.println("Jackpot!"); 14 | }else { 15 | System.out.println("Sorry, Not today. Come tomorrow!"); 16 | } 17 | 18 | } 19 | 20 | public static boolean isLuckyNumber(int number) { 21 | // && if one the conditions is false whole expression will be false 22 | // || if one the condition is true whole exresion will be true 23 | 24 | if(number == 7 || number == 13 || number == 99) { 25 | return true; 26 | } else { 27 | return false; 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /src/day14/Pyramid.java: -------------------------------------------------------------------------------- 1 | package day14; 2 | import java.util.Scanner; 3 | 4 | public class Pyramid { 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | 8 | System.out.println("Enter a number: "); 9 | int number = sc.nextInt(); 10 | 11 | String pyramid = "#"; 12 | for(int i = 0; i < number; i++) { 13 | // ## 14 | System.out.println(pyramid); 15 | // #### ### + # 16 | pyramid = pyramid + "#"; 17 | } 18 | 19 | // String str = "############################"; 20 | // ########## 21 | // ######### 22 | // ####### 23 | // ##### 24 | 25 | /** 26 | * Ask from user number as input 27 | * print pyramid based on this number 28 | * 29 | * 5 30 | * # 31 | * ## 32 | * ### 33 | * #### 34 | * ##### 35 | * 36 | * 3 37 | * # 38 | * ## 39 | * ### 40 | */ 41 | 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/day20/StringAndChars.java: -------------------------------------------------------------------------------- 1 | package day20; 2 | 3 | import java.util.Arrays; 4 | 5 | public class StringAndChars { 6 | public static void main(String[] args) { 7 | String str = "hello"; 8 | 9 | // ['h']['e']['l']['l']['o'] 10 | char[] chArr = new char[5]; 11 | chArr[0] = str.charAt(0); 12 | chArr[1] = str.charAt(1); 13 | chArr[2] = str.charAt(2); 14 | chArr[3] = str.charAt(3); 15 | chArr[4] = str.charAt(4); 16 | System.out.println(Arrays.toString(chArr)); 17 | System.out.println("--------------"); 18 | 19 | char[] chArr1 = new char[str.length()]; 20 | for(int i = 0; i < chArr1.length; i++) { 21 | chArr1[i] = str.charAt(i); 22 | } 23 | System.out.println(Arrays.toString(chArr1)); 24 | System.out.println("--------------"); 25 | 26 | String strTwo = "John Doe"; 27 | char[] chArr2 = strTwo.toCharArray(); 28 | System.out.println(Arrays.toString(chArr2)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/day11/StrEqual.java: -------------------------------------------------------------------------------- 1 | package day11; 2 | 3 | public class StrEqual { 4 | public static void main(String[] args) { 5 | // To compare two Strings we use .equals(String) method 6 | // it will return true if they are equal 7 | // Never use == operator to compare strings 8 | 9 | String box = "apple"; 10 | String box1 = "apple"; 11 | 12 | if(box.equals(box1)) { 13 | System.out.println("They are equal"); 14 | } else { 15 | System.out.println(box + " is not equal to " + box1); 16 | } 17 | 18 | System.out.println(box.equals(box1)); 19 | System.out.println(box == box1); // Never use it to compare Strigns 20 | 21 | String name = "John"; 22 | String name1 = new String("John"); 23 | 24 | System.out.println(name); 25 | System.out.println(name1); 26 | 27 | System.out.println(name.equals(name1)); // true 28 | System.out.println(name == name1); // false 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/day13/BreakAString1.java: -------------------------------------------------------------------------------- 1 | package day13; 2 | import java.util.Scanner; 3 | 4 | public class BreakAString1 { 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | 8 | System.out.println("Provide a word: "); 9 | String str = sc.next(); 10 | 11 | // TODO 12 | // Write a program that will print every other letter from str variable in the same line. 13 | // str = "apple" -> ape 14 | // str = "banana" -> bnn 15 | // str = "123456789" -> 13579 16 | // HINT: index += 2 (index = index + 2) 17 | 18 | int index = 0; 19 | // 5 20 | int len = str.length(); 21 | // 6 < 5 22 | while(index < len) { 23 | // 01234 24 | // apple 25 | // 4 26 | System.out.print(str.charAt(index)); 27 | //6 28 | index = index + 2; 29 | } 30 | 31 | System.out.println(); 32 | System.out.println(index); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/day37/DatePractice.java: -------------------------------------------------------------------------------- 1 | package day37; 2 | 3 | import java.time.LocalDate; 4 | import java.time.Month; 5 | 6 | public class DatePractice { 7 | public static void main(String[] args) { 8 | // current date 9 | LocalDate today = LocalDate.now(); 10 | System.out.println("Current date: " + today); 11 | 12 | LocalDate birthDay = LocalDate.of(1990, Month.MARCH, 05); 13 | System.out.println("Birthday: " + birthDay); 14 | 15 | System.out.println("Day of week: " + birthDay.getDayOfWeek()); 16 | System.out.println("Was it Leap yeat: " + birthDay.isLeapYear()); 17 | System.out.println("ERA: " + birthDay.getEra()); 18 | 19 | birthDay = birthDay.plusMonths(6); 20 | System.out.println("Birthday after 6 months: " + birthDay); 21 | 22 | birthDay = birthDay.plusYears(5); 23 | System.out.println("After 5 years: " + birthDay); 24 | 25 | System.out.println(today.isAfter(birthDay)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/day41/ShoppingBalanceLazy.java: -------------------------------------------------------------------------------- 1 | package day41; 2 | 3 | public class ShoppingBalanceLazy { 4 | private double balance; 5 | 6 | private static ShoppingBalanceLazy instance; 7 | 8 | private ShoppingBalanceLazy(double balance) { 9 | this.balance = balance; 10 | } 11 | 12 | public static ShoppingBalanceLazy getInstance() { 13 | if(instance == null) { 14 | System.out.println("Setting up initial balance"); 15 | instance = new ShoppingBalanceLazy(1000.00); 16 | return instance; 17 | }else { 18 | System.out.println("Balance is exist, returnning old one"); 19 | return instance; 20 | } 21 | } 22 | 23 | public void buy(String item, double price) { 24 | balance = balance - price; 25 | 26 | System.out.println("Bought: " + item); 27 | System.out.println("Price: " + price); 28 | System.out.println("Remaining balance: " + balance); 29 | System.out.println("-----------"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/day11/CharCompare.java: -------------------------------------------------------------------------------- 1 | package day11; 2 | 3 | import java.util.Scanner; 4 | 5 | public class CharCompare { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | System.out.println("Provide word with length 3:"); 9 | String word = scanner.next(); 10 | String originalWord = word; 11 | 12 | word = word.toLowerCase(); 13 | 14 | // I want to make sure if above variable in alphabetical order 15 | 16 | if (word.length() == 3) { 17 | 18 | char l1 = word.charAt(0); 19 | char l2 = word.charAt(1); 20 | char l3 = word.charAt(2); 21 | 22 | if (l3 >= l2 && l2 >= l1) { 23 | System.out.println("Yes, " + originalWord + " is in alphabetical order"); 24 | } else { 25 | System.out.println("No, " + originalWord + " is not in alphabertical order"); 26 | } 27 | 28 | } else { 29 | System.out.println("Not valid input"); 30 | } 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/day20/FixedSize.java: -------------------------------------------------------------------------------- 1 | package day20; 2 | 3 | import java.util.Arrays; 4 | 5 | public class FixedSize { 6 | public static void main(String[] args) { 7 | // Array is collection of variables of same type 8 | // Array is fixed size (immutable) 9 | 10 | // [Ljava.lang.String;@7852e922 11 | String[] car = new String[4]; 12 | car[0] = "BMW"; 13 | car[1] = "Audi"; 14 | car[2] = "Mercedes"; 15 | car[3] = "Toyota"; 16 | 17 | // car[4] = "Honda"; Array Index out of bound exception 18 | System.out.println(Arrays.toString(car)); 19 | 20 | // [BMW, Audi, Mercedes, Toyota] 21 | // [BMW, Audi, Mercedes, Toyota, Honda] 22 | 23 | 24 | 25 | String[] carCopy = new String[5]; 26 | carCopy[0] = car[0]; 27 | carCopy[1] = car[1]; 28 | carCopy[2] = car[2]; 29 | carCopy[3] = car[3]; 30 | carCopy[4] = "Honda"; 31 | 32 | car = carCopy; 33 | System.out.println(Arrays.toString(car)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/day27/Cat.java: -------------------------------------------------------------------------------- 1 | package day27; 2 | 3 | public class Cat { 4 | private String name; 5 | private int age; 6 | private String secondName; 7 | 8 | public Cat(String name, int age) { 9 | this.name = name; 10 | this.age = age; 11 | // System.out.println("Constructor with argruments"); 12 | } 13 | 14 | public Cat() { 15 | // System.out.println("Empty constructor"); 16 | } 17 | 18 | public String getSecondName() { 19 | return secondName; 20 | } 21 | 22 | public void setSecondName(String secondName) { 23 | this.secondName = secondName; 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public int getAge() { 35 | return age; 36 | } 37 | 38 | public void setAge(int age) { 39 | this.age = age; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/day30/JavaStack.java: -------------------------------------------------------------------------------- 1 | package day30; 2 | 3 | import java.util.Stack; 4 | 5 | public class JavaStack { 6 | // Deque can behave as FIFO and LIFO 7 | 8 | // Stack - LIFO data structure 9 | 10 | public static void main(String[] args) { 11 | Stack messages = new Stack(); 12 | // push() will add element on 'top' of the Stack 13 | messages.push("Message from: John"); 14 | messages.push("Message from: Alex"); 15 | messages.push("Message from: Smith"); 16 | 17 | // pop() will get element from the top(last added) of the Stack 18 | // it will remove this element 19 | String message = messages.pop(); 20 | System.out.println(message); 21 | System.out.println(messages); 22 | 23 | message = messages.pop(); 24 | System.out.println(message); 25 | System.out.println(messages); 26 | 27 | message = messages.pop(); 28 | System.out.println(message); 29 | System.out.println(messages); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/day29/City.java: -------------------------------------------------------------------------------- 1 | package day29; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class City { 7 | public static void main(String[] args) { 8 | Map cities = new HashMap<>(); 9 | cities.put("Arlington", 229164); 10 | cities.put("Leesburg", 375629); 11 | cities.put("Manassas", 451721); 12 | cities.put("Richmond", 210309); 13 | cities.put("Alexandria", 147391); 14 | cities.put("Norfolk", 245782); 15 | 16 | // TODO Get total population from map cities 17 | // 1. Create a variable for total population 18 | // 2. Loop over the map using keySet() 19 | // 3. Keep adding the population from each city to created variable 20 | // 4. Print the variable 21 | 22 | int totalPopulation = 0; 23 | for(String key : cities.keySet()) { 24 | totalPopulation += cities.get(key); 25 | } 26 | 27 | System.out.println("Total population is " + totalPopulation); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/day35/Box.java: -------------------------------------------------------------------------------- 1 | package day35; 2 | 3 | public interface Box { 4 | // every non local variable in interface is 5 | // public static final 6 | public static final String boxName = "BOX"; 7 | int numberOfBoxes = 100; 8 | public static final String country = "USA"; 9 | 10 | // methods can be only public abstract except: 11 | // 1. default method 12 | // 2. static method 13 | void putInside(String item); 14 | 15 | public abstract String getItem(int index); 16 | 17 | public abstract int getFreeSpace(); 18 | 19 | public abstract int getNumberOfItems(); 20 | 21 | 22 | // Interface cannot have non abstract methods with body 23 | // public void remove() { 24 | // // some code.. 25 | // } 26 | // Except: 27 | // 1. default method 28 | public default void remove() { 29 | System.out.println("Remove"); 30 | } 31 | 32 | //2. static method 33 | public static void look() { 34 | System.out.println("Look"); 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /src/day18/CountHi.java: -------------------------------------------------------------------------------- 1 | package day18; 2 | 3 | public class CountHi { 4 | public static void main(String[] args) { 5 | int res = countHi("ABChi hi"); 6 | System.out.println(res); 7 | } 8 | 9 | 10 | // countHi("ABChi hi") -> 2 11 | public static int countHi(String str) { 12 | // create int variable to store return result 13 | // loop to throw the string 14 | // get two letters each iteration if its "hi" increase int res var by 1 15 | 16 | int res = 0; 17 | 18 | for(int i = 0; i < str.length() - 1; i++) { 19 | String subStr = str.substring(i, i + 2); 20 | if(subStr.equals("hi")) { 21 | res++; 22 | } 23 | 24 | // String subStr = String.valueOf(str.charAt(i)) + str.charAt(i + 1); 25 | // if(str.charAt(i) == 'h' && str.charAt(i + 1) == 'i') { 26 | // res++; 27 | // } 28 | } 29 | 30 | return res; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/day22/Teams.java: -------------------------------------------------------------------------------- 1 | package day22; 2 | 3 | public class Teams { 4 | public static void main(String[] args) { 5 | // 0 1 6 | String[][] teams = {{"Yulduz", "Mark", "Akylbek", "Daniel"}, {"Ariunna", "Frank", "Nurgazy", "Anna"}, {"Selvin", "Meerim"}, {}}; 7 | // 0 1 2 3 0 1 2 3 8 | String name = teams[1][1].toUpperCase(); 9 | System.out.println(name); 10 | 11 | System.out.println(teams[2][1]); 12 | 13 | System.out.println(teams[0][0]); 14 | System.out.println(teams[0][3]); 15 | 16 | System.out.println(teams[2].length); 17 | 18 | System.out.println("----------------"); 19 | 20 | for(int i = 0; i < teams.length; i++) { 21 | for(int j = 0; j < teams[i].length; j++) { 22 | System.out.println(teams[i][j]); 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/day31_2/ArrayListInterview.java: -------------------------------------------------------------------------------- 1 | package day31_2; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class ArrayListInterview { 7 | public static void main(String[] args) { 8 | List list = new ArrayList<>(); 9 | list.add(1); 10 | list.add(2); 11 | list.add(3); 12 | list.add(4); 13 | list.add(5); 14 | list.add(6); 15 | 16 | List evenList = new ArrayList<>(); 17 | List oddList = new ArrayList<>(); 18 | 19 | // TODO 20 | // Loop over the list 21 | // Use % to find if element is even or odd 22 | // if element is even add to evenList otherwise add to oddList 23 | 24 | for(int i = 0; i < list.size(); i++) { 25 | if(list.get(i) % 2 == 0) { 26 | evenList.add(list.get(i)); 27 | }else { 28 | oddList.add(list.get(i)); 29 | } 30 | } 31 | 32 | System.out.println(evenList); // [2, 4, 6] 33 | System.out.println(oddList); // [1, 3, 5] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/day40/ReadingInputStream.java: -------------------------------------------------------------------------------- 1 | package day40; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | 8 | public class ReadingInputStream { 9 | public static void main(String[] args) { 10 | File file = new File("C:/Users/Beknazar/Desktop/notes.txt"); 11 | 12 | InputStream in = null; 13 | 14 | try { 15 | in = new FileInputStream(file); 16 | 17 | int b; 18 | while((b = in.read()) != -1) { 19 | System.out.print((char)b); 20 | //b = in.read(); 21 | } 22 | 23 | // in.close(); 24 | 25 | }catch(IOException e) { 26 | System.out.println(e.getMessage()); 27 | } finally { 28 | try { 29 | System.out.println("Closing stream.."); 30 | if(in != null) { 31 | in.close(); 32 | } 33 | }catch(IOException e1) { 34 | System.out.println("Error while closing stream"); 35 | } 36 | } 37 | } 38 | } 39 | --------------------------------------------------------------------------------