├── 2022Opel1.pdf ├── A.java ├── A1.java ├── A2.java ├── A3.java ├── A4.java ├── ArrayExercises.java ├── B.java ├── B1.java ├── B3.java ├── B4.java ├── BinarySearchTree.java ├── C.java ├── C1.java ├── Car.java ├── CarDriver.java ├── ChocolateClassJavaA ├── Chocolate.java ├── ChocolateDriver.java └── מחלקה שוקלד גאווה א .pdf ├── ClassA.java ├── ClassB.java ├── Company.java ├── CompanyDriver.java ├── CompanyJavaB.java ├── D.java ├── D1.java ├── Date.java ├── DateDriver.java ├── DynamicArray.java ├── E.java ├── Entry.java ├── Exam2010JavaA-82 ├── A.java ├── Account.java ├── B.java ├── Bank.java ├── Customer.java ├── Exam2010JavaA82.java └── test2010JavaAMoad82.pdf ├── Exam2011JavaA ├── Clsrm.java ├── College.java ├── Course.java ├── Exam2011JavaA87.java └── testJava2011A.pdf ├── Exam2014JavaA ├── Date.java ├── Exam.java ├── Exam2014JavaA.java ├── ExamJavaA2014.pdf └── ExamsCenter.java ├── Exam2017MoadBJavaA ├── Exam2017JavaAMoadB.java ├── RGBColor.java ├── RGBImage.java └── testJavaAMoadBYear2017.pdf ├── Exam2018JavaA ├── Exam2018AJavaA.java ├── Exam2018JavaA83.pdf ├── Point.java └── Rectangle.java ├── Exam2018JavaAMoad82 ├── Clock.java ├── Exam2018Moad82.java └── testJavaA2018Bmoad82.pdf ├── Exam2019JavaA83 ├── Bus.java ├── Exam2019JavaA83.java ├── Exam2019JavaA83.pdf └── Wheel.java ├── Exam2021JavaA ├── Airport.java ├── ExamJavaA2021.java ├── Flight.java ├── Time.java └── javaA2021.pdf ├── Exam2022BJuly91 ├── A.java ├── B.java ├── D.java ├── Exam2022BJuly91.java ├── Exam2022BJuly91Driver.java ├── ExamJava2022BJuly91.pdf ├── IntList.java ├── IntNode.java └── Node.java ├── Exam2022Bjune86 ├── A.java ├── B.java ├── C.java ├── Exam2022Bjune86.java ├── Exam2022Bjune86Driver.java ├── ExamJava2022BJune86.pdf ├── IntLIst.java ├── IntNode.java └── Node.java ├── Exam2022aFebruary89.java ├── ExamComputerScienceInJavaSemesterAYear2016 ├── Card.java ├── Deck.java └── Exam2016SemsterA.java ├── ExamJavaAYear2017SemseterA ├── Date.java ├── Exam2017JavaA.java ├── Exam2017JavaAMoadA.pdf ├── MailBox.java └── Message.java ├── ExamJavaFebruary2022Date87 ├── Exam2022aFebruary87.java └── exam2022.pdf ├── ExamYear2022Semseter1EfekaCollege ├── Artist.java ├── Exam2022SemesterA.java ├── Song.java └── SongsRepository.java ├── HashTableArray.java ├── Loops.java ├── MagicSquare.java ├── MagicSquareDriver.java ├── Node.java ├── PriorityQueue.java ├── Queue.java ├── README.md ├── RecursionExercises.java ├── Rent.java ├── RentDriver.java ├── RentNode.java ├── Runner.java ├── Solution.txt ├── Train.java ├── Triangle.java ├── Triangle1.java ├── Triangle2.java ├── Unit2JavaAExercises.java ├── arrayExerciseAfeka.pdf ├── exam.xlsx ├── exam2022aFebruaryDate89.pdf ├── loopsExercises.pdf ├── mmn13JavaAYear2009 ├── Date.html ├── Date.java ├── Passport.html ├── Passport.java ├── Traveler.html ├── Traveler.java ├── maman12.pdf └── mmn13JavaAYear2009Driver.java └── recursionAfekCollegeExercises.pdf /2022Opel1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lironmiz/Computer-Science-in-Java/71abf905b948e24c02e2d3fc303e285e70a45dfa/2022Opel1.pdf -------------------------------------------------------------------------------- /A.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // A.java 3 | // the class reprsents A 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class A 7 | { 8 | public void method1(float x){ … } 9 | }// end of method A 10 | -------------------------------------------------------------------------------- /A1.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // A1.java 3 | // the class reprsents A1 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class A 7 | { 8 | public void a1() 9 | { 10 | System.out.println("A"); 11 | }// end of method a1 12 | 13 | public void a2() 14 | { 15 | a1(); 16 | }// end of method a2 17 | }// end of class A 18 | -------------------------------------------------------------------------------- /A2.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // A.java 3 | // the class reprsents A 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class A 7 | { 8 | public void doSomething(int x) 9 | { 10 | System.out.println("1"); 11 | }// end of method doSomething 12 | 13 | public void doSomethingElse(int x, int y) 14 | { 15 | System.out.println("2"); 16 | }// end of method doSomethingElse 17 | 18 | public int calc (int x) 19 | { 20 | System.out.println("3"); 21 | return x + 1; 22 | }// end of method calc 23 | 24 | }// end of class A 25 | -------------------------------------------------------------------------------- /A3.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // A.java 3 | // the class reprsents A 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public abstract class A 7 | { 8 | public abstract boolean f(int x); 9 | }// end of abstract class A 10 | -------------------------------------------------------------------------------- /A4.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // A.java 3 | // the class reprsents A 4 | // Author: liron mizrahi 5 | //****************************************************** 6 | public class A 7 | { 8 | private int _x; 9 | public A(int x) 10 | { 11 | _x = x; 12 | }// end of method A 13 | 14 | public int getX() 15 | { 16 | return _x; 17 | }// end of method getX 18 | 19 | public int doubleX() 20 | { 21 | return 2 * getX(); 22 | }// end of method doubleX 23 | 24 | public int tripleX() 25 | { 26 | return 3 * _x; 27 | }// end of method tripleX 28 | 29 | public int subXhelper() 30 | { 31 | return _x -1; 32 | }// end of method subXhelper 33 | 34 | public int subX() 35 | { 36 | return subXhelper(); 37 | }// end of method subX 38 | }// end of class A 39 | -------------------------------------------------------------------------------- /B.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // B.java 3 | // the class reprsents B 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class B extends A 7 | { 8 | @Override 9 | public void a1() 10 | { 11 | System.out.println("B"); 12 | }// end of method a1 13 | }// end of class B 14 | -------------------------------------------------------------------------------- /B1.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // B.java 3 | // the class reprsents B 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class B extends A 7 | { 8 | public void doSomethingElse(int x) 9 | { 10 | System.out.println("4"); 11 | }// end of method doSomethingElse 12 | }// end of class B 13 | -------------------------------------------------------------------------------- /B3.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // B.java 3 | // the class reprsents B 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public abstract class B extends A 7 | { 8 | public boolean f(int x) 9 | { 10 | return x == 2; 11 | } 12 | }// end of abstract class B 13 | -------------------------------------------------------------------------------- /B4.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // B.java 3 | // the class reprsents B 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class B extends A 7 | { 8 | private int _x; 9 | 10 | public B(int xA, int xB) 11 | { 12 | super(xA); 13 | _x = xB; 14 | }// end of method B 15 | 16 | public int getX() 17 | { 18 | return _x; 19 | }// end of method getX 20 | 21 | public int superX() 22 | { 23 | return super.getX(); 24 | }// end of method superX 25 | 26 | public int tenTimesX() 27 | { 28 | return 10 * _x; 29 | }// end of method tenTimesX 30 | 31 | public int subXhelper() 32 | { 33 | return _x * 2; 34 | }// end of method subXhelper 35 | }// end of class B 36 | -------------------------------------------------------------------------------- /C.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // C.java 3 | // the class reprsents C 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class C 7 | { 8 | public void foo(D d) 9 | { 10 | System.out.println("cd"); 11 | } 12 | }// end of class C 13 | -------------------------------------------------------------------------------- /C1.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // C1.java 3 | // the class reprsents C1 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class C extends A 7 | { 8 | public void doSomething(int x) 9 | { 10 | System.out.println("5"); 11 | }// end of method doSomething 12 | }// end of class C 13 | -------------------------------------------------------------------------------- /Car.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // Class Car.java 3 | // The class represent car 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class Car 7 | { 8 | private int _id; 9 | private char _type; 10 | private String _brand; 11 | private boolean _isManual; 12 | 13 | // Constant in the class 14 | private static final int DEFAULT_ID = 9999999; 15 | private static final int ID_VALID_LENGTH = 7; 16 | /** 17 | * Constructor for class Car 18 | * @param id of the car, type of the car, brand of the car, and isManual 19 | * @return None 20 | */ 21 | public Car(int id, char type, String brand, boolean isManual) 22 | { 23 | // Checking if id is valid 24 | int lengthOfId = String.valueOf(id).length(); 25 | if(lengthOfId == ID_VALID_LENGTH && id > 0) 26 | { 27 | this._id = id; 28 | } 29 | else 30 | { 31 | this._id = DEFAULT_ID; 32 | } 33 | // Checking if type is valid 34 | if(type == 'A' || type == 'B' || type == 'C' || type == 'D') 35 | { 36 | this._type = type; 37 | } 38 | else 39 | { 40 | this._type = 'A'; 41 | } 42 | _brand = brand; 43 | _isManual = isManual; 44 | }// end of Car method 45 | 46 | /** 47 | * Constructor for class Car 48 | * @param id of the car, type of the car, brand of the car, and isManual 49 | * @return None 50 | */ 51 | public Car(Car other) 52 | { 53 | this._id = other._id; 54 | this._type = other._type; 55 | this._brand = other._brand; 56 | this._isManual = other._isManual; 57 | }// end of Car method 58 | /** 59 | * Method return the id of the car 60 | * @param None 61 | * @return the id of the car 62 | */ 63 | public int getId() 64 | { 65 | return this._id; 66 | }// end of getId method 67 | /** 68 | * Method return the type of the car 69 | * @param None 70 | * @return the type of the car 71 | */ 72 | public char getType() 73 | { 74 | return this._type; 75 | }// end of getType method 76 | /** 77 | * Method return the brand of the car 78 | * @param None 79 | * @return the brand of the car 80 | */ 81 | public String getBrand() 82 | { 83 | return this._brand; 84 | }// end of getBrand method 85 | /** 86 | * Method return if the car is manual 87 | * @param None 88 | * @return if the car is manual 89 | */ 90 | public boolean isManual() 91 | { 92 | return this._isManual; 93 | }// end of isManual method 94 | /** 95 | * Method set the car id 96 | * @param id of the car 97 | * @return None 98 | */ 99 | public void setId(int id) 100 | { 101 | int lengthOfId = String.valueOf(id).length(); 102 | if(lengthOfId == ID_VALID_LENGTH && id > 0) 103 | { 104 | this._id = id; 105 | } 106 | }// end of setId method 107 | /** 108 | * Method set the car type 109 | * @param type of the car 110 | * @return None 111 | */ 112 | public void setType(char type) 113 | { 114 | // Checking if type is valid 115 | if(type == 'A' || type == 'B' || type == 'C' || type == 'D') 116 | { 117 | this._type = type; 118 | } 119 | }// end of setType method 120 | /** 121 | * Method set the car brand 122 | * @param brand of the car 123 | * @return None 124 | */ 125 | public void setBrand(String brand) 126 | { 127 | this._brand = brand; 128 | }// end of setBrand method 129 | /** 130 | * Method set if the car is manual 131 | * @param manual 132 | * @return None 133 | */ 134 | public void setIsManual(boolean manual) 135 | { 136 | this._isManual = manual; 137 | }// end of setIsManual method 138 | /** 139 | * Method returns the car data as a string 140 | * @param None 141 | * @return string 142 | */ 143 | public String toString() 144 | { 145 | if (this._isManual) 146 | { 147 | return "id:" + this._id + " type:" + this._type + " brand:" + this._brand + " gear:manual"; 148 | } 149 | return "id:" + this._id + " type:" + this._type + " brand:" + this._brand + " gear:auto"; 150 | }// end of toString method 151 | /** 152 | * Check if two cars are the same 153 | * Cars are considered the same if they have the same type, brand and gear 154 | * @param other the car to compare this car to 155 | * @return true if the cars are the same, otherwise false 156 | */ 157 | public boolean equals (Car other) 158 | { 159 | return this._type == other._type && this._brand.equals(other._brand) && this._isManual == other._isManual; 160 | }// end of equals method 161 | /** 162 | * Check if this car is better than the other car 163 | * A car is considered better than another car if its type is higher. 164 | * If both cars have same type, an automated car is better than a manual car. 165 | * @param other the car to compare this car to 166 | * @return true if the car is better than the other car, otherwise false 167 | */ 168 | public boolean better (Car other) 169 | { 170 | if (this._type > other._type) 171 | { 172 | return true; 173 | } 174 | else if ( this._type == other._type) 175 | { 176 | if (this._isManual == false && other.isManual () == true) 177 | { 178 | return true; 179 | } 180 | } 181 | return false; 182 | }// end of better method 183 | /** 184 | * Check if this car is worse than the other car 185 | * @param other the car to compare this car to 186 | * @return true if the car is worse than the other car, otherwise false 187 | */ 188 | public boolean worse (Car other) 189 | { 190 | return (other.better(this)); 191 | }// end of worse method 192 | }// end of class Car 193 | -------------------------------------------------------------------------------- /CarDriver.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // CarDriver.java 3 | // A main class for check the Car class 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | import java.util.Scanner; 7 | 8 | public class TestCarClass 9 | { 10 | public static void main(String[] args) 11 | { 12 | // making scanner object 13 | Scanner scanner = new Scanner(System.in); 14 | // take input 15 | System.out.println("Please enter Car information: \n ID:(have to be seven digits) \n Type: (A,B,C,D) \n Brand:(car brand) \n Is Manual:(true or false)"); 16 | int id = scanner.nextInt(); 17 | char type = scanner.next().charAt(0); 18 | System.out.println("now string"); 19 | String brand = scanner.next(); 20 | boolean isManual = scanner.nextBoolean(); 21 | Car car1 = new Car(id, type, brand, isManual); 22 | // print to user to add car 23 | System.out.println("Please enter another Car"); 24 | System.out.println("Please enter Car information:\nID:(must be seven digits)\nType:(A,B,C,D)\nBrand:(car brand)\nIs Manual:(true or false)"); 25 | // take input for second car 26 | id = scanner.nextInt(); 27 | type = scanner.next().charAt(0); 28 | brand = scanner.next(); 29 | isManual = scanner.nextBoolean(); 30 | Car car2 = new Car(id, type, brand, isManual); 31 | // print the cars data 32 | System.out.println("car1 = " + car1.toString()); 33 | System.out.println("car2 = " + car2.toString()); 34 | // checking if car1 and car2 is equals 35 | if (car1.equals(car2)) 36 | { 37 | System.out.println("Same car"); 38 | } 39 | else 40 | { 41 | System.out.println("Different car"); 42 | } 43 | // checking if car1 better than car 2 or not 44 | if (car1.better(car2)) 45 | { 46 | System.out.println("Better car:\n" + car1); 47 | } else if (car2.better(car1)) 48 | { 49 | System.out.println("Better car:\n" + car2); 50 | } 51 | // close the scanner object 52 | scanner.close(); 53 | }// end of method main 54 | }// end of class Runner 55 | -------------------------------------------------------------------------------- /ChocolateClassJavaA/Chocolate.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // Chocolate.java 3 | // the class reprsents a a chocolate 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class Chocolate 7 | { 8 | private String _manufacturer; 9 | private int _cubes; 10 | private int _calories; 11 | private double _price; 12 | /** 13 | * constractor of the class Chocolate 14 | * @param: String newManufacturer,int newCubes,int newCalories,double newPrice 15 | * @return: None 16 | */ 17 | public Chocolate(String newManufacturer,int newCubes,int newCalories,double newPrice) 18 | { 19 | _manufacturer = newManufacturer; 20 | _cubes = newCubes; 21 | _calories = newCalories; 22 | _price = newPrice; 23 | }// end of method Chocolate 24 | /** 25 | * copy constractor of the class Chocolate 26 | * @param: Chocolate other 27 | * @return: None 28 | */ 29 | public Chocolate(Chocolate other) 30 | { 31 | _manufacturer = other._manufacturer; 32 | _cubes = other._cubes; 33 | _calories = other._calories; 34 | _price = other._price; 35 | }// end of method Chocolate 36 | /** 37 | * method return the manufacturer 38 | * @param: None 39 | * @return: String 40 | */ 41 | public String getManufacturer() 42 | { 43 | return _manufacturer; 44 | }// end of method getManufacturer 45 | /** 46 | * method the set the manufacturer 47 | * @param: String manufacturerToSet 48 | * @return: None 49 | */ 50 | public void setManufacturer(String manufacturerToSet) 51 | { 52 | _manufacturer = manufacturerToSet; 53 | }// end of method setManufacturer 54 | /** 55 | * method return the num of cubes 56 | * @param: None 57 | * @return: int 58 | */ 59 | public int getCubes() 60 | { 61 | return _cubes; 62 | }// end of method getCubes 63 | /** 64 | * method set the number of cubes 65 | * @param: int cubesToSet 66 | * @return: None 67 | */ 68 | public void setCubes(int cubesToSet) 69 | { 70 | _cubes = cubesToSet ; 71 | }// end of method setCubes 72 | /** 73 | * method return the num of calories 74 | * @param: None 75 | * @return: int 76 | */ 77 | public int getCalories() 78 | { 79 | return _calories; 80 | }// end of method getCalories 81 | /** 82 | * method set the number of calories 83 | * @param: int caloriesToSet 84 | * @return: None 85 | */ 86 | public void setCalories(int caloriesToSet) 87 | { 88 | _calories = caloriesToSet; 89 | }// end of method setCalories 90 | /** 91 | * method return the price of the chocolate 92 | * @param: None 93 | * @return: int 94 | */ 95 | public double getPrice() 96 | { 97 | return _price; 98 | }// end of method getPrice 99 | /** 100 | * method set the price of the chocolate 101 | * @param: double priceToSet 102 | * @return: None 103 | */ 104 | public void setPrice(double priceToSet) 105 | { 106 | _price = priceToSet; 107 | }// end of method setPrice 108 | /** 109 | * Method return String that represents Chocolate 110 | * @param None 111 | * @return String 112 | */ 113 | public String toString() 114 | { 115 | return "Chocolate [manufacturer=" + _manufacturer + ", cubes=" + _cubes + ", calories=" + _calories + ", price="+ _price + "]"; 116 | }// end of method toString 117 | }// end of class Chocolate -------------------------------------------------------------------------------- /ChocolateClassJavaA/ChocolateDriver.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // ChocolateDriver.java 3 | // the class reprsents a tester for the Chocolate class 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class ChocolateDriver 7 | { 8 | public static void main(String[] args) 9 | { 10 | // 1 11 | Chocolate choco1 = new Chocolate("wowChocolate", 5, 120, 10); 12 | Chocolate choco2 = new Chocolate("ourChocolate", 6, 160, 15); 13 | Chocolate choco3 = new Chocolate("iWantChocolate", 4, 20, 30); 14 | // 2 15 | System.out.print(choco1.toString() + " choco2: " + choco2.toString() + " choco3: " + choco3.toString()); 16 | // 3 17 | double newPrice1 = choco1.getPrice() * 1.1; 18 | choco1.setPrice(newPrice1); 19 | double newPrice2 = choco2.getPrice() * 1.1; 20 | choco2.setPrice(newPrice2); 21 | double newPrice3 = choco3.getPrice() * 1.1; 22 | choco3.setPrice(newPrice3); 23 | // 4 24 | choco3.setCubes(choco3.getCubes() + 20); 25 | // 5 26 | System.out.println(choco2.getManufacturer()); 27 | // 6 28 | System.out.print(choco3.toString() + " choco2: " + choco2.toString() + " choco1: " + choco1.toString()); 29 | // 7 30 | System.out.print(choco3.toString()); 31 | // 8 32 | Chocolate choco4 = new Chocolate(choco1); 33 | } 34 | }// end of class ChocolateDriver 35 | -------------------------------------------------------------------------------- /ChocolateClassJavaA/מחלקה שוקלד גאווה א .pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lironmiz/Computer-Science-in-Java/71abf905b948e24c02e2d3fc303e285e70a45dfa/ChocolateClassJavaA/מחלקה שוקלד גאווה א .pdf -------------------------------------------------------------------------------- /ClassA.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // ClassA.java 3 | // the class reprsents ClassA 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class ClassA 7 | { 8 | public ClassA() 9 | { 10 | f(); 11 | }// end of method ClassA 12 | 13 | public void f() 14 | { 15 | System.out.println("Class a"); 16 | }// end of method f 17 | 18 | public static void main(String[] args) 19 | { 20 | new ClassB(); 21 | }// end of method main 22 | }// end of class ClassA 23 | -------------------------------------------------------------------------------- /ClassB.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // ClassB.java 3 | // the class reprsents ClassB 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class ClassB extends ClassA 7 | { 8 | public ClassB() {} 9 | 10 | public void f() 11 | { 12 | System.out.println("b"); 13 | } 14 | }// end of class ClassB 15 | -------------------------------------------------------------------------------- /D.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // D.java 3 | // the class reprsents D 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class D extends C 7 | { 8 | public void foo(C c) 9 | { 10 | System.out.println("dc"); 11 | }// end of methdo foo 12 | 13 | public void foo(D d) 14 | { 15 | System.out.println("dd"); 16 | } // end of method foo 17 | }// end of method class D 18 | -------------------------------------------------------------------------------- /D1.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // D1.java 3 | // the class reprsents D1 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class D extends A 7 | { 8 | public void calc(int x, int y) 9 | { 10 | System.out.println(7+y+x); 11 | }// end of method calc 12 | }// end of class D 13 | -------------------------------------------------------------------------------- /DateDriver.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // DateDriver.java 3 | // A main class for check the Date class 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | 7 | import java.util.Scanner; 8 | public class DateDriver 9 | { 10 | public static void main(String[] args) 11 | { 12 | Scanner scanner = new Scanner(System.in); 13 | // print to user 14 | System.out.println("This program demonstrates the " + " usage of Date class"); 15 | System.out.println("Please enter the day, month, year"); 16 | // take user input 17 | int day = scanner.nextInt(); 18 | int month = scanner.nextInt(); 19 | int year = scanner.nextInt(); 20 | // making 2 Date object 21 | Date d1 = new Date(day, month, year); 22 | Date d2 = new Date(d1.getDay(), d1.getMonth(), d1.getYear()); 23 | System.out.println("d1 = " + d1.toString()); 24 | System.out.println("d2 = " + d2.toString()); 25 | // test the methods in the class 26 | if (d1.equals(d2)) 27 | { 28 | System.out.println("Same Date"); 29 | } 30 | else 31 | { 32 | System.out.println("Different Dates"); 33 | } 34 | d1.setMonth(6); 35 | System.out.println("new month in d1: " + d1.getMonth()); 36 | System.out.println("d1 = " + d1.toString()); 37 | d2.setYear(2022); 38 | System.out.println("Updated year in d2: " + d2.getYear()); 39 | System.out.println("Updated d2 = " + d2.getDay() + "/" + d2.getMonth() + "/" + d2.getYear()); 40 | if (d1.equals(d2)) 41 | { 42 | System.out.println("Same Date"); 43 | } else if (date2.before(date1)) 44 | { 45 | System.out.println("the date before: " + date2); 46 | System.out.println("the date after: " + date1); 47 | } 48 | else 49 | { 50 | System.out.println("the date before: " + date1); 51 | System.out.println("the date after: " + date2); 52 | } 53 | // close the scanner object 54 | scanner.close(); 55 | } // end of method main 56 | } // end of class DateDriver 57 | -------------------------------------------------------------------------------- /DynamicArray.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | //******************************************************* 3 | // DynamicArray.java 4 | // A class that represents an implementation of DynamicArray in java 5 | // Author: liron mizrahi 6 | //******************************************************* 7 | public class DynamicArray 8 | { 9 | Object[] _data; 10 | int _size; 11 | 12 | /** 13 | * constructor of the class 14 | * @param None 15 | * @return None 16 | */ 17 | public DynamicArray() 18 | { 19 | _size = 0; 20 | _data = new Object[1]; 21 | }// end of method DynamicArray 22 | /** 23 | * getSize method return the size of the dynamic array 24 | * @param None 25 | * @return int 26 | */ 27 | public int getSize() 28 | { 29 | return _size; 30 | }// end of method getSize 31 | /** 32 | * get method return the value of the arr in given index 33 | * @param int 34 | * @return T (generics) 35 | */ 36 | public T get(int index) 37 | { 38 | return (T) _data[index]; 39 | }// end of method get 40 | /** 41 | * put method insert a element to the arr 42 | * @param int 43 | * @return T (generics) 44 | */ 45 | public void put(Object element) 46 | { 47 | ensureCapacity(_size + 1); 48 | _data[_size++] = element; 49 | }// end of method put 50 | /** 51 | * ensureCapacity method ensure the capacity is 52 | * @param int 53 | * @return T (generics) 54 | */ 55 | public void ensureCapacity(int minCapacity) 56 | { 57 | int oldCapacity = getSize(); 58 | if( minCapacity > oldCapacity) 59 | { 60 | int newCapacity = oldCapacity * 2; 61 | if(newCapacity < minCapacity) 62 | { 63 | newCapacity = minCapacity; 64 | } 65 | _data = Arrays.copyOf(_data, newCapacity); 66 | } 67 | }// end of method ensureCapacity 68 | }// end of class DynamicArray 69 | -------------------------------------------------------------------------------- /E.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // E.java 3 | // the class reprsents E 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class E extends C 7 | { 8 | public int calc(int x) 9 | { 10 | System.out.println("8"); 11 | return x + 3; 12 | }// end of method calc 13 | }// end of class E 14 | -------------------------------------------------------------------------------- /Entry.java: -------------------------------------------------------------------------------- 1 | 2 | //******************************************************* 3 | // Class Entry.java 4 | // Class that represents an implementation of a Entry for hase table in java 5 | // Author: liron mizrahi 6 | //******************************************************* 7 | public class Entry 8 | { 9 | int _key; 10 | Object _value; 11 | Entry _next; 12 | /** 13 | * constructor of the class 14 | * @param int 15 | * @return None 16 | */ 17 | public Entry(int key, Object value) 18 | { 19 | _key = key; 20 | _value = value; 21 | 22 | }// end of method Entry 23 | public Entry() 24 | { 25 | _next = null; 26 | }// end of method entry 27 | /** 28 | * Method return the key 29 | * @param None 30 | * @return int 31 | */ 32 | public int GetKey() 33 | { 34 | return _key; 35 | }// end of method KetKey 36 | /** 37 | * Method return the value 38 | * @param None 39 | * @return Object 40 | */ 41 | public Object GetValue() 42 | { 43 | return _value; 44 | }// end of method GetValue 45 | }// end of class Entry 46 | -------------------------------------------------------------------------------- /Exam2010JavaA-82/A.java: -------------------------------------------------------------------------------- 1 | public class A 2 | { 3 | private int _x, _y; 4 | 5 | public A() 6 | { 7 | _x = 0; 8 | _y = 0; 9 | } 10 | 11 | public A(int x, int y){ 12 | _x = x; 13 | _y = y; 14 | } 15 | 16 | public A(A other) 17 | { 18 | _x = other._x; 19 | _y = other._y; 20 | } 21 | public int getX() 22 | { 23 | return _x; 24 | } 25 | public int getY() 26 | { 27 | return _y; 28 | } 29 | public void increment() 30 | { 31 | _x = _x + 1; 32 | _y = _y + 1; 33 | } 34 | public boolean equal(A other) 35 | { 36 | return (_x == other._x) && ( _y == other._y); 37 | } 38 | } -------------------------------------------------------------------------------- /Exam2010JavaA-82/Account.java: -------------------------------------------------------------------------------- 1 | 2 | public class Account 3 | { 4 | private static final int FEE = 3; 5 | 6 | private long _accountNum; 7 | private Customer _customer; 8 | private double _balance; 9 | private double _interest; 10 | /** 11 | * constructor of the class Account 12 | * @param: long num, Customer c, double interest 13 | * @return: None 14 | */ 15 | public Account(long num, Customer c, double interest) 16 | { 17 | _accountNum = num; 18 | _customer = c; 19 | _balance = 0; 20 | _interest = interest; 21 | }// end of method Account 22 | /** 23 | * method return account number 24 | * @param: None 25 | * @return: long 26 | */ 27 | public long getAccountNum() 28 | { 29 | return _accountNum; 30 | }// end of method accountNum 31 | /** 32 | * method return the customer of the account 33 | * @param: None 34 | * @return: Customer 35 | */ 36 | public Customer getCustomer() 37 | { 38 | return new Customer(_customer); 39 | }// end of method getCustomer 40 | /** 41 | * method return the balance of the account 42 | * @param: None 43 | * @return: double 44 | */ 45 | public double getBalance() 46 | { 47 | return _balance; 48 | }// end of method getBalance 49 | /** 50 | * method return the interest of the account 51 | * @param: None 52 | * @return: double 53 | */ 54 | public double getInterest() 55 | { 56 | return _interest; 57 | }// end of method getinterest 58 | /** 59 | * method set new interest value to account 60 | * @param: double interestToSet 61 | * @return: None 62 | */ 63 | public void setInterest(double interestToSet) 64 | { 65 | _interest = interestToSet; 66 | }// end of method setInterest 67 | /** 68 | * method set the balance of the account 69 | * @param: double amount 70 | * @return: None 71 | */ 72 | public void deposit(double amount) 73 | { 74 | _balance = amount; 75 | }// end of method doposit 76 | /** 77 | * method set the new balance after withdraw 78 | * @param: double amount 79 | * @return: None 80 | */ 81 | public void withdraw(double amount) 82 | { 83 | _balance = _balance - amount; 84 | }// end of method withdraw 85 | /** 86 | * method add the interest to current balance 87 | * @param: None 88 | * @param: None 89 | */ 90 | public void addInterest() 91 | { 92 | _balance = _balance + _interest * _balance; 93 | }// end of method addInterest 94 | }// end of class Account 95 | -------------------------------------------------------------------------------- /Exam2010JavaA-82/B.java: -------------------------------------------------------------------------------- 1 | 2 | public class B 3 | { 4 | 5 | private double _x, _y; 6 | 7 | public B() 8 | { 9 | _x = 1.0; 10 | _y = -1.0; 11 | } 12 | public B(double x, double y) 13 | { 14 | _x = x; 15 | _y = y; 16 | } 17 | public boolean equals(B other) 18 | { 19 | return (_x == other._x) && (_y == other._y); 20 | } 21 | public boolean equals( A other) 22 | { 23 | return (_x == other.getX()) && (_y == other.getY()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Exam2010JavaA-82/Bank.java: -------------------------------------------------------------------------------- 1 | 2 | public class Bank 3 | { 4 | private static final int MAX_ACCOUNTS = 1000; 5 | private static final double POSITIVE_INTEREST = 0.005; 6 | private static final double NEGATIVE_INTEREST = 0.007; 7 | 8 | public Account[] _bank; 9 | public int _noOfAccounts; // 4 10 | /** 11 | * constructor of the class Bank 12 | * @param: None 13 | * @return: None 14 | */ 15 | public Bank() 16 | { 17 | _bank = new Account[MAX_ACCOUNTS]; 18 | _noOfAccounts = 0; 19 | }// end of method Bank 20 | /** 21 | * method return true if she add account to the bank array succsfuly otherwise false 22 | * @param: String first, String family, long id, long accNum 23 | * @return: boolean 24 | */ 25 | public boolean addAccount(String first, String family, long id, long accNum) 26 | { 27 | // base case managment 28 | Customer customerCurr = new Customer(id, first, family); 29 | if(_noOfAccounts == 0) 30 | { 31 | _bank[0] = new Account(accNum, customerCurr, POSITIVE_INTEREST); 32 | _noOfAccounts++; 33 | return true; 34 | } 35 | if(_noOfAccounts == MAX_ACCOUNTS) 36 | { 37 | return false; 38 | } 39 | _bank[_noOfAccounts] = new Account(accNum, customerCurr, POSITIVE_INTEREST); 40 | _noOfAccounts++; 41 | return true; 42 | }// end of method addAccount 43 | /** 44 | * method return the number of accounts there is to given customer 45 | * @param: Customer c 46 | * @return: int 47 | */ 48 | public int accountCustomer(Customer c) 49 | { 50 | int numberAccounts = 0; 51 | for(int i = 0; i < _noOfAccounts; i++) 52 | { 53 | if(_bank[i].getCustomer().equals(c)) 54 | { 55 | numberAccounts++; 56 | } 57 | } 58 | return numberAccounts; 59 | }// end of method accountCustomer 60 | /** 61 | * methed the return the wealthyest Customer in the bank 62 | * @param: None 63 | * @return: Customer 64 | */ 65 | public Customer wealthy() 66 | { 67 | if(_noOfAccounts == 1) 68 | { 69 | return _bank[0].getCustomer(); 70 | } 71 | double heightBalance =_bank[0].getBalance(); 72 | int indexWealthyest = 0; 73 | for(int i = 1; i < _noOfAccounts; i++) 74 | { 75 | if(_bank[i].getBalance() > heightBalance) 76 | { 77 | heightBalance = _bank[i].getBalance(); 78 | indexWealthyest = i; 79 | } 80 | } 81 | return _bank[indexWealthyest].getCustomer(); 82 | }// end of method wealthyest 83 | /** 84 | * methed set the interest in all the accounts 85 | * @param: None 86 | * @return: None 87 | */ 88 | public void setInterestInAccounts() 89 | { 90 | for(int i = 0; i < _noOfAccounts; i++) 91 | { 92 | if(_bank[i].getBalance() > 0) 93 | { 94 | double currBalance = _bank[i].getBalance(); 95 | double updatedBalance = currBalance + currBalance * POSITIVE_INTEREST; 96 | _bank[i].deposit(updatedBalance); 97 | } 98 | else if( _bank[i].getBalance() != 0) 99 | { 100 | double currBalance = _bank[i].getBalance(); 101 | double updatedBalance = currBalance + currBalance * NEGATIVE_INTEREST; 102 | _bank[i].deposit(updatedBalance); 103 | } 104 | } 105 | }// end of method setInterestInAccounts 106 | 107 | }// end of class Bank 108 | -------------------------------------------------------------------------------- /Exam2010JavaA-82/Customer.java: -------------------------------------------------------------------------------- 1 | 2 | public class Customer 3 | { 4 | private long _id; 5 | private String _firstName; 6 | private String _familyName; 7 | /** 8 | * constructor of the class Customer 9 | * @param: long id, String first, String family 10 | * @return: None 11 | */ 12 | public Customer(long id, String first, String family) 13 | { 14 | _id = id; 15 | _firstName = first; 16 | _familyName = family; 17 | }// end of method 18 | /** 19 | * copy constructor of the class Customer 20 | * @param: Customer other 21 | * @return: None 22 | */ 23 | public Customer(Customer other) 24 | { 25 | _id = other._id; 26 | _firstName = other._firstName; 27 | _familyName = other._familyName; 28 | }// end of method customer 29 | /** 30 | * method return customer id 31 | * @param: None 32 | * @return: long 33 | */ 34 | public long getId() 35 | { 36 | return _id; 37 | }// end of method getId 38 | /** 39 | * method return customer first name 40 | * @param: None 41 | * @return: String 42 | */ 43 | public String getFirstName() 44 | { 45 | return new String(_firstName); 46 | }// end of method getFirstName 47 | /** 48 | * method return customer family name 49 | * @param: None 50 | * @return: String 51 | */ 52 | public String getFamilyName() 53 | { 54 | return new String(_familyName); 55 | }// end of method getFamilyName 56 | /** 57 | * method set the id of the customer 58 | * @param: long idToSet 59 | * @return: None 60 | */ 61 | public void setId( long idToSet) 62 | { 63 | _id = idToSet; 64 | }// end of method setId 65 | /** 66 | * method set the first name of the customer 67 | * @param: String s 68 | * @return: None 69 | */ 70 | public void setFirstName(String s) 71 | { 72 | _firstName = s; 73 | }// end of method setFirstName 74 | /** 75 | * method set the family name of the customer 76 | * @param: String s 77 | * @return: None 78 | */ 79 | public void setFamilytName(String s) 80 | { 81 | _familyName = s; 82 | }// end of method setFirstName 83 | /** 84 | * method return true if given customer is equals 85 | * @param: Customer c 86 | * @return: boolean 87 | */ 88 | public boolean equals(Customer c) 89 | { 90 | if(c._id == _id && c._firstName.equals(_firstName) && c._familyName.equals(_familyName)) 91 | { 92 | return true; 93 | } 94 | return false; 95 | }// end of method equlas 96 | }// end of class Customer 97 | -------------------------------------------------------------------------------- /Exam2010JavaA-82/Exam2010JavaA82.java: -------------------------------------------------------------------------------- 1 | 2 | public class Exam2010JavaA82 3 | { 4 | public static int maximalDrop(int[] a) 5 | { 6 | int maxDiff = Integer.MIN_VALUE; 7 | int minValue = a[0]; 8 | int maxValue = a[0]; 9 | int maxValueIndex = 0; 10 | int minValueIndex = 0; 11 | for(int i = 1; i < a.length; i++) 12 | { 13 | if(a[i] > maxValue) 14 | { 15 | maxValue = a[i]; 16 | maxValueIndex = i; 17 | } 18 | else if( a[i] < minValue) 19 | { 20 | minValue = a[i]; 21 | minValueIndex = i; 22 | } 23 | else if( minValue < a[i] && i > maxValueIndex) 24 | { 25 | minValue = a[i]; 26 | minValueIndex = i; 27 | } 28 | if(maxValue - minValue > maxDiff && maxValueIndex < minValueIndex) 29 | { 30 | maxDiff = maxValue - minValue; 31 | } 32 | } 33 | return maxDiff; 34 | } 35 | public static void main(String[] args) 36 | { 37 | System.out.println(1.0 == 1); 38 | } 39 | /** 40 | * solution exercise 3 41 | * 1: System.out.print(a1 == a2); -> false 42 | * 2: System.out.print(a1 == a3); -> true 43 | * 3: System.out.print(a1 == a4); -> false 44 | * 4: System.out.print(a3 == a4); -> false 45 | * 5: System.out.print(b1 == b2); -> false 46 | * 6: System.out.print(b2 == b3); -> false 47 | * 7: System.out.print(b1 == b3); -> false 48 | * 8: System.out.print(a1.equals(a3)); -> true 49 | * 9: System.out.print(a2.equals(a1)); -> false 50 | * 10: System.out.print(a4.equals(a1)); -> true 51 | * 11: System.out.print(b1.equals(b2)); -> false 52 | * 12: System.out.print(b2.equals(a4)); -> true 53 | * 13: System.out.print(b1.equals(b3)); -> true 54 | * 14: System.out.print(b2.equals(a1)); -> true 55 | */ 56 | /** 57 | * 3.2 58 | * the number of objects is 2 59 | * 3.3 60 | * the number is 3 61 | */ 62 | }// end of class Exam2010JavaA82 63 | -------------------------------------------------------------------------------- /Exam2010JavaA-82/test2010JavaAMoad82.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lironmiz/Computer-Science-in-Java/71abf905b948e24c02e2d3fc303e285e70a45dfa/Exam2010JavaA-82/test2010JavaAMoad82.pdf -------------------------------------------------------------------------------- /Exam2011JavaA/Clsrm.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Clsrm.java 3 | * the class reprsents a clsrm 4 | * Author: liron mizrhai 5 | */ 6 | public class Clsrm 7 | { 8 | private int _classNum; 9 | private int _classPlaces; 10 | private boolean _isAvailable; 11 | /** 12 | * constrctor of the class Clsrm 13 | * @param: int num, int maxPlaces, boolean isAvail 14 | * @return: None 15 | */ 16 | public Clsrm(int num, int maxPlaces, boolean isAvail) 17 | { 18 | _classNum = num; 19 | _classPlaces = maxPlaces; 20 | _isAvailable = isAvail; 21 | }// end of method Clsrm 22 | /** 23 | * copy constrctor of the class 24 | * @param: Clsrm c 25 | * @return: None 26 | */ 27 | public Clsrm(Clsrm c) 28 | { 29 | _classNum = c._classNum; 30 | _classPlaces = c._classPlaces; 31 | _isAvailable = c._isAvailable; 32 | }// end of method Clsrm 33 | /** 34 | * the method return the class number 35 | * @param: None 36 | * @return: int 37 | */ 38 | public int getClassNum() 39 | { 40 | return _classNum; 41 | }// end of method getClassNum 42 | /** 43 | * the method return the class places 44 | * @param: None 45 | * @return: int 46 | */ 47 | public int getClassPlaces() 48 | { 49 | return _classPlaces; 50 | }// end of method getClaassPlaces 51 | /** 52 | * the method return if the class avilable or not 53 | * @param: None 54 | * @return: boolean 55 | */ 56 | public boolean getAvailable() 57 | { 58 | return _isAvailable; 59 | }// end of method getAvilable 60 | /** 61 | * the method set if the class is avilable 62 | * @param: boolean avail 63 | * @return: None 64 | */ 65 | public void setAvilable(boolean avail) 66 | { 67 | _isAvailable = avail; 68 | }// end of method setAvilable 69 | /** 70 | * the method return if the class handicapped suitable 71 | * @param: None 72 | * @return: boolean 73 | */ 74 | public boolean handicappedSuitable() 75 | { 76 | if(_classNum < 100) 77 | { 78 | return true; 79 | } 80 | return false; 81 | }// end of method hadicappedSutable 82 | /** 83 | * the method return if the two clsrm is equals 84 | * equals classes is when the number of class places is equal 85 | * @param: Clsrm other 86 | * @return: boolean 87 | */ 88 | public boolean equals(Clsrm other) 89 | { 90 | if(_classPlaces == other.getClassPlaces()) 91 | { 92 | return true; 93 | } 94 | return false; 95 | }// end of method equals 96 | /** 97 | * the method return true if the class places is bigger than the class places in the given paramter 98 | * @param: Clsrm other 99 | * @return: boolean 100 | */ 101 | public boolean isBigger(Clsrm other) 102 | { 103 | if(_classPlaces > other.getClassPlaces()) 104 | { 105 | return true; 106 | } 107 | return false; 108 | }// end of method isBigger 109 | /** 110 | * the method return true if the class is smaller than the class given as paramter 111 | * @param: Clsrm other 112 | * @return: boolean 113 | */ 114 | public boolean isSmaller(Clsrm other) 115 | { 116 | if(other.isBigger(this)) 117 | { 118 | return true; 119 | } 120 | return false; 121 | }// end of method isSmaller 122 | /** 123 | * the method return true if the class is higher then the class given as paramter 124 | * @param: Clsrm other 125 | * @return: boolean 126 | */ 127 | public boolean isHigher(Clsrm other) 128 | { 129 | if(_classNum < 100 && other.getClassNum() < 100) 130 | { 131 | return false; 132 | } 133 | else if(_classNum > 99 && other.getClassNum() < 100) 134 | { 135 | return true; 136 | } 137 | else if(_classNum < 100 && other.getClassNum() > 99) 138 | { 139 | return false; 140 | } 141 | else if(_classNum > 99 && other.getClassNum() > 99) 142 | { 143 | int lastDigit = _classNum / 100; 144 | int secondLastDigit = other.getClassNum() / 100; 145 | if(lastDigit > secondLastDigit) 146 | { 147 | return true; 148 | } 149 | return false; 150 | } 151 | return false; 152 | }// end of method isHigher 153 | /** 154 | * the method return the floor number of the class 155 | * @param: None 156 | * @return: int 157 | */ 158 | public int getFloorNumber() 159 | { 160 | if(this.getClassNum() < 100) 161 | { 162 | return 0; 163 | } 164 | else 165 | { 166 | return this.getClassNum() / 100; 167 | } 168 | }// end of method getFloorNumber 169 | }// end of class Clsrm 170 | -------------------------------------------------------------------------------- /Exam2011JavaA/College.java: -------------------------------------------------------------------------------- 1 | /** 2 | * College.java 3 | * the class reprsents a College 4 | * Author : liron mizrhai 5 | */ 6 | public class College 7 | { 8 | public final static int NUM_OF_COURSES_OR_CLSRM = 20; 9 | private Course[] _courses; 10 | private Clsrm[] _clsrms; 11 | /** 12 | * the methd return the most popular course in the college 13 | * @param: None 14 | * @return: Course 15 | */ 16 | public Course mostPopular() 17 | { 18 | int index = 0; 19 | for(int i = 1; i < _courses.length; i++)// 4 20 | { 21 | if(_courses[i].getNumOfStudents() > _courses[index].getNumOfStudents()) 22 | { 23 | index = i; 24 | } 25 | } 26 | return _courses[index]; 27 | }// end of method mostPopular 28 | /** 29 | * the method return the beggest clsss in the college 30 | * @param: None 31 | * @return: Clsrm 32 | */ 33 | public Clsrm biggestClsrm() 34 | { 35 | int index = 0; 36 | for(int i = 1; i < _clsrms.length; i++) 37 | { 38 | if(_clsrms[i].getClassPlaces() > _clsrms[index].getClassPlaces()) 39 | { 40 | index = i; 41 | } 42 | } 43 | return _clsrms[index]; 44 | }// end of method biggestClsrm 45 | /** 46 | * the method return how many clsrms are suitable for handicapped people 47 | * @param: None 48 | * @return: int 49 | */ 50 | public int howManyHandi() 51 | { 52 | int num = 0; 53 | for(int i = 0; i < _clsrms.length; i++) 54 | { 55 | if(_clsrms[i].handicappedSuitable() && _clsrms[i].getAvailable()) 56 | { 57 | num++; 58 | } 59 | } 60 | return num; 61 | }// end of method howManyHandi 62 | /** 63 | * the method return how many clsrms are suitable for handicapped people 64 | * @param: None 65 | * @return: int 66 | */ 67 | public int howManyOnTopFloor() 68 | { 69 | int biggestFloor = getBiggestFloor(); 70 | int numTopFloor = 0; 71 | for(int i = 0; i < _clsrms.length; i++) 72 | { 73 | if(_clsrms[i].getFloorNumber() == biggestFloor) 74 | { 75 | numTopFloor++; 76 | } 77 | } 78 | return numTopFloor; 79 | }// end of method howManyOnTopFloor 80 | /** 81 | * the methd return the biggest floor 82 | * @param: None 83 | * @return: Course 84 | */ 85 | private int getBiggestFloor() 86 | { 87 | int index = 0; 88 | for(int i = 1; i < _clsrms.length; i++) 89 | { 90 | if(_clsrms[i].isHigher(_clsrms[index])) 91 | { 92 | index = i; 93 | } 94 | } 95 | return _clsrms[index].getFloorNumber(); 96 | }// end of method getBiggestFloor 97 | }// end of class College 98 | -------------------------------------------------------------------------------- /Exam2011JavaA/Course.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Course.java 3 | * the class reprsents a course 4 | * Author: liron mizrhai 5 | */ 6 | public class Course 7 | { 8 | private String _courseName; 9 | private int _numOfStudents; 10 | private Clsrm _courseClsrm; 11 | /** 12 | * constractor of the class course 13 | * @param: String courseName, int numOfStudents 14 | * @retrurn: None 15 | */ 16 | public Course(String courseName, int numOfStudents) 17 | { 18 | _courseName = courseName; 19 | if( numOfStudents > -1) 20 | { 21 | _numOfStudents = numOfStudents; 22 | } 23 | else 24 | { 25 | _numOfStudents = -1; 26 | } 27 | _courseClsrm = null; 28 | }// end of method Course 29 | /** 30 | * the method return the num of students in the course 31 | * @param: None 32 | * @retrurn: int 33 | */ 34 | public int getNumOfStudents() 35 | { 36 | return _numOfStudents; 37 | }// end of method getNumOfStudents 38 | /** 39 | * the method return name of the course 40 | * @param: None 41 | * @retrurn: String 42 | */ 43 | public String getCourseName() 44 | { 45 | return _courseName; 46 | }// end of method getCourseName 47 | /** 48 | * the method return the clsrm of the course 49 | * @param: None 50 | * @retrurn: Clsrm (null) 51 | */ 52 | public Clsrm getClsrm() 53 | { 54 | if(_courseClsrm == null) 55 | { 56 | return null; 57 | } 58 | return _courseClsrm; 59 | }// end of method getClsrm 60 | /** 61 | * the method set the clsrm of the course 62 | * @param: Clsrm cls 63 | * @retrurn: None 64 | */ 65 | public void setClsrm(Clsrm cls) 66 | { 67 | if(_numOfStudents <= cls.getClassPlaces() && cls.getAvailable()) 68 | { 69 | _courseClsrm = new Clsrm(cls); 70 | cls.setAvilable(false); 71 | } 72 | }// end of method setClsrm 73 | /** 74 | * the method return if the course is suitable for handicapped 75 | * @param: boolean handi 76 | * @retrurn: boolean 77 | */ 78 | public boolean clsrmSuitable(boolean handi) 79 | { 80 | if(!handi) 81 | { 82 | return true; 83 | } 84 | else if(_courseClsrm == null) 85 | { 86 | return false; 87 | } 88 | else if(handi && _courseClsrm.handicappedSuitable()) 89 | { 90 | return true; 91 | } 92 | return false; 93 | }// end of method clsrmSuitable 94 | /** 95 | * the method return if the class is morePopular 96 | * class is more popular if the number of students in the course is higher 97 | * @param: Course c 98 | * @retrurn: boolean 99 | */ 100 | public boolean morePopular(Course c) 101 | { 102 | if(_numOfStudents > c._numOfStudents) 103 | { 104 | return true; 105 | } 106 | return false; 107 | }// end of method morePopular 108 | }// end of class Course 109 | -------------------------------------------------------------------------------- /Exam2011JavaA/Exam2011JavaA87.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Exam2011JavaA87.java 3 | * the class hava solutions to the test 4 | * Author : liron mizrhai 5 | */ 6 | public class Exam2011JavaA87 7 | { 8 | /** 9 | * the method return true if the there are two numbers in the array that there difference is bigger than x else false 10 | * @parma: int[] a, int x 11 | * @return boolean 12 | */ 13 | public boolean difference(int[] a, int x) 14 | { 15 | int max = a[0]; 16 | int min = a[0]; 17 | 18 | for(int i = 1; i < a.length; i++) 19 | { 20 | if(a[i] > max) 21 | { 22 | max = a[i]; 23 | } 24 | if(a[i] < min) 25 | { 26 | min = a[i]; 27 | } 28 | } 29 | int difference = max - min; 30 | return difference > x ? true : false; 31 | }// end of method difference 32 | /** 33 | * Exercise 3 34 | * the correct statments are A, B, E 35 | */ 36 | }// end of class Exam2011JavaA87 37 | -------------------------------------------------------------------------------- /Exam2011JavaA/testJava2011A.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lironmiz/Computer-Science-in-Java/71abf905b948e24c02e2d3fc303e285e70a45dfa/Exam2011JavaA/testJava2011A.pdf -------------------------------------------------------------------------------- /Exam2014JavaA/Date.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Date.java 3 | * the class reprsents a Date 4 | * Author: liron mizrhai 5 | */ 6 | import java.util.Scanner; 7 | public class Date 8 | { 9 | private int _day; 10 | private int _month; 11 | private int _year; 12 | /** 13 | * constructor of the class Date 14 | * @param: int d, int m, int y 15 | * @return: None 16 | */ 17 | public Date(int d, int m, int y) 18 | { 19 | _day = d; 20 | _month = m; 21 | _year = y; 22 | }// end of method Date 23 | /** 24 | * copy constructor of the class Date 25 | * @param: Date d 26 | * @return: None 27 | */ 28 | public Date(Date d) 29 | { 30 | _day = d._day; 31 | _month = d._month; 32 | _year = d._year; 33 | }// end of method Date 34 | /** 35 | * method return the day of the date 36 | * @param: None 37 | * @return: int 38 | */ 39 | public int getDay() 40 | { 41 | return _day; 42 | }// end of method getDay 43 | /** 44 | * method return the month of the date 45 | * @param: None 46 | * @return: int 47 | */ 48 | public int getMonth() 49 | { 50 | return _month; 51 | }// end of method getMonth 52 | /** 53 | * method return the year of the date 54 | * @param: None 55 | * @return: int 56 | */ 57 | public int getYear() 58 | { 59 | return _year; 60 | }// end of method getYear 61 | /** 62 | * method set the day of the date 63 | * @param: int x 64 | * @return: None 65 | */ 66 | public void setDay(int x) 67 | { 68 | _day = x; 69 | }// end of method setDay 70 | /** 71 | * method set the month of the date 72 | * @param: int x 73 | * @return: None 74 | */ 75 | public void setMonth(int x) 76 | { 77 | _month = x; 78 | }// end of method setMonth 79 | /** 80 | * method set the month of the date 81 | * @param: int x 82 | * @return: None 83 | */ 84 | public void setYear(int x) 85 | { 86 | _year = x; 87 | }// end of method setDay 88 | /** 89 | * method return true if the two date are equals 90 | * @param: Date date 91 | * @return: boolean 92 | */ 93 | public boolean equals(Date date) 94 | { 95 | if(_day == date.getDay() && _month == date.getMonth() && _year == date.getYear()) 96 | { 97 | return true; 98 | } 99 | return false; 100 | }// end of method equals 101 | /** 102 | * Method checks if the date represented by the object on which the method is invoked is before the date received as a parameter 103 | * @param other 104 | * @return true if the date is before the other date or false if not 105 | */ 106 | public boolean before (Date other) 107 | { 108 | if ((this._month < other._month && this._year < other._year) || (this._day == other._day && this._month == other._month && this._year < other._year) || (this._month == other._month && this._year == other._year && this._day < other._day) || (this._month > other._month && this._year < other._year) || (this._year == other._year && this._month < other._month)) 109 | { 110 | return true; 111 | } 112 | return false; 113 | }// end of before method 114 | /** 115 | * Method checks if the date represented by the object on which the method is invoked is later than the date received as a parameter 116 | * @param other 117 | * @return true if the date is after the other date or false if not 118 | */ 119 | public boolean after(Date other) 120 | { 121 | if (other.before(this)) 122 | { 123 | return true; 124 | } 125 | return false; 126 | }// end of after method 127 | /** 128 | * Method return String that represents date 129 | * @param None 130 | * @return String 131 | */ 132 | public String toString() 133 | { 134 | return _day + "/" + _month + "/" + _year; 135 | }// end of method toString 136 | }// end of class Date 137 | -------------------------------------------------------------------------------- /Exam2014JavaA/Exam.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Exam.java 3 | * the class reprsents a Exam 4 | * Author: liron mizrhai 5 | */ 6 | public class Exam 7 | { 8 | private String _course; 9 | private Date _date; 10 | private int _noOfStudents; 11 | 12 | /** 13 | * constractor of the class Exam 14 | * @param: String courseName, int day, int month, int year, int numOfStudents 15 | * @return: None 16 | */ 17 | public Exam(String courseName, int day, int month, int year, int numOfStudents) 18 | { 19 | _course = courseName; 20 | Date date = new Date(day, month, year); 21 | _date = new Date(date); 22 | int _noOfStudents = numOfStudents; 23 | }// end of method Exam 24 | /** 25 | * copy constractor of the class Exam 26 | * @param: Exam other 27 | * @return: None 28 | */ 29 | public Exam(Exam other) 30 | { 31 | _course = other._course; 32 | _date = new Date(other._date); 33 | _noOfStudents = other._noOfStudents; 34 | }// end of method Exam 35 | /** 36 | * method the return the date 37 | * @param: None 38 | * @return: Date 39 | */ 40 | public Date getDate() 41 | { 42 | return _date; 43 | }// end of method getDate() 44 | /** 45 | * method return the exam name 46 | * @param: None 47 | * @return: String 48 | */ 49 | public String getCourse() 50 | { 51 | return _course; 52 | }// end of method getCourse 53 | /** 54 | * method return the number of students 55 | * @param: None 56 | * @return: int 57 | */ 58 | public int getNumOfStudents() 59 | { 60 | return _noOfStudents; 61 | }// end of method getNumOfStudents 62 | /** 63 | * method return true if the given name is equal to exam name and false otherwise 64 | * @param: String name 65 | * @return: boolean 66 | */ 67 | public boolean sameCourse(String name) 68 | { 69 | return _course.equals(name); 70 | }// end of method sameCourse 71 | /** 72 | * method return true if given date same as _date and false otherwise 73 | * @param: Date date 74 | * @return: boolean 75 | */ 76 | public boolean sameDate(Date date) 77 | { 78 | return _date.equals(date); 79 | }// end of method sameDate 80 | /** 81 | * method return true if the name is valid 82 | * @param: None 83 | * @return: boolean 84 | */ 85 | public boolean isValidName() 86 | { 87 | if(_course.matches("[a-zA-Z]+")) 88 | { 89 | for(int i = 0; i < _course.length(); i++) 90 | { 91 | if(!Character.isLowerCase(_course.charAt(i))) 92 | { 93 | return false; 94 | } 95 | } 96 | return true; 97 | } 98 | else 99 | { 100 | return false; 101 | } 102 | }// end of method isValidName 103 | }// end of class Exam 104 | -------------------------------------------------------------------------------- /Exam2014JavaA/Exam2014JavaA.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Exam2014JavaA.java 3 | * the class reprsents a solutions to the test 4 | * Author: liron mizrhai 5 | */ 6 | public class Exam2014JavaA 7 | { 8 | public static void main(String[] args) 9 | { 10 | String s1 = "abcdef\n"; 11 | //System.out.println(s1.substring(0,0)); 12 | A.f(5); 13 | } 14 | /** 15 | * solution to Exercise 2 16 | * 2.1 The method returns the index with the largest ASCII 17 | * length in the string from position f + 1 to the end 18 | * of the string 19 | * 20 | * 2.2 The "fun2" method performs the swapping 21 | * of characters to move the smallest character 22 | * found by the "fun1" method to its proper position 23 | * in the string. The method takes the character at 24 | * the index "i" and moves it to the left until it 25 | * is in its proper sorted position. The method does 26 | * his by comparing the value of the current character 27 | * with the previous character in the string, and if 28 | * the previous character is greater, the two characters 29 | * are swapped. This process continues until the current 30 | * character is in its proper position, or until there 31 | * are no more characters to the left to compare with. 32 | * The sorted string is then returned by the method. 33 | * 34 | * 2.3 The "something" method performs a sort on a given 35 | * string of characters "s" by iterating over the string 36 | * "s" and finding the index of the smallest character 37 | * starting from the current position "i". 38 | * The method then moves the smallest character to the current 39 | * position "i" by swapping the characters in the string. 40 | * This process is repeated until the string is 41 | * sorted in ascending order. 42 | */ 43 | 44 | /** 45 | * solution to exercise 3 46 | * a.g(4) : ? -> 6, 4 -> lines of code 47 | * a.g(3) : ? -> 3, 3 -> lines of code 48 | * a.f(1) : ? -> 0, 1 -> lines of code 49 | * a.f(5) : ? -> 20, 14 -> lines of code 50 | */ 51 | // Ex2 code 52 | public int fun1(String s, int f) 53 | { 54 | int ans = f; 55 | for(int i =f+1; i s.charAt(i)) 58 | { 59 | ans = i; 60 | } 61 | } 62 | return ans; 63 | }// end of method fun1 64 | public String fun2(String s, int i) 65 | { 66 | char value = s.charAt(i); 67 | while (i > 0 && s.charAt(i-1) > value) 68 | { 69 | s=s.substring(0,i)+s.charAt(i-1)+s.substring(i+1); 70 | i = i-1; 71 | } 72 | s=s.substring(0,i)+value+s.substring(i+1); 73 | return s; 74 | }// end of method fun2 75 | public String something(String s) 76 | { 77 | for(int i=0; i0; i--) 90 | { 91 | g(i); 92 | } 93 | }// ene of method f 94 | public static void g (int n) 95 | { 96 | for (int i=0; i 99) 31 | { 32 | return false; 33 | } 34 | _center[_noOfExams] = ex; 35 | _noOfExams++; // 1 36 | return true; 37 | }// end of method addExam 38 | /** 39 | * method return the number of exams between two given dates 40 | * @param: Date d1, Date d2 41 | * @return: int 42 | */ 43 | public int howManyExamsBetweenDates(Date d1, Date d2) 44 | { 45 | int numOfExams = 0; 46 | Date DateEarlier = d1.before(d2) ? d1 : d2; 47 | for(int i = 0; i < _noOfExams; i++) 48 | { 49 | Exam curr = _center[i]; 50 | if(curr.getDate().after(d1) && curr.getDate().before(d2)) 51 | { 52 | numOfExams++; 53 | } 54 | else if(curr.getDate().equals(d1) || curr.getDate().equals(d2)) 55 | { 56 | numOfExams++; 57 | } 58 | } 59 | return numOfExams; 60 | }// end of method howManyExamsBetweenDates 61 | /** 62 | * method return the most Popular Date 63 | * @param: None 64 | * @return: Date 65 | */ 66 | public Date mostPopularDate() 67 | { 68 | int[] ExamsInDate = new int[_noOfExams]; 69 | for(int i = 0; i < _noOfExams; i++) 70 | { 71 | Date currDate = _center[i].getDate(); 72 | ExamsInDate[i] = howManyExamsBetweenDates(currDate, currDate); 73 | } 74 | int max = -1; 75 | int maxIndex = 0; 76 | for(int i = 0; i < ExamsInDate.length; i++) 77 | { 78 | if(ExamsInDate[i] > max) 79 | { 80 | max = ExamsInDate[i]; 81 | maxIndex = i; 82 | } 83 | } 84 | return _center[maxIndex].getDate(); 85 | }// end of method mostPopularDate 86 | /** 87 | * method delete all the exams that there name is equal to given courseName 88 | * @param: String courseName 89 | * @return: None 90 | */ 91 | public void deleteExams(String courseName) 92 | { 93 | int preNumOfExams = _noOfExams; 94 | for(int i = 0; i < _noOfExams; i++) 95 | { 96 | if(_center[i].getCourse().equals(courseName)) 97 | { 98 | _noOfExams--; 99 | _center[i] = null; 100 | } 101 | } 102 | 103 | for(int j = 0; j < preNumOfExams; j++) 104 | { 105 | if(_center[j] == null) 106 | { 107 | for( int k = j + 1; k < preNumOfExams; k++) 108 | { 109 | if(_center[k] != null) 110 | { 111 | _center[j] = _center[k]; 112 | _center[k] = null; 113 | break; 114 | } 115 | } 116 | } 117 | } 118 | }// end of methd deleteExams 119 | }// end of class ExamCenter 120 | -------------------------------------------------------------------------------- /Exam2017MoadBJavaA/Exam2017JavaAMoadB.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Exam2017JavaAMoadB.java 3 | * the class reprsents a Exam2017JavaAMoadB 4 | * Author: liron mizrhai 5 | */ 6 | public class Exam2017JavaAMoadB 7 | { 8 | /** 9 | * solution to exercise 2: 10 | * 2.1 11 | * solution: |3|4|1|2|11|9| 12 | * 2.2 13 | * soltion: |2|1|3|4|11|9| 14 | * 2.3 15 | * solution: 16 | * Median of the members of the array 17 | * (that is, the number that half of the members are larger 18 | * than and half of the members are smaller than) 19 | */ 20 | public class Q2 21 | { 22 | private static double average (int []a, int low, int high) 23 | { 24 | System.out.println("ok"); 25 | return 5; 26 | }// end of method average 27 | 28 | private static void swap (int []a, int p, int q) 29 | { 30 | 31 | }// end of method swap 32 | 33 | public static int split (int[] a, int left, int right) 34 | { 35 | double avg = average (a, left, right); 36 | while (left < right) 37 | { 38 | while (left < right && a[left] <=avg) 39 | { 40 | left++; 41 | } 42 | while (right > left && a[right] >=avg) 43 | { 44 | right--; 45 | } 46 | swap (a, left, right); 47 | } 48 | return right; 49 | }// end of method split 50 | 51 | public static void split (int [] a) 52 | { 53 | int left = 0; 54 | int right = a.length-1; 55 | int mid = a.length/2; 56 | int cut = split(a, left, right); 57 | while (cut!= mid) 58 | { 59 | if (cut < mid) 60 | { 61 | left = cut; 62 | } 63 | else 64 | { 65 | right = cut-1; 66 | } 67 | cut = split(a, left, right); 68 | } 69 | }// end of method split 70 | 71 | public static int what (int [] a) 72 | { 73 | split(a); 74 | int mid = a.length/2; 75 | int min = a[mid]; 76 | for (int i = mid+1; i= 'a' && s1.charAt(i)<= 'z') 104 | { 105 | int p = s1.charAt(i) -'a'; 106 | if (c[p] != 0) 107 | { 108 | res = res.substring(0, count) + res.substring(count+1); 109 | } 110 | else 111 | { 112 | count++; 113 | } 114 | } 115 | else 116 | { 117 | count++; 118 | } 119 | } 120 | return res; 121 | }// end of method what 122 | }// end of exam Exam2017JavaAMoadB -------------------------------------------------------------------------------- /Exam2017MoadBJavaA/RGBColor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * RGBColor.java 3 | * the class reprsents a RGBColor 4 | * Author: liron mizrhai 5 | */ 6 | public class RGBColor 7 | { 8 | private final int MAX_COLOR = 255; 9 | private int _red; 10 | private int _green; 11 | private int _blue; 12 | /** 13 | * constructor of the class RGBColor 14 | * @param: None 15 | * @return: None 16 | */ 17 | public RGBColor() 18 | { 19 | _red = 0; 20 | _green = 0; 21 | _blue = 0; 22 | }// end of method RGBColor 23 | /** 24 | * constructor of the class RGBColor 25 | * @param: int red, int green, int blue 26 | * @return: None 27 | */ 28 | public RGBColor(int red, int green, int blue) 29 | { 30 | _red = red; 31 | _green = green; 32 | _blue = blue; 33 | }// end of method RGBColor 34 | /** 35 | * copy constructor of the class RGBColor 36 | * @param: RGBColor other 37 | * @return: None 38 | */ 39 | public RGBColor(RGBColor other) 40 | { 41 | _red = other._red; 42 | _green = other._green; 43 | _blue = other._blue; 44 | }// end of method RGBColor 45 | /** 46 | * method return the _red 47 | * @param: None 48 | * @return: int 49 | */ 50 | public int getRed() 51 | { 52 | return _red; 53 | }// end of method getRed 54 | /** 55 | * method return the _blue 56 | * @param: None 57 | * @return: int 58 | */ 59 | public int getBlue() 60 | { 61 | return _blue; 62 | }// end of method getBlue 63 | /** 64 | * method return the _green 65 | * @param: None 66 | * @return: int 67 | */ 68 | public int getGreen() 69 | { 70 | return _green; 71 | }// end of method getGreen 72 | /** 73 | * method set the _red 74 | * @param: int num 75 | * @return: None 76 | */ 77 | public void setRed(int num) 78 | { 79 | if(!(num < 0 || num > 255)) 80 | { 81 | _red = num; 82 | } 83 | }// end of method setRed 84 | /** 85 | * method set the _blue 86 | * @param: int num 87 | * @return: None 88 | */ 89 | public void setBlue(int num) 90 | { 91 | if(!(num < 0 || num > 255)) 92 | { 93 | _blue = num; 94 | } 95 | }// end of method setBlue 96 | /** 97 | * method set the _green 98 | * @param: int num 99 | * @return: None 100 | */ 101 | public void setGreen(int num) 102 | { 103 | if(!(num < 0 || num > 255)) 104 | { 105 | _green = num; 106 | } 107 | }// end of method setGreen 108 | /** 109 | * method invert the rgb values 110 | * @param: None 111 | * @return: None 112 | */ 113 | public void invert() 114 | { 115 | if(_red <= 255 && _red >= 0 && _green <= 255 && _green >= 0 && _blue <= 255 && _blue >= 0) 116 | { 117 | _red = 255 - _red; 118 | _blue = 255 - _blue; 119 | _green = 255 - _green; 120 | } 121 | }// end of method invert 122 | /** 123 | * method mix the rgb values 124 | * @param: RGBColor other 125 | * @return: None 126 | */ 127 | public void mix(RGBColor other) 128 | { 129 | _red = (int) ((_red + other._red) / 2); 130 | _green = (int) ((_green + other._green) / 2); 131 | _blue = (int) ((_blue + other._blue) / 2); 132 | }// end of method mix 133 | /** 134 | * method convert the pixel to grayscale 135 | * @param: None 136 | * @return: double 137 | */ 138 | public double convertToGrayscale() 139 | { 140 | double gray = 0.3 * _red + 0.59 * _green + 0.11 * _blue; 141 | return gray; 142 | }// end of method convertToGreayscale 143 | /** 144 | * method return true if the given other is equals to the rgb that the methd is on 145 | * @param: other 146 | * @return: boolean 147 | */ 148 | public boolean equals(RGBColor other) 149 | { 150 | if(_red == other._red && _blue == other._blue && _green == other._green) 151 | { 152 | return true; 153 | } 154 | return false; 155 | }// end of method equals 156 | /** 157 | * method return string represents the data of the rebcolor 158 | * @param: None 159 | * @return: String 160 | */ 161 | public String toString() 162 | { 163 | return "(" + _red + "," + _green + "," + _blue + ")"; 164 | }// end of method toString 165 | }// end of class RGBColor 166 | -------------------------------------------------------------------------------- /Exam2017MoadBJavaA/RGBImage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * RGBImage.java 3 | * the class reprsents a RGBImage 4 | * Author: liron mizrhai 5 | */ 6 | public class RGBImage 7 | { 8 | private RGBColor[][] _image; 9 | /** 10 | * constructor of the class RGBImage 11 | * @param: int rows, int cols 12 | * @return: None 13 | */ 14 | public RGBImage(int rows, int cols) 15 | { 16 | _image = new RGBColor[rows][cols]; 17 | for(int i = 0; i < rows; i++) 18 | { 19 | for(int j = 0; j < cols; j++) 20 | { 21 | _image[i][j] = new RGBColor(); 22 | } 23 | } 24 | }// end of method RGBImage 25 | public RGBImage(RGBColor[][] pixels) 26 | { 27 | System.out.println("ok"); 28 | }// end of method RGBImage 29 | public RGBImage(RGBImage other) 30 | { 31 | System.out.println("ok"); 32 | }// end of method RGBImage 33 | /** 34 | * method return the pixel at postion row col 35 | * @param: int row, in col 36 | * @return: None 37 | */ 38 | public RGBColor getPixel(int row, int col) 39 | { 40 | if(row < _image.length && row > 0 && col < _image[0].length && col > 0) 41 | { 42 | return new RGBColor(_image[row][col]); 43 | } 44 | return new RGBColor(); 45 | }// end of method getPixel 46 | public void setPixel(int row, int col, RGBColor pixel) 47 | { 48 | System.out.println("ok"); 49 | }// end of method setPixel 50 | /** 51 | * method return the height of the image 52 | * @param: None 53 | * @return: int 54 | */ 55 | public int getHeight() 56 | { 57 | return _image.length; 58 | }// end of method getHeight 59 | /** 60 | * method return the height of the image 61 | * @param: None 62 | * @return: int 63 | */ 64 | public int getWidth() 65 | { 66 | return _image[0].length; 67 | }// end of method getHeight 68 | public boolean equals(RGBImage other) 69 | { 70 | if (other==null) 71 | { 72 | return false; 73 | } 74 | if (_image.length!=other._image.length ||_image[0].length!=other._image[0].length) 75 | { 76 | return false; 77 | } 78 | for(int i=0;i<_image.length;i++) 79 | { 80 | for(int j=0;j<_image[0].length;j++) 81 | { 82 | if (!(_image[i][j].equals(other._image[i][j]))) 83 | { 84 | return false; 85 | } 86 | } 87 | } 88 | return true; 89 | }// end of method equals 90 | /** 91 | * method flipHorizontal the two d array 92 | * @param: None 93 | * @return: None 94 | */ 95 | public void flipHorizontal() 96 | { 97 | for(int i=0;i<_image.length/2;i++) 98 | { 99 | RGBColor[] temp = _image[i]; 100 | _image[i] =_image[_image.length-i-1]; 101 | _image[_image.length-i-1]=temp; 102 | } 103 | }// end of method flipHorizontal 104 | /** 105 | * method invert the colors ot the two d array 106 | * @param: None 107 | * @return: None 108 | */ 109 | public void invertColors() 110 | { 111 | for(int i = 0; i < _image.length; i++) 112 | { 113 | for(int j = 0; j < _image[0].length; j++) 114 | { 115 | _image[i][j].invert(); 116 | } 117 | } 118 | }// end of method invertColors 119 | /** 120 | * method return two d array that been converted to gray scale 121 | * @param: None 122 | * @return: None 123 | */ 124 | public double[][] toGrayScaleArray() 125 | { 126 | int numRow = _image.length; 127 | int numCol = _image[0].length; 128 | double[][] grayScaleArray = new double[numRow][numCol]; 129 | for(int i = 0; i < numRow; i++) 130 | { 131 | for(int j = 0; j < numCol; j++) 132 | { 133 | grayScaleArray[i][j] = _image[i][j].convertToGrayscale(); 134 | } 135 | } 136 | return grayScaleArray; 137 | }// end of method toGrayScaleArray 138 | }// end of class RGBImage 139 | -------------------------------------------------------------------------------- /Exam2017MoadBJavaA/testJavaAMoadBYear2017.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lironmiz/Computer-Science-in-Java/71abf905b948e24c02e2d3fc303e285e70a45dfa/Exam2017MoadBJavaA/testJavaAMoadBYear2017.pdf -------------------------------------------------------------------------------- /Exam2018JavaA/Exam2018AJavaA.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Exam2018AJavaA.java 3 | * the class have solutions to the test 4 | * Author: liron mizrhai 5 | */ 6 | public class Exam2018AJavaA 7 | { 8 | /** 9 | * the method return true if there are a partition that the sum of the two partitions are equal 10 | * @param: int[] a 11 | * @return: boolean 12 | */ 13 | public static boolean equalPartition(int[] a) 14 | { 15 | for(int i = 0; i < a.length; i++) 16 | { 17 | int sumLeft = 0; 18 | int sumRight = 0; 19 | for(int j = 0; j <= i; j++) 20 | { 21 | sumLeft += a[j]; 22 | } 23 | for(int k = i + 1; k < a.length; k++) 24 | { 25 | sumRight += a[k]; 26 | } 27 | if(sumLeft == sumRight) 28 | { 29 | return true; 30 | } 31 | } 32 | return false; 33 | }// end of method equalPartition 34 | 35 | // Exercise 3 36 | // A -> 3 37 | // B -> abcde 38 | // C -> no 39 | // D -> t the method will return the index (position) 40 | // in the input string where the longest consecutive repeating characters sequence starts, 41 | 42 | // Exercise 4 43 | // A -> 2 3 44 | // b -> 2 45 | // c -> 2 5 46 | // d -> The method prints the necessary divisors when allowing 47 | // the number to reach zero by dividing them without a remainder 48 | }// end of class Exam2018AJavaA 49 | -------------------------------------------------------------------------------- /Exam2018JavaA/Exam2018JavaA83.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lironmiz/Computer-Science-in-Java/71abf905b948e24c02e2d3fc303e285e70a45dfa/Exam2018JavaA/Exam2018JavaA83.pdf -------------------------------------------------------------------------------- /Exam2018JavaA/Point.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Point.java 3 | * the class reprsents a Point 4 | * Author: liron mizrhai 5 | */ 6 | public class Point 7 | { 8 | public int _x; 9 | public int _y; 10 | /** 11 | * the constractor of the class Point 12 | * @param: int x, int y 13 | * @return: None 14 | */ 15 | public Point(int x, int y) 16 | { 17 | _x = x; 18 | _y = y; 19 | }// end of method Point 20 | /** 21 | * copy constractor of the class Point 22 | * @param: Point other 23 | * @return: None 24 | */ 25 | public Point(Point other) 26 | { 27 | _x = other._x; 28 | _y = other._y; 29 | }// end of method Point 30 | /** 31 | * method return the x value of the class 32 | * @param: None 33 | * @return: int 34 | */ 35 | public int getX() 36 | { 37 | return _x; 38 | }// end of method getX 39 | /** 40 | * method return the y value of the class 41 | * @param: None 42 | * @return: int 43 | */ 44 | public int getY() 45 | { 46 | return _y; 47 | }// end of method getY 48 | /** 49 | * method set the x attribute of the class 50 | * @param: int num 51 | * @return: None 52 | */ 53 | public void setX(int num) 54 | { 55 | _x = num; 56 | }// end of method setX 57 | /** 58 | * method set the y attribute of the class 59 | * @param: int num 60 | * @return: None 61 | */ 62 | public void setY(int num) 63 | { 64 | _y = num; 65 | }// end of method setY 66 | }// end of class Point 67 | -------------------------------------------------------------------------------- /Exam2018JavaA/Rectangle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Rectangle.java 3 | * the class reprsents a rectangle 4 | * Author: liron mizrhai 5 | */ 6 | public class Rectangle 7 | { 8 | private Point _pointSW; 9 | private Point _pointNE; 10 | /** 11 | * the constractor of the class Rectangle 12 | * @param: int x, int y 13 | * @return: None 14 | */ 15 | public Rectangle(int x, int y) 16 | { 17 | _pointNE.setX(x); 18 | _pointNE.setY(y); 19 | _pointSW.setX(0); 20 | _pointSW.setY(0); 21 | }// end of method Rectangle 22 | /** 23 | * second constractor of the class Rectangle 24 | * @param: Point SW, Point NE 25 | * @return: None 26 | */ 27 | public Rectangle(Point SW, Point NE) 28 | { 29 | _pointSW.setX(SW.getX()); 30 | _pointSW.setY(SW.getY()); 31 | _pointNE.setX(NE.getX()); 32 | _pointNE.setY(NE.getY()); 33 | }// end of method Rectangle 34 | /** 35 | * the method return the rectangle area 36 | * @param: None 37 | * @return: int 38 | */ 39 | public int RectangleArea() 40 | { 41 | int length = Math.abs(_pointSW.getY() - _pointNE.getY()); 42 | int width = Math.abs(_pointSW.getX() - _pointNE.getX()); 43 | return length * width; 44 | }// end of method RectangleArea 45 | }// end of class Rectangle 46 | -------------------------------------------------------------------------------- /Exam2018JavaAMoad82/Clock.java: -------------------------------------------------------------------------------- 1 | 2 | public class Clock 3 | { 4 | public int _hour; 5 | public int _minute; 6 | public int _second; 7 | /** 8 | * Constractor of the class Clock 9 | * @param: int h, int m, int s 10 | * @return: None 11 | */ 12 | public Clock(int h, int m, int s) 13 | { 14 | if( h <= 23 && h >= 0) 15 | { 16 | _hour = h; 17 | } 18 | else 19 | { 20 | _hour = 0; 21 | } 22 | if( m <= 59 && m >= 0) 23 | { 24 | _minute = m; 25 | } 26 | else 27 | { 28 | _minute = 0; 29 | } 30 | if( s <= 59 && s >= 0) 31 | { 32 | _second = s; 33 | } 34 | else 35 | { 36 | _second = 0; 37 | } 38 | }// end of method Clock 39 | /** 40 | * method return true if this object is before the given paramter otherwise false 41 | * @param: Clock other 42 | * @return: boolean 43 | */ 44 | public boolean before(Clock other) 45 | { 46 | if(_hour < other._hour) 47 | { 48 | return true; 49 | } 50 | else if(_hour == other._hour) 51 | { 52 | if(_minute < other._minute) 53 | { 54 | return true; 55 | } 56 | else if(_minute == other._minute) 57 | { 58 | if(_second < other._second) 59 | { 60 | return true; 61 | } 62 | return false; 63 | } 64 | } 65 | return false; 66 | }// end of method before 67 | /** 68 | * method return true if this object is after the given paramter otherwise false 69 | * @param: Clock other 70 | * @return: boolean 71 | */ 72 | public boolean after(Clock other) 73 | { 74 | return other.before(this); 75 | }// end of method after 76 | 77 | }// end of class Clock 78 | -------------------------------------------------------------------------------- /Exam2018JavaAMoad82/Exam2018Moad82.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class Exam2018Moad82 3 | { 4 | /** 5 | * solution to Exercise 2 6 | */ 7 | public static boolean diffValues(int[] a, int num) 8 | { 9 | if(a.length == 1) 10 | { 11 | return a[0] <= num && a[0] >= 1; 12 | } 13 | for(int i = 0; i < a.length; i++) 14 | { 15 | if(a[i] < 1 || a[i] > num) 16 | { 17 | return false; 18 | } 19 | if( i != a.length - 1) 20 | { 21 | for(int j = i + 1; j < a.length; j++) 22 | { 23 | if(a[j] == a[i]) 24 | { 25 | return false; 26 | } 27 | } 28 | } 29 | } 30 | return true; 31 | }// end of method diffValues 32 | /** 33 | * Solution to exercise 3 34 | */ 35 | // 3.1 36 | // |8|68|12|6|3|7|45|23| 37 | // 3.2 38 | // 2 4 5 5 5 5 5 5 39 | // 3.3 40 | // 5 5 5 5 5 5 5 5 41 | // 3.4 42 | // The program section puts odd numbers on the right side of 43 | // the array and even numbers on the left side of the array 44 | // when it print the even and odd numbers at the end 45 | public static void main(String[] args) 46 | { 47 | int[] arr = new int[8]; 48 | int i=0, k, num; 49 | Scanner input = new Scanner(System.in); 50 | k = arr.length - 1; 51 | while (i <= k) 52 | { 53 | num = input.nextInt(); 54 | if (num%2 == 0) 55 | { 56 | arr[i] = num;i++; 57 | } 58 | else 59 | { 60 | arr[k] = num; 61 | k--; 62 | } 63 | } 64 | System.out.println ("i= " + i + "k= " + k); 65 | } 66 | 67 | /** 68 | * Solution to exercise 4 69 | */ 70 | // 4.1 71 | // |5|9|12|14|16|18| 72 | // |9|12|14|16|18|20| 73 | // |12|14|16|18|20|40| 74 | // 4.2 75 | // The method checks that for each member the member to the right and below it is greater than 76 | // it if all the members represent it except 77 | // the lower right member the function returns true otherwise false 78 | }// end of class Exam2018Moad82 79 | -------------------------------------------------------------------------------- /Exam2018JavaAMoad82/testJavaA2018Bmoad82.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lironmiz/Computer-Science-in-Java/71abf905b948e24c02e2d3fc303e285e70a45dfa/Exam2018JavaAMoad82/testJavaA2018Bmoad82.pdf -------------------------------------------------------------------------------- /Exam2019JavaA83/Bus.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Bus.java 3 | * the class reprsents a Bus 4 | * Author: liron mizrhai 5 | */ 6 | public class Bus 7 | { 8 | public static final int MAX_WHEELS_IN_BUS = 10; 9 | public Wheel[] _wheels = new Wheel[MAX_WHEELS_IN_BUS]; 10 | public int _noOfWheels; 11 | /** 12 | * the method return true if wheel is added otherwise false 13 | * @param: Wheel wh 14 | * @return: boolean 15 | */ 16 | public boolean addWheel(Wheel wh) 17 | { 18 | if(_wheels[MAX_WHEELS_IN_BUS - 1] instanceof Wheel) 19 | { 20 | return false; 21 | } 22 | int numOfWheels = howMuchWheels(); 23 | int middleIndex = numOfWheels / 2; 24 | int finalIndex = numOfWheels - 1; 25 | for(int i = numOfWheels; i > middleIndex; i--) 26 | { 27 | _wheels[i] = _wheels[i - 1]; 28 | } 29 | _wheels[middleIndex] = wh; 30 | return true; 31 | }// end of method addWheel 32 | /** 33 | * the method return the num of wheels in the array of wheels 34 | * @param: None 35 | * @return: int 36 | */ 37 | private int howMuchWheels() 38 | { 39 | int count = 0; 40 | for(int i = 0; i < MAX_WHEELS_IN_BUS; i++) 41 | { 42 | if(_wheels[i] instanceof Wheel) 43 | { 44 | count++; 45 | } 46 | } 47 | return count; 48 | }// end of method howMuchWheel 49 | /** 50 | * the method return true if all the wheels is valid 51 | * @param: None 52 | * @return: boolean 53 | */ 54 | public boolean allVaild() 55 | { 56 | for(int i = 0; i < MAX_WHEELS_IN_BUS; i++) 57 | { 58 | if(_wheels[i] instanceof Wheel) 59 | { 60 | if(!_wheels[i].isValidCatNum(_wheels[i].getCatNum())) 61 | { 62 | return false; 63 | } 64 | } 65 | } 66 | return true; 67 | }// end of method allVaild 68 | /** 69 | * the method return true if the bus can drive 70 | * @param: None 71 | * @return: boolean 72 | */ 73 | public boolean canDrive() 74 | { 75 | int isEven = 0; 76 | boolean isCanDrive = true; 77 | for(int i = 0; i < MAX_WHEELS_IN_BUS; i++) 78 | { 79 | Wheel wheel = _wheels[i]; 80 | if( wheel instanceof Wheel) 81 | { 82 | isEven++; 83 | if(!(wheel.getIsOk() && wheel.isValidCatNum(wheel.getCatNum()))) 84 | { 85 | System.out.println(i); 86 | isCanDrive = false; 87 | } 88 | } 89 | } 90 | return isCanDrive && isEven % 2 == 0; 91 | }// end of method canDrive 92 | }// end of class Bus 93 | -------------------------------------------------------------------------------- /Exam2019JavaA83/Exam2019JavaA83.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Exam2019JavaA83.java 3 | * the class solutions to the test 4 | * Author: liron mizrhai 5 | */ 6 | public class Exam2019JavaA83 7 | { 8 | /** 9 | * the method return the original string of secret string 10 | * @param: String secret 11 | * @return: String 12 | */ 13 | public static String getOriginal(String secret) 14 | { 15 | String originalString = ""; 16 | for(int i = 0; i < secret.length(); i++) 17 | { 18 | char ch = secret.charAt(i); 19 | int intChar = (int) (ch - (i + 1)); 20 | ch = (char) intChar; 21 | originalString += ch; 22 | } 23 | return originalString; 24 | }// end of method gotOriginal 25 | 26 | // Ex3 27 | // Solution 1 -> | | | | |2|5|7|0|9|4| 28 | // Solution 2 -> the method put the num in the last indexs she need to 29 | // Solution 3-> |0|0|0|0|6|4|6|1|8|9| 30 | // Solution 4 -> she do add the two numbers and put in the arr3 31 | 32 | /** 33 | * Ex4 34 | * -3 -2 0 9 35 | * -1 0 5 12 36 | * 5 8 11 14 37 | * num = 5 38 | */ 39 | // Solution 1 -> true 40 | // Solution 2 -> the method return true if the array is sorted for low to high in all the rows and columns 41 | // Solution 3 -> 2 42 | // Solution 4 -> The method returns the number of occurrences of the number in the two-dimensional matrix, given that the test method returned true 43 | 44 | // res = 2 45 | // row = 3 46 | // col = -1 47 | // while( 3 < 3 && 0>=0) 48 | // 49 | }// end of class Exam2019JavaA83 50 | -------------------------------------------------------------------------------- /Exam2019JavaA83/Exam2019JavaA83.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lironmiz/Computer-Science-in-Java/71abf905b948e24c02e2d3fc303e285e70a45dfa/Exam2019JavaA83/Exam2019JavaA83.pdf -------------------------------------------------------------------------------- /Exam2019JavaA83/Wheel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Wheel.java 3 | * the class reprsents a Wheel 4 | * Author: liron mizrhai 5 | */ 6 | public class Wheel 7 | { 8 | public int _catNum; 9 | public boolean _isOk; 10 | /** 11 | * Constructor of the class Wheel 12 | * @param: None 13 | * @return: None 14 | */ 15 | public Wheel() 16 | { 17 | _catNum = 1234; 18 | _isOk = true; 19 | }// end of method Wheel 20 | /** 21 | * Constructor of the class Wheel 22 | * @param: int catNum, boolean isOk 23 | * @return: None 24 | */ 25 | public Wheel(int catNum, boolean isOk) 26 | { 27 | if(catNum > 0) 28 | { 29 | _catNum = catNum; 30 | } 31 | else 32 | { 33 | _catNum = 1234; 34 | } 35 | _isOk = isOk; 36 | }// end of method Wheel 37 | /** 38 | * copy Constructor of the class Wheel 39 | * @param: Wheel other 40 | * @return: None 41 | */ 42 | public Wheel(Wheel other) 43 | { 44 | _catNum = other._catNum; 45 | _isOk = other._isOk; 46 | }// end of method Wheel 47 | /** 48 | * method return true if catNum is valid otherwise false 49 | * @param: int catNum 50 | * @return: boolean 51 | */ 52 | public boolean isValidCatNum(int catNum) 53 | { 54 | if(catNum > 0 && catNum % 3 == 0 && catNum % 10 == 7) 55 | { 56 | return true; 57 | } 58 | return false; 59 | }// end of method isValidCatNum 60 | /** 61 | * method return the cat num of the Wheel 62 | * @param: None 63 | * @return: int 64 | */ 65 | public int getCatNum() 66 | { 67 | return _catNum; 68 | }// end of method getCatNum 69 | 70 | /** 71 | * method return if the wheel is fine 72 | * @param: None 73 | * @return: boolean 74 | */ 75 | public boolean getIsOk() 76 | { 77 | return _isOk; 78 | }// end of method getIsOk 79 | /** 80 | * method set the catNum of the wheel 81 | * @param: int catNum 82 | * @return: None 83 | */ 84 | public void setCatNum(int catNum) 85 | { 86 | _catNum = catNum; 87 | }// end of method setCatNum 88 | 89 | /** 90 | * method set the catNum of the wheel 91 | * @param: booelan isOk 92 | * @return: None 93 | */ 94 | public void setIsOk(boolean isOk) 95 | { 96 | _isOk = isOk; 97 | }// end of method setCatNum 98 | }// end of class Wheel 99 | -------------------------------------------------------------------------------- /Exam2021JavaA/Airport.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Airport.java 3 | * the class reprsents airport 4 | * Author: liron mizrhai 5 | */ 6 | public class Airport 7 | { 8 | public static final int MAX_FLIGHTS = 200; 9 | 10 | public Flight[] _flightsSchedule; 11 | public int _noOfFlight; 12 | 13 | /** 14 | * method return the first flight from given place 15 | * @param: String place 16 | * @return: Time 17 | */ 18 | public Time firstFlightFromPlace(String place) 19 | { 20 | Flight[] flightsFromPlace = new Flight[MAX_FLIGHTS]; 21 | int noOfFlightFromPlace = 0; 22 | int index = 0; 23 | for(int i = 0; i < _noOfFlight; i++) 24 | { 25 | if(_flightsSchedule[i].getOrigin().equals(place)) 26 | { 27 | flightsFromPlace[index] = _flightsSchedule[i]; 28 | index++; 29 | } 30 | } 31 | if(flightsFromPlace.length == 1) 32 | { 33 | flightsFromPlace[0].getDepatureTime(); 34 | } 35 | else if(flightsFromPlace.length > 1) 36 | { 37 | Time TimeOfFirstFlightFromPlace = flightsFromPlace[0].getDepatureTime(); 38 | for(int i = 1; i < noOfFlightFromPlace; i++) 39 | { 40 | if(flightsFromPlace[i].getDepatureTime().before(TimeOfFirstFlightFromPlace)) 41 | { 42 | TimeOfFirstFlightFromPlace = flightsFromPlace[i].getDepatureTime(); 43 | } 44 | } 45 | if(TimeOfFirstFlightFromPlace != null) 46 | { 47 | return TimeOfFirstFlightFromPlace; 48 | } 49 | else 50 | { 51 | return null; 52 | } 53 | } 54 | return null; 55 | }// end of method firstFlightFromPlace 56 | /** 57 | * method return the most popular destination 58 | * @param: None 59 | * @return String 60 | * 61 | */ 62 | public String mostPopularDestination() 63 | { 64 | if(_noOfFlight == 0) 65 | { 66 | return null; 67 | } 68 | int popCount = 0; 69 | int count = 0; 70 | 71 | String popDes = null; 72 | String tempDes; 73 | for(int i = 0; i < _noOfFlight; i++) 74 | { 75 | tempDes = _flightsSchedule[i].getDestination(); 76 | count = 0; 77 | for(int j = 0; j < _noOfFlight; j++) 78 | { 79 | if(tempDes.equals(_flightsSchedule[j].getDestination())) 80 | { 81 | count++; 82 | } 83 | } 84 | if(count > popCount) 85 | { 86 | popCount = count; 87 | popDes = tempDes; 88 | } 89 | } 90 | return popDes; 91 | }// end of method mostPopularDestination 92 | }// end of class Airport 93 | -------------------------------------------------------------------------------- /Exam2021JavaA/ExamJavaA2021.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Exam2021AavaA.java 3 | * the class have solutions to the test 4 | * Author: liron mizrhai 5 | */ 6 | public class ExamJavaA2021 7 | { 8 | /** 9 | * solution to exercise 2 10 | * method return true if given num is specialNumber otherwise false 11 | * @param: int 12 | * @return: boolean 13 | */ 14 | public static boolean specialNumber(int num) 15 | { 16 | int firstSum = 0; 17 | int secondSum = 0; 18 | int index = 0; 19 | if(num < 10) 20 | { 21 | return true; 22 | } 23 | while(num > 0) 24 | { 25 | int lastDigit = num % 10; 26 | if(index % 2 == 0) 27 | { 28 | firstSum += lastDigit; 29 | } 30 | else 31 | { 32 | secondSum += lastDigit; 33 | } 34 | num /= 10; 35 | index++; 36 | } 37 | return firstSum == secondSum; 38 | }// end of method specialNumber 39 | /** 40 | * solution to exercise 3 41 | * 1. row = 1 col = 3 42 | * solution to exercise 4 43 | * false 44 | * solution to exercise 5 45 | * false 46 | * solution to exercise 6 47 | * 4 none of the enswer are correct 48 | * solution to exercise 7 49 | * false 50 | * solution to exercise 8 51 | * 'c' 52 | * solution to exercise 9 53 | * 'n' 54 | * solution to exercise 10 55 | * "medcne" 56 | * solution to exercise 11 57 | * 'f' 58 | * solution to exercise 12 59 | * "cdeeilimn" 60 | * solution to exercise 13 61 | * "nmiieedc 62 | */ 63 | }// end of class ExamJavaA2021 64 | -------------------------------------------------------------------------------- /Exam2021JavaA/Flight.java: -------------------------------------------------------------------------------- 1 | /** 2 | * flight.java 3 | * the class reprsents flight 4 | * Author: liron mizrhai 5 | */ 6 | public class Flight 7 | { 8 | public static final int MAX_CAPACITY = 250; 9 | 10 | private String _origin; 11 | private String _destination; 12 | private Time _depatureTime; 13 | private int _flightDuration; 14 | private int _noOfPassengers; 15 | private boolean _ifFull; 16 | /** 17 | * constructor of the class Flight 18 | * @param: String origin, String des, int hour, int minute, int flightDuration, int passangerNumber 19 | * @return: None 20 | */ 21 | public Flight(String origin, String des, int hour, int minute, int flightDuration, int passangerNumber) 22 | { 23 | _origin = origin; 24 | _destination = des; 25 | _depatureTime = new Time(hour, minute); 26 | _flightDuration = flightDuration; 27 | _noOfPassengers = passangerNumber; 28 | if(passangerNumber < 250) 29 | { 30 | _ifFull = false; 31 | } 32 | else 33 | { 34 | _ifFull = true; 35 | } 36 | }// end of method Flight 37 | /** 38 | * copy constructor of the class Flight 39 | * @param: Time other 40 | * @return: None 41 | */ 42 | public Flight(Flight other) 43 | { 44 | _origin = other._origin; 45 | _destination = other._destination; 46 | _depatureTime = new Time(other._depatureTime); 47 | _noOfPassengers = other._noOfPassengers; 48 | if(other._noOfPassengers < 250) 49 | { 50 | _ifFull = false; 51 | } 52 | else 53 | { 54 | _ifFull = true; 55 | } 56 | }// end of method Flight 57 | // private Time _depatureTime; 58 | public void setDepatureTime(Time depatureTimeToSet) 59 | { 60 | _depatureTime = new Time(depatureTimeToSet); 61 | } 62 | /** 63 | * method return the depatrueTime 64 | * @param: None 65 | * @return: Time 66 | */ 67 | public Time getDepatureTime() 68 | { 69 | return _depatureTime; 70 | }// end of method getDepatureTime 71 | /** 72 | * return the arrival time of the flight 73 | * @param: None 74 | * @return: Time 75 | */ 76 | public Time getArrivalTime() 77 | { 78 | return _depatureTime.addMinutes(_flightDuration); 79 | }// end of method getArrivalTime 80 | /** 81 | * method return the origin of the flight 82 | * @param: None 83 | * @return: String 84 | */ 85 | public String getOrigin() 86 | { 87 | return _origin; 88 | }// end of method getOrigin 89 | /** 90 | * method return the destination of the flight 91 | * @param: None 92 | * @return: String 93 | */ 94 | public String getDestination() 95 | { 96 | return _destination; 97 | }// end of method getDestination 98 | /** 99 | * method return true if numbers of passengers is valid otherwise false 100 | * @param: int 101 | * @return: boolean 102 | */ 103 | public boolean addPassengers(int num) 104 | { 105 | if(_ifFull) 106 | { 107 | return false; 108 | } 109 | int newPassengersCount = _noOfPassengers + num; 110 | if(newPassengersCount > MAX_CAPACITY) 111 | { 112 | return false; 113 | } 114 | else if (newPassengersCount == MAX_CAPACITY) 115 | { 116 | _ifFull = true; 117 | return true; 118 | } 119 | return true; 120 | }// end of method addPassengers 121 | }// end of class Flight 122 | -------------------------------------------------------------------------------- /Exam2021JavaA/Time.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Time.java 3 | * the class reprsents time 4 | * Author: liron mizrhai 5 | */ 6 | public class Time 7 | { 8 | public static int _hour; 9 | public static int _minute; 10 | /** 11 | * constructor of the class Time 12 | * @param: int h, int m 13 | * @return: None 14 | */ 15 | public Time(int h, int m) 16 | { 17 | if(h < 0 && h > 23 && m < 0 && m > 59 ) 18 | { 19 | _hour = h; 20 | _minute = m; 21 | } 22 | else 23 | { 24 | _hour = 0; 25 | _minute = 0; 26 | } 27 | }// end of method Time 28 | /** 29 | * copy constructor of the class Time 30 | * @param: Time t 31 | * @return: None 32 | */ 33 | public Time(Time t) 34 | { 35 | _hour = t._hour; 36 | _minute = t._minute; 37 | }// end of methed Time 38 | /** 39 | * method return the hour 40 | * @param: None 41 | * @return: int 42 | */ 43 | public int getHour() 44 | { 45 | return _hour; 46 | }// end of method getHour 47 | /** 48 | * method return the minute 49 | * @param: None 50 | * @return: int 51 | */ 52 | public int getMinute() 53 | { 54 | return _minute; 55 | }// end of method getMinute 56 | /** 57 | * method return time object after add to the time given paramter 58 | * @param: int mintueToAdd 59 | * @return: Time 60 | */ 61 | public Time addMinutes(int minuteToAdd) 62 | { 63 | int addHour = minuteToAdd / 60; 64 | int m = minuteToAdd - addHour * 60; 65 | if( _hour + addHour > 23 || _minute + m > 59) 66 | { 67 | return new Time((_hour + addHour) % 23, (_minute + m) % 59); 68 | } 69 | else 70 | { 71 | return new Time(_hour + addHour, _minute + m); 72 | } 73 | }// end of method addMinutes 74 | /** 75 | * method return true if given time equals to this 76 | * @param: Time other 77 | * @return: boolean 78 | */ 79 | public boolean equals(Time other) 80 | { 81 | if(_hour == other._hour && _minute == other._minute ) 82 | { 83 | return true; 84 | } 85 | else 86 | { 87 | return false; 88 | } 89 | }// end of method equals 90 | /** 91 | * method return true if this is before given paramter 92 | * @param: Time other; 93 | * @return: boolean; 94 | */ 95 | public boolean before(Time other) 96 | { 97 | if(_hour < other._hour) 98 | { 99 | return true; 100 | } 101 | else if(_hour == other._hour && _minute < other._minute) 102 | { 103 | return true; 104 | } 105 | return false; 106 | }// end of method before 107 | /** 108 | * method return true if this is after given paramter 109 | * @param: Time other 110 | * @return: boolean 111 | */ 112 | public boolean after(Time other) 113 | { 114 | return other.before(this); 115 | }// end of method after 116 | /** 117 | * method return string represent the object 118 | * @param: None 119 | * @return: String 120 | */ 121 | public String toString() 122 | { 123 | return _hour + ":" + _minute; 124 | }// end of method toString 125 | }// end of class Time 126 | -------------------------------------------------------------------------------- /Exam2021JavaA/javaA2021.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lironmiz/Computer-Science-in-Java/71abf905b948e24c02e2d3fc303e285e70a45dfa/Exam2021JavaA/javaA2021.pdf -------------------------------------------------------------------------------- /Exam2022BJuly91/A.java: -------------------------------------------------------------------------------- 1 | /** 2 | * A.java 3 | * the class represents a A 4 | * Author: liron mizrhai 5 | */ 6 | public abstract class A 7 | { 8 | protected int _x; 9 | 10 | public A() 11 | { 12 | _x = 1; 13 | }// end of method A 14 | 15 | public abstract int f(int x); 16 | 17 | public void f(A a) 18 | { 19 | _x = a._x; 20 | }// end of method f 21 | }// end of abstract class A 22 | -------------------------------------------------------------------------------- /Exam2022BJuly91/B.java: -------------------------------------------------------------------------------- 1 | /** 2 | * B.java 3 | * the class represents a B 4 | * Author: liron mizrhai 5 | */ 6 | public class B extends A 7 | { 8 | public B() 9 | { 10 | super(); 11 | }// end of method B 12 | 13 | public B(int val) 14 | { 15 | _x = f(val); 16 | }// end of method B 17 | 18 | public int f(int x) 19 | { 20 | return _x + x; 21 | }// end of method f 22 | 23 | public void f(B b) 24 | { 25 | _x = _x * b._x; 26 | }// end of method f 27 | }// end of class B 28 | -------------------------------------------------------------------------------- /Exam2022BJuly91/D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * D.java 3 | * the class represents a D 4 | * Author: liron mizrhai 5 | */ 6 | public class D extends B 7 | { 8 | public D(int val) 9 | { 10 | _x = val - _x; 11 | }// end of method D 12 | 13 | public void f(A a) 14 | { 15 | _x = _x + a._x + 1; 16 | }// end of method f 17 | 18 | public void f(D d) 19 | { 20 | _x = d._x -1; 21 | }// end of method f 22 | }// end of class D 23 | -------------------------------------------------------------------------------- /Exam2022BJuly91/Exam2022BJuly91.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // Exam in July 2022B (91) 3 | // Semester 2022B 4 | // Solutions to the test 5 | // Author: liron mizrahi 6 | //******************************************************* 7 | public class Exam2022BJuly91 8 | { 9 | /** 10 | * Ex1 11 | * static recursive method thet return the min pay that amir need to pay to go from first 12 | * station to the last and also the method print all the possible traces from the first to last station 13 | * in this format: 14 | * for example if the arr is [2][4][8][3][10][1][12][3][2] 15 | * @param int[] stations, int step1, int step2, int limit 16 | * @return int 17 | */ 18 | public static int cheapRt(int[] stations, int step1, int step2, int limit) 19 | { 20 | // bases cases 21 | if(stations.length - 1 == 0) 22 | { 23 | System.out.print(0 + " =" + stations[0]); 24 | return stations[1]; 25 | } 26 | else if(step1 >= stations.length && step2 >= stations.length) 27 | { 28 | return Integer.MAX_VALUE; 29 | } 30 | // call to the Aulliexsery method 31 | return cheapRt(stations, step1, step2, limit, 0, 0, " "); 32 | }// end of method cheapRt 33 | // Aulliexsery method 34 | private static int cheapRt(int[] stations, int step1, int step2, int limit, int sum, int index,String str) 35 | { 36 | if(index > stations.length - 1 || limit < 0) 37 | { 38 | return Integer.MAX_VALUE; 39 | } 40 | if(index == stations.length - 1 && limit >= 0) 41 | { 42 | sum += stations[index]; 43 | str += index + " "; 44 | System.out.println(str + "=" + sum); 45 | return sum; 46 | } 47 | int firstWay = cheapRt(stations, step1, step2, limit, sum + stations[index], index + step1,str + index + " "); 48 | int secondWay = cheapRt(stations, step1, step2, limit - 1, sum + stations[index], index + step2, str + index + " "); 49 | return Math.min(firstWay, secondWay); 50 | }// end of method cheapRt 51 | /** 52 | * Explanation of the code: 53 | * I used a recursive pattern of testing using a helper method 54 | * to keep track of the indexes and building the requested string when 55 | * I checked two conditions one condition if I went beyond the limits 56 | * of the array or we used more than our quota for the second step when 57 | * in this situation I returned Integer.MAX_VALUE and in the second 58 | * condition I checked if I reached the end of the array I advanced the 59 | * amount Accordingly, I printed the requested strings while returning 60 | * the amount, when at the end of the method I return the minimum 61 | * number among all the options while using the loading 62 | */ 63 | /** 64 | * Ex2 65 | * the method need to fine 3 numbers in the arr thet there product art the max product of 3 numbers in the arr 66 | * the method also need to print the 3 numbers 67 | * for example: 68 | * arr -> [-4][1][-8][9][6] 69 | * the method will print -4 -8 9 70 | * and return -4*-8*9 = 288 71 | * @param int[] arr 72 | * @return int 73 | * Time Complexity: O(n) n = len of the arr 74 | * Space Complexity O(1) the space is fixed and not dependent on the size of the arr 75 | */ 76 | public static int findTriplet(int[] arr) 77 | { 78 | int max1 = Integer.MIN_VALUE, max2 = Integer.MIN_VALUE, max3 = Integer.MIN_VALUE, min1 = Integer.MAX_VALUE, min2 = Integer.MAX_VALUE; 79 | for(int n : arr) 80 | { 81 | if ( n > max1) 82 | { 83 | max3 = max2; 84 | max2 = max1; 85 | max1 = n; 86 | } 87 | else if( n > max2) 88 | { 89 | max3 = max2; 90 | max2 = n; 91 | } 92 | else if( n > max3) 93 | { 94 | max3 = n; 95 | } 96 | if (n < 1) 97 | { 98 | min2 = min1; 99 | min1 = n; 100 | } 101 | else if( n < min2) 102 | { 103 | min2 = n; 104 | } 105 | } 106 | if( max1*max2*max3 > max1*min1*min2) 107 | { 108 | System.out.println(max1 + " " + max2 + " " + max3); 109 | return max1*max2*max3; 110 | } 111 | else 112 | { 113 | System.out.println(max1 + " " + min1 + " " + min2); 114 | return max1*min1*min2; 115 | } 116 | }// end of methdo findTriplet 117 | /** 118 | * Explanation of the code: 119 | * we loop in the arr and fine the free largest 120 | * number and the two smallest and return the bigger product of the two options 121 | */ 122 | 123 | /** 124 | * Ex3 125 | * Section A: what f method will return after the call BinaryTree.f(root, 30) 126 | * Enswer : true 127 | * Section B: what f method do? 128 | * Enswer: the method return true if the tree is not empty and num exists in one of the nodes 129 | * if not it will return false 130 | * Section C: what secret method will print after the call BinaryTree.secret(root, 25) 131 | * Enswer: the method will return 0 132 | * Section D: what will return what method after the call BinaryTree.what(root, 10) 133 | * Enswer: 50 134 | * Section E: what what method do? 135 | * Enswer: the what method return the sum of the Node that own of there sons is the same value as num 136 | * if there not like this or the tree is empty the method will return the value 0 137 | * 138 | */ 139 | /** 140 | * Ex4 141 | * Section A: 142 | * a = new B(m); // m type is int 143 | * what will need to be the value of m that after the above line make the proporty of _x of a equal to 25? 144 | * Enswer: 24 145 | * Section B: 146 | * a = new B(3); // _x = 4 147 | * int k = a.f(a.f(6)); 148 | * what the value of k will be after the above two lines? 149 | * Enswer: 14 150 | * Section C: 151 | * b = new D(5); 152 | * int k = b.f(b.f(4)); 153 | * Enswer: 12 154 | * Section D: 155 | * a = new D(8); // 7 156 | * b = new B(6); // 7 157 | * b.f(a); 158 | * what will be the value _x of the object b after the above 3 lines 159 | * Enswer: 7 160 | * Section E: 161 | * D d = new D(m) m of type int 162 | * a = new D(2); 163 | * ((A)d).f(a); 164 | * what need to be the value of for _x after the above 3 lines wil be 5 165 | * Enswer 4 166 | * Ex5 167 | * Section A 168 | * if we call the secret method on the list = 8 -> 2 -> 5 -> 4 -> null 169 | * how the list will look like 170 | * Enswer: 171 | * list = 4->5->2->8-> null 172 | * Section B 173 | * how need to look a list that if we will call the secret method upon we wil get the list 174 | * list = 7->7->7->7->null 175 | * Enswer: 7->7->7->7->null 176 | * Section C 177 | * if we will call the what method on the list 178 | * list = 4->5->->2->9->7->2->1->4-> null what value the method will give? 179 | * Enswer: false 180 | * Section D: 181 | * what is the minimal changes that we need to do in list from Section c for if we call what method on this list if will print true 182 | * Enswer: 183 | * the 5 we will change to 1 184 | * the 9 we will change to 7 185 | * Section E: 186 | * if we will call to what method on list with odd numbers if she will do the same thing like we will call 187 | * to what method on even numbers? if no write why? and if yes give example 188 | * to a list with even len and example to a list with odd len and tell what is the diffrent between them. 189 | * Enswer: 190 | * Palindrome can be with even size and odd size the meaning of the method will not change!!. 191 | * 192 | */ 193 | }// end of class Exam2022BJuly91 194 | -------------------------------------------------------------------------------- /Exam2022BJuly91/Exam2022BJuly91Driver.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // tester for the class 3 | // Semester 2022B 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class Exam2022BJuly91Driver 7 | { 8 | public static void main(String[] args) 9 | { 10 | Exam2022BJuly91 classObject = new Exam2022BJuly91(); 11 | // Ex1 12 | int[] stations = new int[9]; 13 | stations[0] = 2; 14 | stations[1] = 4; 15 | stations[2] = 8; 16 | stations[3] = 3; 17 | stations[4] = 10; 18 | stations[5] = 1; 19 | stations[6] = 12; 20 | stations[7] = 3; 21 | stations[8] = 2; 22 | int step1= 3; 23 | int step2 = 2; 24 | int limit = 4; 25 | System.out.print(classObject.cheapRt(stations,3, 2, 4)); // output -> 26 | // 0 2 4 6 8 =34 27 | // 0 2 5 8 =13 28 | // 0 3 5 8 =8 29 | // 0 3 6 8 =19 30 | // System.out.print(classObject.cheapRt(stations, 3, 6, 4)); // Integer.MAX_VALUE 31 | // Ex2 32 | int[] arr = new int[5]; 33 | arr[0] = -4; 34 | arr[1] = 1; 35 | arr[2] = -8; 36 | arr[3] = 9; 37 | arr[4] = 6; 38 | System.out.print(classObject.findTriplet(arr)); 39 | // output 40 | // -4 -8 9 41 | // 288 42 | // tree 43 | Node root = new Node(60); 44 | root._rightSon = new Node(40); 45 | root._leftSon = new Node(20); 46 | root._leftSon._leftSon = new Node(10); 47 | root._leftSon._leftSon._leftSon = new Node(15); 48 | root._leftSon._rightSon = new Node(30); 49 | root._leftSon._rightSon._leftSon = new Node(10); 50 | root._leftSon._rightSon._leftSon._rightSon = new Node(30); 51 | root._leftSon._rightSon._rightSon = new Node(5); 52 | // Ex3 Section A 53 | System.out.println(root.f(root, 30));// true 54 | // Ex3 Section C 55 | System.out.println(root.secret(root,25));// 0 56 | // Ex3 Section D 57 | System.out.println(root.what(root, 10)); // 50 58 | // Ex4 59 | A a; 60 | B b; 61 | // Section A 62 | a = new B(24); 63 | System.out.println(a._x); // 25 64 | // Section B 65 | a = new B(3); 66 | int k = a.f(a.f(6)); 67 | System.out.println(k); // 14 68 | // Section C 69 | b = new D(5); 70 | k = b.f(b.f(4)); 71 | System.out.println(k); // 12 72 | // Section D 73 | a = new D(8); 74 | b = new B(6); 75 | b.f(a); 76 | System.out.println(b._x); // 7 77 | // Section E: 78 | D d = new D(4); 79 | a = new D(2); 80 | ((A)d).f(a); 81 | System.out.println(d._x); // 5 82 | //Ex5 83 | // first list 84 | IntNode node4 = new IntNode(4, null); 85 | IntNode node3 = new IntNode(5, node4); 86 | IntNode node2 = new IntNode(2, node3); 87 | IntNode node1 = new IntNode(8, node2); 88 | IntList list = new IntList(); 89 | list.secret(); // list = 4->5->2->8 90 | // second list 91 | IntNode list2Node8 = new IntNode(4, null); 92 | IntNode list2Node7 = new IntNode(1, list2Node8); 93 | IntNode list2Node6 = new IntNode(2, list2Node7); 94 | IntNode list2Node5 = new IntNode(7, list2Node6); 95 | IntNode list2Node4 = new IntNode(9, list2Node5); 96 | IntNode list2Node3 = new IntNode(2, list2Node4); 97 | IntNode list2Node2 = new IntNode(5, list2Node3); 98 | IntNode list2Node1 = new IntNode(4, list2Node2); 99 | IntList list2 = new IntList(); 100 | System.out.println(list2.what()); // false 101 | }// end of method main 102 | }// end of class Exam2022BJuly91Driver 103 | -------------------------------------------------------------------------------- /Exam2022BJuly91/ExamJava2022BJuly91.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lironmiz/Computer-Science-in-Java/71abf905b948e24c02e2d3fc303e285e70a45dfa/Exam2022BJuly91/ExamJava2022BJuly91.pdf -------------------------------------------------------------------------------- /Exam2022BJuly91/IntList.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // IntList.java 3 | // the class reprsents IntList 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class IntList 7 | { 8 | private IntNode _head; 9 | 10 | public void IntList(IntNode node) 11 | { 12 | _head = node; 13 | }// end of method IntList 14 | 15 | public void secret() 16 | { 17 | IntNode p = null, ptr = _head, temp; 18 | while (ptr != null) 19 | { 20 | temp = ptr.getNext(); 21 | ptr.setNext(p); 22 | p = ptr; 23 | ptr = temp; 24 | } 25 | _head = p; 26 | }// end of method secret 27 | 28 | public boolean what() 29 | { 30 | boolean ans = true; 31 | IntNode p1 = _head, p2 = _head; 32 | IntNode m = null; 33 | if (_head == null) 34 | { 35 | return true; 36 | } 37 | while(p2 != null) 38 | { 39 | p2 = p2.getNext(); 40 | if(p2!= null) 41 | { 42 | p2 = p2.getNext(); 43 | } 44 | if(p2 != null) 45 | { 46 | p1 = p1.getNext(); 47 | } 48 | } 49 | m = p1; 50 | //IntList part = new IntList(m.getNext()); 51 | //part.secret(); 52 | //m.setNext(part._head); 53 | p1 = _head; 54 | //p2 = m.getNext(); 55 | while(ans == true && p2 != null) 56 | { 57 | if(p1.getValue() != p2.getValue()) 58 | { 59 | ans = false; 60 | } 61 | p1 = p1.getNext(); 62 | p2 = p2.getNext(); 63 | } 64 | //part.secret(); 65 | //m.setNext(part._head); 66 | return ans; 67 | }// end of method what 68 | }// end of class IntList 69 | -------------------------------------------------------------------------------- /Exam2022BJuly91/IntNode.java: -------------------------------------------------------------------------------- 1 | 2 | //******************************************************* 3 | // IntNode.java 4 | // the class reprsents IntNode 5 | // Author: liron mizrahi 6 | //******************************************************* 7 | public class IntNode 8 | { 9 | private int _value; 10 | private IntNode _next; 11 | 12 | public IntNode(int val, IntNode n) 13 | { 14 | _value = val; 15 | _next = n; 16 | }// end of method IntNode 17 | 18 | public IntNode getNext() 19 | { 20 | return _next; 21 | }// end of method getNext 22 | 23 | public void setNext(IntNode node) 24 | { 25 | _next = node; 26 | }// end of method setNext 27 | 28 | public int getValue() 29 | { 30 | return _value; 31 | }// end of method getValue 32 | 33 | public void setValue(int v) 34 | { 35 | _value = v; 36 | }// end of method setValue 37 | }// end of class IntNode 38 | -------------------------------------------------------------------------------- /Exam2022BJuly91/Node.java: -------------------------------------------------------------------------------- 1 | 2 | //******************************************************* 3 | // Node.java 4 | // the class reprsents Node 5 | // Author: liron mizrahi 6 | //******************************************************* 7 | public class Node 8 | { 9 | public int _number; 10 | public Node _leftSon, _rightSon; 11 | 12 | public Node(int number) 13 | { 14 | _number = number; 15 | _leftSon = null; 16 | _rightSon = null; 17 | }// end of mehtod Node 18 | 19 | public int getNumber() 20 | { 21 | return _number; 22 | }// end of method getNumber 23 | 24 | public Node getLeftSon() 25 | { 26 | return _leftSon; 27 | }// end of method getLeftSon 28 | 29 | public Node getRightSon() 30 | { 31 | return _rightSon; 32 | }// end of method getRightSon 33 | 34 | public static boolean f(Node root, int num) 35 | { 36 | if(root == null) 37 | { 38 | return false; 39 | } 40 | if(root.getNumber() == num) 41 | { 42 | return true; 43 | } 44 | return f(root.getLeftSon(), num) || f(root.getRightSon(), num); 45 | }// end of method f 46 | 47 | public static int what(Node root, int x) 48 | { 49 | if(f(root, x)) 50 | { 51 | return secret(root, x); 52 | } 53 | return 0; 54 | }// end of method what 55 | 56 | public static int secret(Node root, int x) 57 | { 58 | if(root == null) 59 | { 60 | return 0; 61 | } 62 | if((root.getLeftSon() != null && (root.getLeftSon()).getNumber() == x) || (root.getRightSon() != null && (root.getRightSon()).getNumber() == x)) 63 | { 64 | return root.getNumber() + secret(root.getLeftSon(), x) + secret(root.getRightSon(), x); 65 | } 66 | return secret(root.getLeftSon(), x) + secret(root.getRightSon(), x); 67 | }// end of method secret 68 | }// end of class Node 69 | -------------------------------------------------------------------------------- /Exam2022Bjune86/A.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // A.java 3 | // the class reprsents A 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class A 7 | { 8 | private int _num; 9 | 10 | public A(int num) 11 | { 12 | _num = num; 13 | }// end of method A 14 | 15 | public int getNum() 16 | { 17 | return _num; 18 | }// end of method getNum 19 | 20 | public void setNum(int num) 21 | { 22 | _num = num; 23 | }// end of method setNum 24 | 25 | public int f(A a) 26 | { 27 | System.out.print("in A "); 28 | _num = a._num; 29 | return _num; 30 | }// end of method f 31 | }// end of class A 32 | -------------------------------------------------------------------------------- /Exam2022Bjune86/B.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // B.java 3 | // the class reprsents B 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class B extends A 7 | { 8 | public B(int n) 9 | { 10 | super (n); 11 | }// end of method B 12 | 13 | public int f(B b) 14 | { 15 | System.out.print ("in B "); 16 | setNum(b.getNum() * 2); 17 | return getNum(); 18 | }// end of method f 19 | }// end of class B 20 | -------------------------------------------------------------------------------- /Exam2022Bjune86/C.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // C.java 3 | // the class reprsents C 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class C extends B 7 | { 8 | public C(int n) 9 | { 10 | super (n); 11 | }// end of method C 12 | 13 | public int f(A a) 14 | { 15 | System.out.print("in C "); 16 | if( a instanceof C) 17 | { 18 | return a.getNum() + 1; 19 | } 20 | return super.f(a); 21 | }// end of method f 22 | }// end of class C 23 | -------------------------------------------------------------------------------- /Exam2022Bjune86/Exam2022Bjune86Driver.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // Exam2022Bjune86Driver.java 3 | // tester for the exam 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class Exam2022Bjune86Driver 7 | { 8 | public static void main(String[] args) 9 | { 10 | Exam2022Bjune86 classObject = new Exam2022Bjune86(); 11 | int[][] mat = { {12,22,23,54,11}, {43,35,21,20,30}, {34,23,43,22,30}, {25,31,2,20,34}, {10,22,10,11,10}, {40,13,3,1,23} }; 12 | System.out.println(classObject.maxPath(mat)); 13 | int[] arr = new int[9]; 14 | arr[0] = 35; 15 | arr[1] = 17; 16 | arr[2] = 13; 17 | arr[3] = 252; 18 | arr[4] = 4; 19 | arr[5] = 128; 20 | arr[6] = 7; 21 | arr[7] = 3; 22 | arr[8] = 81; 23 | classObject.sortmod(arr, 10); 24 | for(int i = 0; i < arr.length; i++) 25 | { 26 | System.out.println(arr[i]); 27 | } 28 | // first tree 29 | Node root = new Node(20); 30 | root._leftSon = new Node(30); 31 | root._rightSon = new Node(5); 32 | root._rightSon._leftSon = new Node(50); 33 | root._rightSon._rightSon = new Node(10); 34 | root._rightSon._rightSon._leftSon = new Node(40); 35 | System.out.println(root.what(root)); 36 | // second tree 37 | Node root1 = new Node(2); 38 | root1._leftSon = new Node(15); 39 | root1._rightSon = new Node(4); 40 | root1._rightSon._leftSon = new Node(30); 41 | root1._rightSon._rightSon = new Node(7); 42 | System.out.println(root.what(root1)); 43 | // three tree 44 | Node root2 = new Node(42); 45 | root2._leftSon = new Node(24); 46 | root2._leftSon._rightSon = new Node(45); 47 | root2._leftSon._leftSon = new Node(10); 48 | root2._leftSon._leftSon._leftSon = new Node(5); 49 | root2._rightSon = new Node(41); 50 | root2._rightSon._rightSon = new Node(6); 51 | root2._rightSon._leftSon = new Node(38); 52 | root2._rightSon._leftSon._rightSon = new Node(11); 53 | System.out.println(root.what1(root2)); 54 | A ab = new B(2); 55 | B bb = new B(3); 56 | A ac = new C(4); 57 | B bc = new C(5); 58 | System.out.println(ab.f(bb)); 59 | System.out.println(ab.f((A)bb)); 60 | System.out.println(bb.f(ab)); 61 | System.out.println(bb.f(bc)); 62 | System.out.println(ac.f(bc)); 63 | System.out.println(ac.f(bb)); 64 | System.out.println(bc.f(ab)); 65 | System.out.println(bc.f(bb)); 66 | System.out.println(bc.f((C)ab)); 67 | IntNode node12 = new IntNode(0,null); 68 | IntNode node11 = new IntNode(0,node12); 69 | IntNode node10 = new IntNode(1, node11); 70 | IntNode node9 = new IntNode(1, node10); 71 | IntNode node8 = new IntNode(1, node9); 72 | IntNode node7 = new IntNode(1, node8); 73 | IntNode node6 = new IntNode(0, node7); 74 | IntNode node5 = new IntNode(1, node6); 75 | IntNode node4 = new IntNode(1, node5); 76 | IntNode node3 = new IntNode(0, node4); 77 | IntNode node2 = new IntNode(1, node3); 78 | IntNode node1 = new IntNode(1, node2); 79 | IntList list = new IntList(); 80 | list.setHead(node1); 81 | System.out.println(list.what(0)); 82 | }// end of method main 83 | }// end of class Exam2022Bjune86Driver 84 | -------------------------------------------------------------------------------- /Exam2022Bjune86/ExamJava2022BJune86.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lironmiz/Computer-Science-in-Java/71abf905b948e24c02e2d3fc303e285e70a45dfa/Exam2022Bjune86/ExamJava2022BJune86.pdf -------------------------------------------------------------------------------- /Exam2022Bjune86/IntLIst.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // IntList.java 3 | // the class reprsents IntList 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class IntList 7 | { 8 | private IntNode _head; 9 | 10 | public void IntList() 11 | { 12 | _head = null; 13 | }// end of method IntList 14 | 15 | public void setHead(IntNode node) 16 | { 17 | _head = node; 18 | }// end of method setHead 19 | 20 | public int what(int k) 21 | { 22 | int m = 0, f = 0, b = 0, s = 0; 23 | IntNode fp = _head, bp = _head; 24 | while( fp != null) 25 | { 26 | if(fp.getValue() == 0) 27 | { 28 | s++; 29 | if(s > k) 30 | { 31 | while(bp.getValue() != 0) 32 | { 33 | b++; 34 | bp = bp.getNext(); 35 | } 36 | b++; 37 | bp = bp.getNext(); 38 | s--; 39 | } 40 | } 41 | if(f - b + 1 > m) 42 | { 43 | m = f - b + 1; 44 | } 45 | f++; 46 | fp = fp.getNext(); 47 | } 48 | return m; 49 | }// end of method what 50 | }// end of class IntList 51 | -------------------------------------------------------------------------------- /Exam2022Bjune86/IntNode.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // IntNode.java 3 | // the class reprsents IntNode 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class IntNode 7 | { 8 | private int _value; 9 | private IntNode _next; 10 | 11 | public IntNode(int val, IntNode n) 12 | { 13 | _value = val; 14 | _next = n; 15 | }// end of method IntNode 16 | 17 | public IntNode getNext() 18 | { 19 | return _next; 20 | }// end of method getNext 21 | 22 | public int getValue() 23 | { 24 | return _value; 25 | }// end of method getValue 26 | }// end of class IntNode 27 | -------------------------------------------------------------------------------- /Exam2022Bjune86/Node.java: -------------------------------------------------------------------------------- 1 | import java.util.Stack; 2 | //******************************************************* 3 | // Node.java 4 | // the class reprsents Node 5 | // Author: liron mizrahi 6 | //******************************************************* 7 | public class Node 8 | { 9 | int _number; 10 | Node _leftSon, _rightSon; 11 | 12 | public Node(int number) 13 | { 14 | _number = number; 15 | _leftSon = null; 16 | _rightSon = null; 17 | }// end of method Node 18 | 19 | public int getNumber() 20 | { 21 | return _number; 22 | }// end of method getNumber 23 | 24 | public Node getLeftSon() 25 | { 26 | return _leftSon; 27 | }// end of method getLeftSon 28 | 29 | public Node getRightSon() 30 | { 31 | return _rightSon; 32 | }// end of method getRightSon 33 | // what method in the exam 34 | public static String what(Node t) 35 | { 36 | String output = "("; 37 | if(t.getLeftSon() != null) 38 | { 39 | output += what(t.getLeftSon()); 40 | } 41 | output += t.getNumber(); 42 | if(t.getRightSon() != null) 43 | { 44 | output += what(t.getRightSon()); 45 | } 46 | output += ")"; 47 | return output; 48 | }// end of method what 49 | // what method enswer in ex4 section D 50 | public static String what1(Node t) 51 | { 52 | String output = "("; 53 | // Base Case 54 | if (t == null) 55 | { 56 | return output; 57 | } 58 | output += t.getNumber(); 59 | output += what1(t._leftSon); 60 | output += ")"; 61 | output += what1(t._rightSon); 62 | return output; 63 | } // end of method what1 64 | }// end of class node 65 | -------------------------------------------------------------------------------- /ExamComputerScienceInJavaSemesterAYear2016/Card.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.io.PrintWriter; 3 | import java.util.Scanner; 4 | //******************************************************* 5 | // Card.java 6 | // the class reprsents Card 7 | // Author: liron mizrahi 8 | //******************************************************* 9 | public class Card 10 | { 11 | public final static int FINAL_VALUE_FOR_CARD = 10; 12 | private int _cardValue; 13 | public enum _typeOfCard{SPADES,HEARTS,DIAMONDS,CLUBS}; 14 | public static _typeOfCard _type; 15 | /** 16 | * constractor of the class Card 17 | * @parm: int cardValue, _typeOfCard type 18 | * @return: None 19 | */ 20 | public Card(int cardValue, _typeOfCard type) 21 | { 22 | _cardValue = cardValue; 23 | if( cardValue >= 1 && cardValue <= 10) 24 | { 25 | _cardValue = cardValue; 26 | } 27 | else 28 | { 29 | _cardValue = 1; 30 | } 31 | }// end of method Card 32 | /** 33 | * constractor of the class Card 34 | * @parm: int cardValue, _typeOfCard type 35 | * @return: None 36 | */ 37 | public Card(Scanner s) 38 | { 39 | this(s.nextInt(), _typeOfCard.valueOf(s.next())); 40 | }// end of method Card 41 | /** 42 | * the method get printWriter object and write to him the value of the card and the sign on him 43 | * @parm: PrintWriter pw 44 | * @return: None 45 | */ 46 | public void save(PrintWriter pw) 47 | { 48 | pw.println(_cardValue); 49 | pw.println(_type.name()); 50 | }// end of method save 51 | /** 52 | * the method 53 | * @parm: PrintWriter pw 54 | * @return: None 55 | */ 56 | public boolean isHigher(Card card) 57 | { 58 | if(_cardValue > card._cardValue) 59 | { 60 | return true; 61 | } 62 | else if(_cardValue < card._cardValue) 63 | { 64 | return false; 65 | } 66 | else 67 | { 68 | return _type.ordinal() > card._type.ordinal(); 69 | } 70 | }// end of method isHigher 71 | /** 72 | * the method return string with object data 73 | * @parm: None 74 | * @return: String 75 | */ 76 | public String toString() 77 | { 78 | return "card value: " + _cardValue + " type of card: " + _type; 79 | }// end of method toString 80 | }// end of class Card 81 | -------------------------------------------------------------------------------- /ExamComputerScienceInJavaSemesterAYear2016/Deck.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.io.PrintWriter; 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | //******************************************************* 6 | // Deck.java 7 | // the class reprsents Deck 8 | // Author: liron mizrahi 9 | //******************************************************* 10 | public class Deck 11 | { 12 | public final static int MAX_NUM_OF_CARD = 40; 13 | public Card[] _cardArray; 14 | public int _leftCard; 15 | /** 16 | * constractor of the class Card 17 | * @parm: None 18 | * @return: None 19 | */ 20 | public Deck() 21 | { 22 | _cardArray = new Card[MAX_NUM_OF_CARD]; 23 | _leftCard = 0; 24 | 25 | Card._type[] allTypes = Card._type.values(); 26 | for(int i = 1; i <= Card.FINAL_VALUE_FOR_CARD; i++) 27 | { 28 | for(Card._type t : allTypes) 29 | { 30 | _cardArray[_leftCard++] = new Card(i, t); 31 | } 32 | } 33 | shuffle(); 34 | }// end of method Deck 35 | /** 36 | * constractor of the class Card 37 | * @parm: String fileName 38 | * @return: 39 | */ 40 | public Deck(String fileName) throws FileNotFoundException 41 | { 42 | Scanner s = new Scanner(new File(fileName)); 43 | _leftCard = s.nextInt(); 44 | _cardArray = new Card[_leftCard]; 45 | for(int i = 0; i < _cardArray.length; i++) 46 | { 47 | _cardArray[i] = new Card(s); 48 | } 49 | 50 | s.close(); 51 | }// end of method Deck 52 | /** 53 | * the method save the number of left cards and the data of the cards to file given as paramter 54 | * @parm: String file 55 | * @return: None 56 | */ 57 | public void save(String file) throws FileNotFoundException 58 | { 59 | File f = new File(file); 60 | PrintWriter pw = new PrintWriter(f); 61 | 62 | pw.println(_leftCard); 63 | for(int i = 0; i < _leftCard; i++) 64 | { 65 | _cardArray[i].save(pw); 66 | } 67 | pw.close(); 68 | }// end of method save 69 | /** 70 | * the method shuffles the cards in the Deck of cards 71 | * @parm: None 72 | * @return: None 73 | */ 74 | public void shuffle() 75 | { 76 | for(int i = 0; i < _cardArray.length; i++) 77 | { 78 | int rand1 = (int) (Math.random() * _cardArray.length); 79 | int rand2 = (int) (Math.random() * _cardArray.length); 80 | Card temp = _cardArray[rand1]; 81 | _cardArray[rand1] = _cardArray[rand2]; 82 | _cardArray[rand2] = temp; 83 | } 84 | }// end of method shuffle 85 | /** 86 | * the method return the num of cards left in the deck 87 | * @parm: None 88 | * @return: int 89 | */ 90 | public int cardsLeft() 91 | { 92 | return _leftCard; 93 | }// end of method cardsLeft 94 | /** 95 | * the method return the last card in card array and remove him 96 | * @parm: None 97 | * @return: Card 98 | */ 99 | public Card dealTopCard() 100 | { 101 | return _cardArray[--_leftCard]; 102 | }// end of method dealTopCard 103 | /** 104 | * the method return the last card in card array and not remove him 105 | * @parm: None 106 | * @return: Card 107 | */ 108 | public Card peekTopCard() 109 | { 110 | return _cardArray[_leftCard - 1]; 111 | }// peekTopCard 112 | /** 113 | * the method return the data of the deck as string 114 | * @parm: None 115 | * @return: String 116 | */ 117 | public String toString() 118 | { 119 | StringBuffer str = new StringBuffer("[" + _leftCard +" -"); 120 | for(int i=_leftCard - 1; i >= 0; i--) 121 | { 122 | str.append(_cardArray[i].toString() + ", "); 123 | } 124 | str.append("]"); 125 | return str.toString(); 126 | }// end of method toString 127 | }// end of method Deck 128 | -------------------------------------------------------------------------------- /ExamJavaAYear2017SemseterA/Date.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class Date 3 | { 4 | private int _day; 5 | private int _month; 6 | private int _year; 7 | /** 8 | * constructor of the class Date 9 | * @param: int d, int m, int y 10 | * @return: None 11 | */ 12 | public Date(int d, int m, int y) 13 | { 14 | _day = d; 15 | _month = m; 16 | _year = y; 17 | }// end of method Date 18 | /** 19 | * copy constructor of the class Date 20 | * @param: Date d 21 | * @return: None 22 | */ 23 | public Date(Date d) 24 | { 25 | _day = d._day; 26 | _month = d._month; 27 | _year = d._year; 28 | }// end of method Date 29 | /** 30 | * method return the day of the date 31 | * @param: None 32 | * @return: int 33 | */ 34 | public int getDay() 35 | { 36 | return _day; 37 | }// end of method getDay 38 | 39 | /** 40 | * method return the month of the date 41 | * @param: None 42 | * @return: int 43 | */ 44 | public int getMonth() 45 | { 46 | return _month; 47 | }// end of method getMonth 48 | 49 | /** 50 | * method return the year of the date 51 | * @param: None 52 | * @return: int 53 | */ 54 | public int getYear() 55 | { 56 | return _day; 57 | }// end of method getYear 58 | /** 59 | * method set the day of the date 60 | * @param: int x 61 | * @return: None 62 | */ 63 | public void setDay(int x) 64 | { 65 | _day = x; 66 | }// end of method setDay 67 | /** 68 | * method set the month of the date 69 | * @param: int x 70 | * @return: None 71 | */ 72 | public void setMonth(int x) 73 | { 74 | _month = x; 75 | }// end of method setMonth 76 | /** 77 | * method set the month of the date 78 | * @param: int x 79 | * @return: None 80 | */ 81 | public void setYear(int x) 82 | { 83 | _year = x; 84 | }// end of method setDay 85 | /** 86 | * method return true if the two date are equals 87 | * @param: Date date 88 | * @return: boolean 89 | */ 90 | public boolean equals(Date date) 91 | { 92 | if(_day == date.getDay() && _month == date.getMonth() && _year == date.getYear()) 93 | { 94 | return true; 95 | } 96 | return false; 97 | }// end of method equals 98 | /** 99 | * Method checks if the date represented by the object on which the method is invoked is before the date received as a parameter 100 | * @param other 101 | * @return true if the date is before the other date or false if not 102 | */ 103 | public boolean before (Date other) 104 | { 105 | if ((this._month < other._month && this._year < other._year) || (this._day == other._day && this._month == other._month && this._year < other._year) || (this._month == other._month && this._year == other._year && this._day < other._day) || (this._month > other._month && this._year < other._year) || (this._year == other._year && this._month < other._month)) 106 | { 107 | return true; 108 | } 109 | return false; 110 | }// end of before method 111 | /** 112 | * Method checks if the date represented by the object on which the method is invoked is later than the date received as a parameter 113 | * @param other 114 | * @return true if the date is after the other date or false if not 115 | */ 116 | public boolean after(Date other) 117 | { 118 | if (other.before(this)) 119 | { 120 | return true; 121 | } 122 | return false; 123 | }// end of after method 124 | /** 125 | * Method return String that represents date 126 | * @param None 127 | * @return String 128 | */ 129 | public String toString() 130 | { 131 | return _day + "/" + _month + "/" + _year; 132 | }// end of method 133 | }// end of class Date 134 | -------------------------------------------------------------------------------- /ExamJavaAYear2017SemseterA/Exam2017JavaA.java: -------------------------------------------------------------------------------- 1 | 2 | public class Exam2017JavaA 3 | { 4 | /** 5 | * Ex2 6 | * 7 | * solution: 8 | * Ex2.A 9 | * |-4|-3|0|0|1|2|6|4|5|3|2| 10 | * Ex2.B 11 | * rearranges its elements such that all positive 12 | * elements are at the end of the array, all negative 13 | * elements are at the beginning of the array, and all 14 | * 0's are in the middle. 15 | */ 16 | public static int[] secret (int [] a) 17 | { 18 | int r = -1; 19 | int w = 0; 20 | int b = a.length; 21 | int temp; 22 | do{ 23 | if (a[w] == 0) 24 | w++; 25 | else 26 | if (a[w] < 0) 27 | { 28 | r++; 29 | temp = a[r]; 30 | a[r] = a[w]; 31 | a[w] = temp; 32 | w++; 33 | } 34 | else 35 | { 36 | b--; 37 | temp = a[b]; 38 | a[b] = a[w]; 39 | a[w] = temp; 40 | } 41 | } while (w longest) 80 | { 81 | longest = _inbox[i].howManyWords(); 82 | indexLongest = i; 83 | } 84 | } 85 | } 86 | } 87 | return _inbox[indexLongest]; 88 | }// end of method longestMessageFromSender 89 | /** 90 | * method remove the oldest message 91 | * @param: None 92 | * @return: None 93 | */ 94 | public void removeOldestMessage() 95 | { 96 | Date oldest = new Date(_inbox[0].getRecDate()); 97 | int indexOldest = 0; 98 | for(int i = 1; i < _inbox.length; i++) 99 | { 100 | if(_inbox[i] instanceof Message) 101 | { 102 | if(_inbox[i].getRecDate().before(oldest)); 103 | { 104 | oldest = new Date(_inbox[i].getRecDate()); 105 | indexOldest = i; 106 | } 107 | } 108 | } 109 | _inbox[indexOldest] = null; 110 | for(int j = indexOldest + 1; j < _inbox.length; j++) 111 | { 112 | if(_inbox[j] instanceof Message) 113 | { 114 | _inbox[j-1] = _inbox[j]; 115 | } 116 | else 117 | { 118 | break; 119 | } 120 | } 121 | }// end of method removeOldestMessage 122 | }// end of class MailBox 123 | -------------------------------------------------------------------------------- /ExamJavaAYear2017SemseterA/Message.java: -------------------------------------------------------------------------------- 1 | 2 | public class Message 3 | { 4 | private String _sender, _subject, _content; 5 | private Date _dateReceived; 6 | /** 7 | * constructor of the class Message 8 | * @param: String sender, String subject, String content, Date date 9 | * @return: None 10 | */ 11 | public Message(String sender, String subject, String content, Date date) 12 | { 13 | _sender = sender; 14 | _subject = subject; 15 | _content = content; 16 | _dateReceived = date; 17 | }// end of method Message 18 | /** 19 | * copy constructor of the class Message 20 | * @param: Message m 21 | * @return: None 22 | */ 23 | public Message(Message m) 24 | { 25 | _sender = m._sender; 26 | _subject = m._subject; 27 | _content = m._content; 28 | _dateReceived = new Date(m._dateReceived.getDay(), m._dateReceived.getMonth(), m._dateReceived.getYear()); 29 | }// end of method Message 30 | /** 31 | * methed return the sender of the message 32 | * @param: None 33 | * @return: String 34 | */ 35 | public String getSender() 36 | { 37 | return _sender; 38 | }// end of method getSender 39 | /** 40 | * methed return the subject of the message 41 | * @param: None 42 | * @return: String 43 | */ 44 | public String getSubject() 45 | { 46 | return _subject; 47 | }// end of method getSubject 48 | /** 49 | * methed return the content of the message 50 | * @param: None 51 | * @return: String 52 | */ 53 | public String getContent() 54 | { 55 | return _content; 56 | }// end of method getContent 57 | /** 58 | * methed return date of the message 59 | * @param: None 60 | * @return: String 61 | */ 62 | public Date getRecDate() 63 | { 64 | return new Date(_dateReceived); 65 | }// end of method getRecDate 66 | /** 67 | * methed return true if the address is valid 68 | * @param: None 69 | * @return: boolean 70 | */ 71 | public boolean isValidAddress() 72 | { 73 | return _sender.contains("@"); 74 | }// end of method isValidAddress 75 | /** 76 | * methed return the number of words in the message content 77 | * @param: None 78 | * @return: int 79 | */ 80 | public int howManyWords() 81 | { 82 | return _content.length(); 83 | }// end of method howManyWords 84 | /** 85 | * methed return the number of words in the message content 86 | * @param: Message 87 | * @return: boolean 88 | */ 89 | public boolean wasReceivedEarlier(Message other) 90 | { 91 | return other.getRecDate().before(this.getRecDate()); 92 | }// end of method wasReceivedEarlier 93 | }// end of class Message 94 | -------------------------------------------------------------------------------- /ExamJavaFebruary2022Date87/exam2022.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lironmiz/Computer-Science-in-Java/71abf905b948e24c02e2d3fc303e285e70a45dfa/ExamJavaFebruary2022Date87/exam2022.pdf -------------------------------------------------------------------------------- /ExamYear2022Semseter1EfekaCollege/Artist.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // Artist.java 3 | // the class reprsents Artist 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | import java.util.Arrays; 7 | public class Artist 8 | { 9 | private String _name; 10 | private Song[] _writtenSongs; 11 | private Song[] _performedSongs; 12 | /** 13 | * constractor of the class Artist 14 | * @param: String name 15 | * @return: None 16 | */ 17 | public Artist(String name) 18 | { 19 | _name = name; 20 | _writtenSongs = new Song[0]; 21 | _performedSongs = new Song[0]; 22 | }// end of method Artist 23 | /** 24 | * method return the name of the artist 25 | * @param: String name 26 | * @return: String 27 | */ 28 | public String getName() 29 | { 30 | return _name; 31 | }// end of method getName 32 | /** 33 | * method return returns true if the artists already has a song 34 | * @param: Song theSong 35 | * @return: boolean 36 | */ 37 | public boolean hasWroteSong(Song theSong) 38 | { 39 | for(int i = 0; i < _writtenSongs.length; i++) 40 | { 41 | if(_writtenSongs[i].getName() == theSong.getName()) 42 | { 43 | return true; 44 | } 45 | } 46 | return false; 47 | }// end of method hasWroteSong 48 | /** 49 | * method return true if she add given song to writtenSong list 50 | * @param: Song newSong 51 | * @return: boolean 52 | */ 53 | public boolean addWrittenSong(Song newSong) 54 | { 55 | return false; 56 | }// end of method addWrittenSong 57 | /** 58 | * method return true if she add performed song to the performedSongs list 59 | * @param: Song newsSong 60 | * @return: boolean 61 | */ 62 | public boolean addPerformedSong(Song newSong) 63 | { 64 | if (hasPerformedSong(newSong)) 65 | { 66 | return false; 67 | } 68 | 69 | _performedSongs = Arrays.copyOf(_performedSongs, _performedSongs.length+1); 70 | _performedSongs[_performedSongs.length-1] = newSong; 71 | newSong.setLastPerformer(this); 72 | return true; 73 | }// end of method addPerformedSong 74 | /** 75 | * method return true if given song is exists in the performedSongs list 76 | * @param: Song theSong 77 | * @return: boolean 78 | */ 79 | public boolean hasPerformedSong(Song theSong) 80 | { 81 | for (int i=0 ; i < _performedSongs.length ; i++) 82 | { 83 | if (_performedSongs[i].getName().equals(theSong.getName())) 84 | { 85 | return true; 86 | } 87 | } 88 | return false; 89 | }// end of method hasPerformedSong 90 | @Override 91 | /** 92 | * method return Artists data as string 93 | * @param: None 94 | * @return: String 95 | */ 96 | public String toString() 97 | { 98 | StringBuffer sb = new StringBuffer("The artist " + _name + " wrote " + _writtenSongs.length + " songs:\n"); 99 | for (int i=0 ; i < _writtenSongs.length; i++) 100 | { 101 | sb.append("\t" + _writtenSongs[i].getName()+ "\n"); 102 | } 103 | sb.append("and performed these songs: \n"); 104 | for (int i=0 ; i < _performedSongs.length; i ++) 105 | { 106 | sb.append("\t" + _performedSongs[i].getName()+ "\n"); 107 | } 108 | return sb.toString(); 109 | }// end of method toString 110 | }// end of class Artist 111 | -------------------------------------------------------------------------------- /ExamYear2022Semseter1EfekaCollege/Song.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // Song.java 3 | // the class reprsents Song 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class Song 7 | { 8 | private String _name; 9 | private Artist _writer; 10 | private Artist _lastPerformer; 11 | /** 12 | * constractor of the class Song 13 | * @param: String name, Artist writer, Artist lastPerformer 14 | * @return: None 15 | */ 16 | public Song(String name, Artist writer, Artist lastPerformer) 17 | { 18 | _name = name; 19 | _writer = writer; 20 | _writer.addWrittenSong(this); 21 | 22 | _lastPerformer = lastPerformer; 23 | 24 | if (_lastPerformer != null) 25 | { 26 | _lastPerformer.addPerformedSong(this); 27 | } 28 | }// end of method Song 29 | /** 30 | * constractor set the last performer 31 | * @param: Artist lastPerformer 32 | * @return: None 33 | */ 34 | public void setLastPerformer(Artist lastPerformer) 35 | { 36 | if (lastPerformer!= null && _lastPerformer != lastPerformer) 37 | { 38 | _lastPerformer = lastPerformer; 39 | _lastPerformer.addPerformedSong(this); 40 | } 41 | }// end of method setLastPerformer 42 | /** 43 | * method get the name of the song 44 | * @param: None 45 | * @return: String 46 | */ 47 | public String getName() 48 | { 49 | return _name; 50 | }// end of method getName 51 | /** 52 | * method return the data of the song as string 53 | * @param: None 54 | * @return: String 55 | */ 56 | @Override 57 | public String toString() 58 | { 59 | StringBuffer sb = new StringBuffer("The song '" + _name + "' was written by " + _writer.getName()); 60 | if (_lastPerformer != null) 61 | { 62 | sb.append(" and was last performed by " + _lastPerformer.getName()); 63 | } 64 | return sb.toString(); 65 | }// end of method toString 66 | }// end of class toString 67 | -------------------------------------------------------------------------------- /ExamYear2022Semseter1EfekaCollege/SongsRepository.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // SongsRepository.java 3 | // the class reprsents SongsRepository 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | import java.util.Arrays; 7 | public class SongsRepository 8 | { 9 | public enum eAddSongStatus 10 | { 11 | Success, SongAlreadyExist, WriterDoesntExist, PerformerDoesntExist 12 | }; 13 | 14 | private Artist[] _allArtists; 15 | private int _numOfArtists; 16 | private Song[] _allSongs; 17 | private int _numOfSongs; 18 | /** 19 | * constractor of the class SongsRepository 20 | * @param: None 21 | * @return: None 22 | */ 23 | public SongsRepository() 24 | { 25 | _allArtists = new Artist[2]; 26 | _numOfArtists = 0; 27 | 28 | _allSongs = new Song[2]; 29 | _numOfSongs = 0; 30 | }// end of method SongsRepository 31 | /** 32 | * method return the artist object with given name if the artist exists 33 | * @param: String name 34 | * @return: Artist 35 | */ 36 | public Artist getArtistByName(String name) 37 | { 38 | for (int i = 0; i < _numOfArtists; i++) 39 | { 40 | if (_allArtists[i].getName().equals(name)) 41 | { 42 | return _allArtists[i]; 43 | } 44 | } 45 | return null; 46 | }// end of method getArtistByName 47 | /** 48 | * method return the song by the name by the name of the song 49 | * @param: String name 50 | * @return: Artist 51 | */ 52 | public Song getSongByName(String name) 53 | { 54 | for (int i = 0; i < _numOfSongs; i++) 55 | { 56 | if (_allSongs[i].getName().equals(name)) 57 | { 58 | return _allSongs[i]; 59 | } 60 | } 61 | return null; 62 | }// end of method getSongByName 63 | /** 64 | * method return true if the method add artist to allArtists list 65 | * @param: String name 66 | * @return: boolean 67 | */ 68 | public boolean addArtist(String name) 69 | { 70 | Artist temp = getArtistByName(name); 71 | if (temp == null) 72 | { 73 | if (_numOfArtists == _allArtists.length) 74 | { 75 | _allArtists = Arrays.copyOf(_allArtists, _allArtists.length*2); 76 | } 77 | _allArtists[_numOfArtists++] = new Artist(name); 78 | return true; 79 | } 80 | return false; 81 | }// end of method addArtist 82 | /** 83 | * method update the status of the song 84 | * @param: String songName, String writerName, String performerName 85 | * @return: eAddSongStatus 86 | */ 87 | public eAddSongStatus addSong(String songName, String writerName, String performerName) 88 | { 89 | Song temp = getSongByName(songName); 90 | if (temp != null) 91 | { 92 | return eAddSongStatus.SongAlreadyExist; 93 | } 94 | Artist writer = getArtistByName(writerName); 95 | if (writer == null) 96 | { 97 | return eAddSongStatus.WriterDoesntExist; 98 | } 99 | Artist performer = null; 100 | if (!performerName.equals("")) 101 | { 102 | performer = getArtistByName(performerName); 103 | if (performer == null) 104 | { 105 | return eAddSongStatus.PerformerDoesntExist; 106 | } 107 | } 108 | 109 | if (_numOfSongs == _allSongs.length) 110 | { 111 | _allSongs = Arrays.copyOf(_allSongs, _allSongs.length * 2); 112 | } 113 | 114 | _allSongs[_numOfSongs] = new Song(songName, writer, performer); 115 | 116 | writer.addWrittenSong(_allSongs[_numOfSongs]); 117 | 118 | if (performer != null) 119 | { 120 | performer.addPerformedSong(_allSongs[_numOfSongs]); 121 | } 122 | _numOfSongs++; 123 | return eAddSongStatus.Success; 124 | }// end of method addSong 125 | /** 126 | * method return the data of the song as string 127 | * @param: None 128 | * @return: String 129 | */ 130 | @Override 131 | public String toString() 132 | { 133 | StringBuffer sb = new StringBuffer("The artists in the repository:\n"); 134 | for (int i = 0; i < _numOfArtists; i++) 135 | { 136 | sb.append(_allArtists[i].toString() + "\n"); 137 | } 138 | sb.append("The songs in the repository:\n"); 139 | for (int i = 0; i < _numOfSongs; i++) 140 | { 141 | sb.append(_allSongs[i].toString() + "\n"); 142 | } 143 | return sb.toString(); 144 | }// end of method toString 145 | }// end of class SongsRepository 146 | -------------------------------------------------------------------------------- /HashTableArray.java: -------------------------------------------------------------------------------- 1 | 2 | //******************************************************* 3 | // Class Entry.java 4 | // A class that represents an implementation of a hase table in java 5 | // Author: liron mizrahi 6 | //******************************************************* 7 | public class HashTableArray 8 | { 9 | Entry[] _hashArray; 10 | int _size; 11 | /** 12 | * constructor of the class 13 | * @param int 14 | * @return None 15 | */ 16 | public void HaseTableArray( int size) 17 | { 18 | _size = size; 19 | _hashArray = new Entry[size]; 20 | for(int i=0; i= 0; i--) 38 | { 39 | if(val > _arr[i]) 40 | { 41 | _arr[i + 1] = _arr[i]; 42 | } 43 | else 44 | { 45 | break; 46 | } 47 | } 48 | _arr[i + 1] = val; 49 | _length++; 50 | }// end of method insert 51 | /** 52 | * printPriorityQueue method will print the values in the queue 53 | * @param None 54 | * @return None 55 | */ 56 | public void printPriorityQueue() 57 | { 58 | for( int i = 0; i < _length; i++) 59 | { 60 | System.out.print(_arr[i] + " "); 61 | } 62 | }// end of method printPriorityQueue 63 | /** 64 | * remove method remove the last value in the queue 65 | * @param None 66 | * @return int 67 | */ 68 | public int remove() 69 | { 70 | return _arr[--_length]; 71 | }// end of method remove 72 | /** 73 | * isFull method return if the queue is full or not 74 | * @param None 75 | * @return boolean 76 | */ 77 | public boolean isFull() 78 | { 79 | return _length == _max; 80 | }// end of method isFull 81 | /** 82 | * isEmpty method return if the queue is empty or not 83 | * @param None 84 | * @return boolean 85 | */ 86 | public boolean isEmpty() 87 | { 88 | return _length == 0; 89 | }// end of method isEmpty 90 | }// end of class PriorityQueue 91 | -------------------------------------------------------------------------------- /Queue.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // Queue.java 3 | // A class that represents an implementation of a Queue in java 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | public class Queue 7 | { 8 | int[] _queue; 9 | int _size; // total number of elements in queue 10 | int _front; 11 | int _rear; 12 | /** 13 | * constractor of the class queue 14 | * @param int 15 | * @return None 16 | */ 17 | public Queue(int sizeOfArray) 18 | { 19 | _queue = new int[sizeOfArray]; 20 | _rear = -1; 21 | _front = -1; 22 | _size = 0; 23 | }//end of method Queue 24 | /** 25 | * method return the size of the queue 26 | * @param None 27 | * @return int 28 | */ 29 | public int getSize() 30 | { 31 | return _size; 32 | }// end of method getSize 33 | /** 34 | * return true if the queue is empty 35 | * @param None 36 | * @return boolean 37 | */ 38 | public boolean isEmpty() 39 | { 40 | boolean response = false; 41 | // if the size in 0 there the queue is empty 42 | if(_size == 0) 43 | { 44 | response = true; 45 | } 46 | return response; 47 | }//end of method isEmpty 48 | /** 49 | * method is insert value to queue 50 | * @param int 51 | * @return boolean 52 | */ 53 | public boolean enQueue(int element) 54 | { 55 | boolean response = false; 56 | // checking if the rear is not equeal the the final inded 57 | if(_rear != _queue.length - 1) 58 | { 59 | _rear++; 60 | _queue[_rear] = element; 61 | _size = _size + 1; 62 | response = true; 63 | } 64 | return response; 65 | }//end of method enQueue 66 | /** 67 | * method is removing value from queue 68 | * @param None 69 | * @return int 70 | */ 71 | public int deQueue() 72 | { 73 | int response = 0; 74 | // checking if the queue is not empty 75 | if(_size != 0) 76 | { 77 | _front++; 78 | response = _queue[_front]; 79 | _size--; 80 | } 81 | return response; 82 | }// end of method deQueue 83 | /** 84 | * method is print the queue elements 85 | * @param None 86 | * @return None 87 | */ 88 | public void show() 89 | { 90 | System.out.println("Elements: "); 91 | // loopint the queue elements and prints them 92 | for(int i = 0; i < _size; i++) 93 | { 94 | System.out.print(_queue[i] + " "); 95 | } 96 | }// end of method show 97 | /** 98 | * method is show the first element in queue 99 | * @param None 100 | * @return int 101 | */ 102 | public int peek() 103 | { 104 | int response = 0; 105 | if(!isEmpty()) 106 | { 107 | response = _queue[_front + 1]; 108 | } 109 | return response; 110 | }// end of method peek 111 | 112 | public static void main(String[] args) 113 | { 114 | // making queue object 115 | Queue queue = new Queue(10); 116 | // insert element to the queue 117 | System.out.println(queue.enQueue(1000)); // return true 118 | System.out.println(queue.enQueue(2000)); // retrun true 119 | System.out.println(queue.enQueue(500)); // return true 120 | System.out.println(queue.getSize()); // return 3 121 | System.out.println(queue.peek()); // return 1000 122 | queue.show(); // return 1000, 2000, 500 123 | queue.isEmpty(); //return false 124 | System.out.println(queue.deQueue() + " deleted from the list"); // return 1000 deleted from the list 125 | }// end of method main 126 | }// end of class Queue 127 | -------------------------------------------------------------------------------- /RentDriver.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // RentDriver.java. 3 | // tester for the rent class 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | import java.util.Scanner; 7 | public class RentDriver 8 | { 9 | public static void main(String[] args) 10 | { 11 | // creat scanner object 12 | Scanner scanner = new Scanner(System.in); 13 | // print to user 14 | System.out.println(" Please enter the name, car, pick date, return date"); 15 | String name = scanner.nextLine(); 16 | // take user input for car object 17 | System.out.println("Please enter Car information: \n ID:(have to be seven digits) \n Type: (A,B,C,D) \n Brand:(car brand) \n Is Manual:(true or false)"); 18 | int id = scanner.nextInt(); 19 | char type = scanner.next().charAt(0); 20 | System.out.println("now string"); 21 | String brand = scanner.next(); 22 | boolean isManual = scanner.nextBoolean(); 23 | Car car = new Car(id, type, brand, isManual); 24 | // take input for pick date 25 | System.out.println("Please enter the day, month, year" + " of the pick date"); 26 | // take user input 27 | int pickDay = scanner.nextInt(); 28 | int pickMonth = scanner.nextInt(); 29 | int pickYear = scanner.nextInt(); 30 | // making Date object 31 | Date pickDate = new Date(pickDay, pickMonth, pickYear); 32 | // take input for return date 33 | System.out.println("Please enter the day, month, year" + " of the return date"); 34 | // take user input 35 | int returnDay = scanner.nextInt(); 36 | int returnMonth = scanner.nextInt(); 37 | int returnYear = scanner.nextInt(); 38 | // making Date object 39 | Date returnDate = new Date(returnDay, returnMonth, returnYear); 40 | // make a rent object 41 | Rent rent = new Rent(name, car, pickDate, returnDate); 42 | // print to user 43 | System.out.println(" Please enter the name, car, pick date, return date"); 44 | String name1 = scanner.next(); 45 | // take user input for car object 46 | System.out.println("Please enter Car information: \n ID:(have to be seven digits) \n Type: (A,B,C,D) \n Brand:(car brand) \n Is Manual:(true or false)"); 47 | int id1 = scanner.nextInt(); 48 | char type1 = scanner.next().charAt(0); 49 | System.out.println("now string"); 50 | String brand1 = scanner.next(); 51 | boolean isManual1 = scanner.nextBoolean(); 52 | Car car1 = new Car(id1, type1, brand1, isManual1); 53 | // take input for pick date 54 | System.out.println("Please enter the day, month, year" + " of the pick date"); 55 | // take user input 56 | int pickDay1 = scanner.nextInt(); 57 | int pickMonth1 = scanner.nextInt(); 58 | int pickYear1 = scanner.nextInt(); 59 | // making Date object 60 | Date pickDate1 = new Date(pickDay1, pickMonth1, pickYear1); 61 | // take input for return date 62 | System.out.println("Please enter the day, month, year" + " of the return date"); 63 | // take user input 64 | int returnDay1 = scanner.nextInt(); 65 | int returnMonth1 = scanner.nextInt(); 66 | int returnYear1 = scanner.nextInt(); 67 | // making Date object 68 | Date returnDate1 = new Date(returnDay1, returnMonth1, returnYear1); 69 | // make a rent object 70 | Rent rent1 = new Rent(name1, car1, pickDate1, returnDate1); 71 | // chek the equals method 72 | if (rent.equals(rent1)) 73 | { 74 | System.out.println("Same"); 75 | } 76 | else 77 | { 78 | System.out.println("not the same"); 79 | } 80 | // check toString method 81 | System.out.println(rent.toString()); 82 | System.out.println(rent1.toString()); 83 | // check how much rent day left 84 | System.out.println("the days left is: " + rent.howManyDays()); 85 | // get the price of the rent 86 | System.out.println("rent price is: " + rent.getPrice()); 87 | System.out.println("rent1 price is: " + rent1.getPrice()); 88 | // check the overlap method 89 | Rent overlapRent = rent.overlap(rent1); 90 | System.out.println("overlap rent: " + overlapRent.toString()); 91 | // close the scanner object 92 | scanner.close(); 93 | }// end of method main 94 | }// end of class RentDriver 95 | -------------------------------------------------------------------------------- /RentNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * RentNode.java 3 | * the class represent a RentNode 4 | * @author (liron mizrhai) 5 | * @Date (1/20/2023) 6 | */ 7 | public class RentNode 8 | { 9 | private Rent _rent; 10 | private RentNode _next; 11 | 12 | /** 13 | * constuctor of the class RentNode 14 | * @parm Rent r 15 | * @return None 16 | */ 17 | public RentNode (Rent r) 18 | { 19 | _rent = new Rent(r); 20 | _next = null; 21 | }// end of method RentNode 22 | 23 | /** 24 | * constuctor of the class RentNode 25 | * @parm Rent r, RentNode next 26 | * @return None 27 | */ 28 | public RentNode (Rent r, RentNode next) 29 | { 30 | this._rent = new Rent(r); 31 | this._next = next; 32 | }// end of method RentNode 33 | /** 34 | * copy constuctor of the class RentNode 35 | * @parm RentNode other 36 | * @return None 37 | */ 38 | public RentNode(RentNode other) 39 | { 40 | _rent = other._rent; 41 | _next = other._next; 42 | }// end of method RentNode 43 | /** 44 | * method return the rent 45 | * @parm None 46 | * @return Rent 47 | */ 48 | public Rent getRent() 49 | { 50 | return new Rent(_rent); 51 | }// end of method getRent 52 | /** 53 | * method return the getNext 54 | * @parm None 55 | * @return _next 56 | */ 57 | public RentNode getNext() 58 | { 59 | return _next; 60 | }// end of method getNext 61 | /** 62 | * method set the _rent to given rent 63 | * @parm Rent r 64 | * @return None 65 | */ 66 | public void setRent(Rent r) 67 | { 68 | _rent = new Rent(r); 69 | }// end of method setRent 70 | /** 71 | * method set the _next to given RentNode 72 | * @parm RentNode next 73 | * @return None 74 | */ 75 | public void setNext(RentNode next) 76 | { 77 | _next = next; 78 | }// end of method setNext 79 | /** 80 | * method return RentNode at given index 81 | * @parm int index 82 | * @return RentNode 83 | */ 84 | public RentNode get(int index) 85 | { 86 | if(index < 0) 87 | { 88 | throw new IndexOutOfBoundsException(); 89 | } 90 | RentNode temp = new RentNode(_rent); 91 | for(int i = 0; i < index; i++) 92 | { 93 | temp = temp.getNext(); 94 | } 95 | return temp; 96 | }// end of method get 97 | }// end of class RentNode 98 | -------------------------------------------------------------------------------- /Runner.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Class Runner.java 3 | * A main class for playing and checking the priority queue 4 | */ 5 | public class Runner 6 | { 7 | public static void main(String[] args) 8 | { 9 | // create a priority queue object 10 | PriorityQueue queue = new PriorityQueue(10); 11 | // add data 12 | queue.insert(10); 13 | queue.insert(55); 14 | queue.insert(40); 15 | queue.insert(5); 16 | queue.insert(-5); 17 | queue.insert(100); 18 | queue.insert(525); 19 | queue.insert(430); 20 | queue.insert(18); 21 | queue.insert(78); 22 | // -5 | 5 | 10 | 18 | 40 | 55 | 78 | 100 | 430 | 525 23 | // print the queue values 24 | queue.printPriorityQueue(); 25 | // print if the queue is empty 26 | System.out.println("is queue empty? " + queue.isEmpty()); 27 | // remove data 28 | queue.remove(); 29 | queue.remove(); 30 | // print the queue values 31 | queue.printPriorityQueue(); 32 | // | 10 | 18 | 40 | 55 | 78 | 100 | 430 | 525 | 33 | }// end of method main 34 | }// end of class Runner 35 | -------------------------------------------------------------------------------- /Solution.txt: -------------------------------------------------------------------------------- 1 | ex1 -> Class b - בגלל מנגנון ה - polymorphism 2 | ex2 -> public void method1(float y) 3 | ex3 -> אם הרשאת הגישה לשיטה f שבמחלקה A היא protected והרשאת הגישה לשיטה f שבמחלקה B היא private. 4 | ex4 ->המחלקות Computer ו-TV יורשות מהמחלקה ElectronicDevice והמחלקה Laptop יורשת מהמחלקה 5 | ex5 -> הפלט יהיה: B 6 | ex6 -> המחלקה A מכילה שיטה בשם f שאינה מקבלת פרמטרים. 7 | ex7 -> שגיאת קומפליציה 8 | ex8 -> שגיאת זמן ריצה 9 | ex12 -> על הפלט יודפס dd 10 | ex13 -> שגיאת קומפליציה 11 | ex14 -> על הפלט יודפס 3 ובשורה שאחריה יודפס 10 12 | ex15 -> שגיאת קומפליציה 13 | ex16 -> על הפלט יודפס 1 14 | ex17 -> Card 15 | ex18 -> כל קטע קוד הנכתב באחת מן המחלקות היורשות זמין באופן מיידי במחלקה - האם ובכל אחיותיה בעת הירושה 16 | ex19 -> המחלקות poodle , dalmation יורשות מהמחלקה dog והמחלקות dog and cat יורשות מהמחלקה mammal 17 | ex20 -> כל התשובות האחרות אינן נכונות 18 | 19 | public class ClassA 20 | { 21 | public ClassA() 22 | { 23 | f(); 24 | }// end of method ClassA 25 | 26 | public void f() 27 | { 28 | System.out.println("Class a"); 29 | }// end of method f 30 | 31 | public static void main(String[] args) 32 | { 33 | new ClassB(); 34 | }// end of method main 35 | }// end of class ClassA 36 | 37 | 38 | public class ClassB extends ClassA 39 | 40 | { 41 | 42 | public ClassB() {} 43 | 44 | 45 | 46 | public void f() 47 | 48 | { 49 | 50 | System.out.println("Class b"); 51 | 52 | } 53 | 54 | } 55 | 56 | public class A { 57 | 58 | public void method1(float x){ … } 59 | 60 | } 61 | 62 | public class A 63 | { 64 | public void a1() 65 | { 66 | System.out.println("A"); 67 | }// end of method a1 68 | 69 | public void a2() 70 | { 71 | a1(); 72 | }// end of method a2 73 | }// end of class A 74 | 75 | 76 | 77 | public class B extends A 78 | { 79 | @Override 80 | public void a1() 81 | { 82 | System.out.println("B"); 83 | }// end of method a1 84 | }// end of class B 85 | 86 | 87 | public class C 88 | { 89 | public void foo(D d) 90 | { 91 | System.out.println("cd"); 92 | } 93 | }// end of class C 94 | 95 | 96 | 97 | 98 | public class D extends C 99 | { 100 | public void foo(C c) 101 | { 102 | System.out.println("dc"); 103 | }// end of methdo foo 104 | 105 | public void foo(D d) 106 | { 107 | System.out.println("dd"); 108 | } 109 | 110 | }// end of method class D 111 | 112 | 113 | public class A 114 | { 115 | public void doSomething(int x) 116 | { 117 | System.out.println("1"); 118 | }// end of method doSomething 119 | 120 | public void doSomethingElse(int x, int y) 121 | { 122 | System.out.println("2"); 123 | }// end of method doSomethingElse 124 | 125 | public int calc (int x) 126 | { 127 | System.out.println("3"); 128 | return x + 1; 129 | }// end of method calc 130 | 131 | }// end of class A 132 | 133 | 134 | public class B extends A 135 | { 136 | public void doSomethingElse(int x) 137 | { 138 | System.out.println("4"); 139 | }// end of method doSomethingElse 140 | }// end of class B 141 | 142 | 143 | public class D extends A 144 | { 145 | public void calc(int x, int y) 146 | { 147 | System.out.println(7+y+x); 148 | }// end of method calc 149 | }// end of class D 150 | 151 | 152 | public class C extends A 153 | { 154 | public void doSomething(int x) 155 | { 156 | System.out.println("5"); 157 | }// end of method doSomething 158 | }// end of class C 159 | 160 | 161 | public class E extends C 162 | { 163 | public int calc(int x) 164 | { 165 | System.out.println("8"); 166 | return x + 3; 167 | }// end of method calc 168 | }// end of class E 169 | 170 | public abstract class A 171 | { 172 | public abstract boolean f(int x); 173 | }// end of abstract class A 174 | 175 | 176 | public abstract class B extends A 177 | { 178 | public boolean f(int x) 179 | { 180 | return x == 2; 181 | } 182 | }// end of abstract class B 183 | 184 | public class A 185 | { 186 | private int _x; 187 | public A(int x) 188 | { 189 | _x = x; 190 | }// end of method A 191 | 192 | public int getX() 193 | { 194 | return _x; 195 | }// end of method getX 196 | 197 | public int doubleX() 198 | { 199 | return 2 * getX(); 200 | }// end of method doubleX 201 | 202 | public int tripleX() 203 | { 204 | return 3 * _x; 205 | }// end of method tripleX 206 | 207 | public int subXhelper() 208 | { 209 | return _x -1; 210 | }// end of method subXhelper 211 | 212 | public int subX() 213 | { 214 | return subXhelper(); 215 | }// end of method subX 216 | }// end of class A 217 | 218 | public class B extends A 219 | { 220 | private int _x; 221 | 222 | public B(int xA, int xB) 223 | { 224 | super(xA); 225 | _x = xB; 226 | }// end of method B 227 | 228 | public int getX() 229 | { 230 | return _x; 231 | }// end of method getX 232 | 233 | public int superX() 234 | { 235 | return super.getX(); 236 | }// end of method superX 237 | 238 | public int tenTimesX() 239 | { 240 | return 10 * _x; 241 | }// end of method tenTimesX 242 | 243 | public int subXhelper() 244 | { 245 | return _x * 2; 246 | }// end of method subXhelper 247 | }// end of class B 248 | -------------------------------------------------------------------------------- /Train.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class Train 3 | { 4 | public static void main (String [] args) 5 | { 6 | Scanner scan = new Scanner (System.in); 7 | System.out.println ("Please enter 4 integers "); 8 | System.out.println ("Please enter the speed of train 1:"); 9 | int v1 = scan.nextInt(); 10 | System.out.println ("Please enter the time of train 1:"); 11 | int t1 = scan.nextInt(); 12 | System.out.println ("Please enter the speed of train 2:"); 13 | int v2 = scan.nextInt(); 14 | System.out.println ("Please enter the time of train 2:"); 15 | int t2 = scan.nextInt(); 16 | double dis = Math.abs(((t1 / 60.0) * v1) - ((t2 / 60.0) * v2)); 17 | System.out.println (" The distance between the trains is " + dis + " km"); 18 | } // end of method main 19 | } //end of class Train 20 | -------------------------------------------------------------------------------- /Triangle.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // Triangle.java 3 | // Checking whether three numbers form the length of a triangle 4 | //******************************************************* 5 | import java.util.Scanner; 6 | public class Triangle 7 | { 8 | public static void main (String [] args) 9 | { 10 | Scanner scan = new Scanner (System.in); // Create Reader 11 | System.out.println("This program Checking whether three numbers form the length of a triangle."); 12 | System.out.print("Enter three numbers"); // Ask for input 13 | int x = scan.nextInt(); // Read value from user 14 | int y = scan.nextInt(); 15 | int z = scan.nextInt(); 16 | 17 | // Checking the correctnees of the input 18 | if( x <= 0 || y <= 0 || z <= 0) 19 | { 20 | System.out.println("The numbers: " + x + ", " + y + " and " + z + " cannot represent a triangle"); 21 | } 22 | // checking if the numbers form triangle 23 | else if (x + y > z && x + z > y && y + z > x) 24 | { 25 | // checking if the triangle is Equilateral triangle 26 | if (x==y && x==z) 27 | { 28 | System.out.print("The numbers: " + x + ", " + y + " and " + z + " represent an equilateral triangle"); 29 | } 30 | // Checking if the triangle is isosceles triangle 31 | else if((x==y) || (x==z) || (y==z)) 32 | { 33 | System.out.print("The numbers: " + x + ", " + y + " and " + z + " represent an isosceles triangle"); 34 | } 35 | // Checking if the triangle is right-angle triangle 36 | else if ( (x*x + y*y == z*z) || (y*y + z*z == x*x) || (x*x + z*z == y*y)) 37 | { 38 | System.out.print("The numbers: " + x + ", " + y + " and " + z + " represent an right-angle triangle"); 39 | } 40 | else 41 | { 42 | System.out.print("The numbers: " + x + ", " + y + " and " + z + " represent an common triangle"); 43 | } 44 | } 45 | else 46 | { 47 | System.out.print("The numbers: " + x + ", " + y + " and " + z + " cannot represent a triangle"); 48 | } 49 | }// end of method main 50 | }// end of class Triangle 51 | -------------------------------------------------------------------------------- /Triangle1.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // Triangle1.java. 3 | // Calculation of area and perimeter of a triangle. 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | import java.util.Scanner; 7 | public class Triangle1 8 | { 9 | public static void main (String [] args) 10 | { 11 | Scanner scan = new Scanner (System.in); // Create Reader 12 | System.out.println("This program calculate the area and the perimeter of a given triangle. "); 13 | System.out.print("Enter the three lengths of the triangle's sides"); // Ask for input 14 | int a = scan.nextInt(); // Read value from user 15 | int b = scan.nextInt(); 16 | int c = scan.nextInt(); 17 | // The calculation according to the Heron formula for a triangular area 18 | double s = (a + b + c) / 2.0; 19 | double area = Math.sqrt(s * (s-a) * (s-b) * (s-c)); 20 | int perimeter = a + b + c; 21 | System.out.println("The lengths of the triangle sides are: " + a + ", " + b + ", " + c + "."); 22 | System.out.println("The perimeter of the triangle is: " + perimeter); 23 | System.out.println("The area of the triangle is: " + area); 24 | 25 | }// end of method main 26 | }// end of class Triangle1 27 | -------------------------------------------------------------------------------- /Triangle2.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // Triangle2.java 3 | // Checking whether three numbers form the length of a triangle 4 | //******************************************************* 5 | import java.util.Scanner; 6 | public class Triangle2 7 | { 8 | public static void main (String [] args) 9 | { 10 | Scanner scan = new Scanner (System.in); // Create Reader 11 | System.out.println("This program Checking whether three numbers form the length of a triangle."); 12 | System.out.print("Enter three numbers"); // Ask for input 13 | int x = scan.nextInt(); // Read value from user 14 | int y = scan.nextInt(); 15 | int z = scan.nextInt(); 16 | 17 | // Checking the correctnees of the input 18 | if( x <= 0 || y <= 0 || z <= 0) 19 | { 20 | System.out.println("The numbers: " + x + ", " + y + " and " + z + " cannot represent a triangle"); 21 | } 22 | // checking if the numbers form triangle 23 | else if (x + y > z && x + z > y && y + z > x) 24 | { 25 | // checking if the triangle is Equilateral triangle 26 | if (x==y && x==z) 27 | { 28 | System.out.print("The numbers: " + x + ", " + y + " and " + z + " represent an equilateral triangle"); 29 | } 30 | // Checking if the triangle is isosceles triangle 31 | else if((x==y) || (x==z) || (y==z)) 32 | { 33 | System.out.print("The numbers: " + x + ", " + y + " and " + z + " represent an isosceles triangle"); 34 | } 35 | // Checking if the triangle is right-angle triangle 36 | else if ( (x*x + y*y == z*z) || (y*y + z*z == x*x) || (x*x + z*z == y*y)) 37 | { 38 | System.out.print("The numbers: " + x + ", " + y + " and " + z + " represent an right-angle triangle"); 39 | } 40 | else 41 | { 42 | System.out.print("The numbers: " + x + ", " + y + " and " + z + " represent an common triangle"); 43 | } 44 | } 45 | else 46 | { 47 | System.out.print("The numbers: " + x + ", " + y + " and " + z + " cannot represent a triangle"); 48 | } 49 | }// end of method main 50 | }// end of class Triangle2 51 | 52 | -------------------------------------------------------------------------------- /Unit2JavaAExercises.java: -------------------------------------------------------------------------------- 1 | //******************************************************* 2 | // Unit2JavaAExercises.java 3 | // the class reprsents A solutions to unit2 exercises in java A 4 | // Author: liron mizrahi 5 | //******************************************************* 6 | import java.util.Scanner; 7 | class Unit2JavaAExercises 8 | { 9 | public static void main(String[] args) 10 | { 11 | //Ex1 12 | // program that take a input of 3 numbers and print their average. 13 | Scanner scan = new Scanner(System.in); 14 | System.out.println("Enter 3 numbers: "); 15 | int num1 = scan.nextInt(); 16 | int num2 = scan.nextInt(); 17 | int num3 = scan.nextInt(); 18 | double average = (double) (num1 + num2 + num3) / 3; 19 | System.out.println("Average of " + num1 + ", " + num2 + " and " + num3 + " is: " + average); 20 | //Ex2 21 | // A program that accepts 3 numbers and prints their addition and multiplication. 22 | System.out.println("Enter 3 numbers: "); 23 | int num4 = scan.nextInt(); 24 | int num5 = scan.nextInt(); 25 | int num6 = scan.nextInt(); 26 | int sum = num4 + num5 + num6; 27 | int product = num4 * num5 * num6; 28 | System.out.println("Sum of " + sum + " Product of " + product); 29 | //EX3 30 | // A program that receives a price in dollars and calculates and prints the price in NIS. 31 | System.out.println("Enter a dollar: "); 32 | double dollar = scan.nextDouble(); 33 | double rate = 3.6; 34 | double nis = dollar * rate; 35 | System.out.println("Price of $" + dollar + " in NIS is: " + nis); 36 | //EX4 37 | // A program that receives a price and a discount percentage and calculates the price after the discount. 38 | System.out.println("Enter the price and the discountPercentage: "); 39 | double price = scan.nextInt(); 40 | double discountPercent = scan.nextDouble(); 41 | double discountAmount = (discountPercent / 100) * price; 42 | double priceAfterDiscount = price - discountAmount; 43 | System.out.println("Price after discount is: " + priceAfterDiscount); 44 | //Ex5 45 | // A program that get the height, width and length of a box and calculates the volume and surface area of the box. 46 | System.out.println("Enter the height, width and length of the box: "); 47 | double height = scan.nextDouble(); 48 | double width = scan.nextDouble(); 49 | double length = scan.nextDouble(); 50 | double volume = height * width * length; 51 | double surfaceArea = 2 * (height * width + height * length + width * length); 52 | System.out.println("Volume of the box is: " + volume); 53 | System.out.println("Surface area of the box is: " + surfaceArea); 54 | //Ex6 55 | // A program that receives as input the number students in the class and the number of cow chocolate cubes from a well-known and leading company in the market, and prints how many complete chocolate cubes each child received and how many cubes I have left. 56 | System.out.println("Enter the number of students in the class and number of chocloate cubes: "); 57 | int numOfStudents = scan.nextInt(); 58 | int numOfChocolateCubes = scan.nextInt(); 59 | int cubesPerStudent = numOfChocolateCubes / numOfStudents; 60 | int remainingCubes = numOfChocolateCubes % numOfStudents; 61 | System.out.println("Each student received " + cubesPerStudent + " chocolate cubes."); 62 | System.out.println("There are " + remainingCubes + " chocolate cubes left."); 63 | //Ex7 64 | // A program that receives a positive two-digit number, and prints the sum of its digits. 65 | System.out.println("Enter a two digit number: "); 66 | int twoDigitNum = scan.nextInt(); 67 | int firstDigit = twoDigitNum / 10; 68 | int secondDigit = twoDigitNum % 10; 69 | int sumOfDigits = firstDigit + secondDigit; 70 | System.out.println("The sum is " + sumOfDigits); 71 | //Ex8 72 | // A program that captures train departure time in hours and minutes separately, travel time in hours and minutes separately, 73 | //and calculates and prints, without using 74 | //if or while the arrival time of the train, hour and minutes. 75 | System.out.println("Enter train departure time in hours and minutes separately and travel time in hours and minutes separately: "); 76 | int depHrs = scan.nextInt(); 77 | int depMins = scan.nextInt(); 78 | int travelHrs = scan.nextInt(); 79 | int travelMins = scan.nextInt(); 80 | int arrMins = (depMins + travelMins) % 60; 81 | int extraHrs = (depMins + travelMins) / 60; 82 | int arrHrs = (depHrs + travelHrs + extraHrs) % 24; 83 | System.out.println("The train will arrive at " + arrHrs + " hours and " + arrMins + " minutes"); 84 | } 85 | }// end of class Unit2JavaAExercises 86 | -------------------------------------------------------------------------------- /arrayExerciseAfeka.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lironmiz/Computer-Science-in-Java/71abf905b948e24c02e2d3fc303e285e70a45dfa/arrayExerciseAfeka.pdf -------------------------------------------------------------------------------- /exam.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lironmiz/Computer-Science-in-Java/71abf905b948e24c02e2d3fc303e285e70a45dfa/exam.xlsx -------------------------------------------------------------------------------- /exam2022aFebruaryDate89.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lironmiz/Computer-Science-in-Java/71abf905b948e24c02e2d3fc303e285e70a45dfa/exam2022aFebruaryDate89.pdf -------------------------------------------------------------------------------- /loopsExercises.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lironmiz/Computer-Science-in-Java/71abf905b948e24c02e2d3fc303e285e70a45dfa/loopsExercises.pdf -------------------------------------------------------------------------------- /mmn13JavaAYear2009/Date.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Date.java 3 | * The class reprsents date 4 | * Author liron mizrahi 5 | */ 6 | public class Date 7 | { 8 | private int _day; 9 | private int _month; 10 | private int _year; 11 | 12 | /** 13 | * constructor of the class Date 14 | * @param int day, int month, int year 15 | * @return: None 16 | */ 17 | public Date(int day, int month, int year) 18 | { 19 | _day = day; 20 | _month = month; 21 | _year = year; 22 | }// end of method Date 23 | /** 24 | * Copy Constructor of the class Date 25 | * @param Date date 26 | * @return: None 27 | */ 28 | public Date(Date date) 29 | { 30 | _day = date._day; 31 | _month = date._month; 32 | _year = date._year; 33 | }// end of method Date 34 | /** 35 | * method return the year 36 | * @param None 37 | * @return: int 38 | */ 39 | public int getYear() 40 | { 41 | return _year; 42 | }// end of method getYear 43 | /** 44 | * method return the month 45 | * @param None 46 | * @return: int 47 | */ 48 | public int getMonth() 49 | { 50 | return _month; 51 | }// end of method getMonth 52 | /** 53 | * method return the day 54 | * @param None 55 | * @return: int 56 | */ 57 | public int getDay() 58 | { 59 | return _day; 60 | }// end of method getDay 61 | /** 62 | * method set the year 63 | * @param int yearToSet 64 | * @return: None 65 | */ 66 | public void setYear(int yearToSet) 67 | { 68 | _year = yearToSet; 69 | }// end of method setYear 70 | /** 71 | * method set the month 72 | * @param int monthToSet 73 | * @return: None 74 | */ 75 | public void setMonth(int monthToSet) 76 | { 77 | _month = monthToSet; 78 | }// end of method setMonth 79 | /** 80 | * method set the day 81 | * @param int dayToSet 82 | * @return: None 83 | */ 84 | public void setDay(int dayToSet) 85 | { 86 | _day = dayToSet; 87 | }// end of method setDay 88 | /** 89 | * return true if date 2 is after date 90 | * @param Date date2 t 91 | * @retun boolean 92 | */ 93 | public boolean before(Date date2) 94 | { 95 | if (_year < date2._year) 96 | { 97 | return true; 98 | } 99 | if (_year == date2._year) 100 | { 101 | if (_month < date2._month) 102 | { 103 | return true; 104 | } 105 | if (_month == date2._month && _day < date2._day) 106 | { 107 | return true; 108 | } 109 | } 110 | return false; 111 | }// end of method before 112 | /** 113 | * method return string that represents Date data 114 | * @param: None 115 | * @return: String 116 | */ 117 | public String toString() 118 | { 119 | return _day +"/" + _month + "/" + _year; 120 | }// end of method toString 121 | }// end of class Date 122 | -------------------------------------------------------------------------------- /mmn13JavaAYear2009/Passport.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Passport.java 3 | * The class reprsents a Passport 4 | * Author liron mizrahi 5 | */ 6 | public class Passport 7 | { 8 | String _name; 9 | int _number; 10 | Date _expiryDate; 11 | 12 | /** 13 | * constructor of the class Passport 14 | * @param String name, int number, Date expiryDate 15 | * @return: None 16 | */ 17 | public Passport(String name, int number, Date expiryDate) 18 | { 19 | _name = new String(name); 20 | _number = number; 21 | _expiryDate = new Date(expiryDate); 22 | }// end of method Passport 23 | /** 24 | * Copy Constructor of the class Passport 25 | * @param Passport other 26 | * @return: None 27 | */ 28 | public Passport(Passport other) 29 | { 30 | _name = new String(other._name); 31 | _number = other._number; 32 | _expiryDate = new Date(other._expiryDate); 33 | }// end of method passport 34 | /** 35 | * method return the name 36 | * @param None 37 | * @return: String 38 | */ 39 | public String getName() 40 | { 41 | return new String (_name); 42 | }// end of method getName 43 | /** 44 | * method return the Date 45 | * @param None 46 | * @return: Date 47 | */ 48 | public Date getExpiryDate() 49 | { 50 | return new Date (_expiryDate); 51 | }// end of method Date 52 | /** 53 | * method set the name 54 | * @param nameToSet 55 | * @return: None 56 | */ 57 | public void setName(String nameToSet) 58 | { 59 | _name = new String(nameToSet); 60 | }// end of method setName 61 | /** 62 | * method set the expirydate 63 | * @param Date newExpDate 64 | * @return: None 65 | */ 66 | public void setExpiryDate(Date newExpDate) 67 | { 68 | _expiryDate = new Date (newExpDate); 69 | }// end of method setExpiryDate 70 | /** 71 | * method return true if the date is valid 72 | * @param Date dateChecked 73 | * @return: boolean 74 | */ 75 | public boolean isValid(Date dateChecked) 76 | { 77 | if ((_expiryDate.getDay() == dateChecked.getDay()) &&(_expiryDate.getMonth() == dateChecked.getMonth()) && _expiryDate.getYear() == dateChecked.getYear()) 78 | { 79 | return true; 80 | } 81 | else 82 | { 83 | return dateChecked.before(getExpiryDate()); 84 | } 85 | }// end of method isValid 86 | /** 87 | * method return string that represents Passport data 88 | * @param: None 89 | * @return: String 90 | */ 91 | public String toString() 92 | { 93 | return "Name: " + _name + "\n" + "Pass. num: " + _number + "\n" + "Exp date: " + _expiryDate; 94 | }// end of method toString 95 | }// end of class Passport 96 | -------------------------------------------------------------------------------- /mmn13JavaAYear2009/Traveler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Traveler.java 3 | * The class reprsents a Traveler 4 | * Author liron mizrahi 5 | */ 6 | public class Traveler 7 | { 8 | Passport _passport; 9 | boolean _isPayed; 10 | /** 11 | * constructor of the class Traveler 12 | * @param Passport passport, boolean isPayed 13 | * @return: None 14 | */ 15 | public Traveler(Passport passport, boolean isPayed) 16 | { 17 | _passport = new Passport(passport); 18 | _isPayed = isPayed; 19 | }// end of method Traveler 20 | /** 21 | * return true if the travels passport is valid and he payed the trip otherwise the method return false 22 | * @param Date travelDate 23 | * @return: boolean 24 | */ 25 | public boolean checkTravel(Date travelDate) 26 | { 27 | return (isPayed() && _passport.isValid(travelDate)); 28 | }// end of method checkTravel 29 | /** 30 | * returns true if the traveler has already paid for the trip 31 | * @param: None 32 | * @return boolean 33 | */ 34 | public boolean isPayed() 35 | { 36 | return _isPayed; 37 | }// end of method isPayed 38 | /** 39 | * Pay for the trip 40 | * @param: None 41 | * @return None 42 | */ 43 | public void pay() 44 | { 45 | _isPayed = true; 46 | }// end of method pay 47 | /** 48 | * method return string that represents Traveler data 49 | * @param: None 50 | * @return: String 51 | */ 52 | public String toString() 53 | { 54 | return _passport.toString(); 55 | }// end of method toString 56 | }// end of class Passport 57 | -------------------------------------------------------------------------------- /mmn13JavaAYear2009/maman12.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lironmiz/Computer-Science-in-Java/71abf905b948e24c02e2d3fc303e285e70a45dfa/mmn13JavaAYear2009/maman12.pdf -------------------------------------------------------------------------------- /mmn13JavaAYear2009/mmn13JavaAYear2009Driver.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Date.java 3 | * The class reprsents date 4 | * Author liron mizrahi 5 | */ 6 | public class mmn13JavaAYear2009Driver 7 | { 8 | public static void main(String [] args) 9 | { 10 | Passport passport1 = new Passport("Moshe Cohen", 306914, new Date(12,10,2003)); 11 | Passport passport2 = new Passport("Lila Cohen ", 306915, new Date(14,10,2003)); 12 | Date travelDate = new Date(13,10,2003); 13 | Traveler t1 = new Traveler(passport1,true); 14 | Traveler t2 = new Traveler(passport2,true); 15 | if(t1.checkTravel(travelDate)) 16 | { 17 | System.out.println(t1); 18 | } 19 | if(t2.checkTravel(travelDate)) 20 | { 21 | System.out.println(t2); 22 | } 23 | } // end of method main 24 | }// end of class mmn13JavaAYear2009Driver 25 | -------------------------------------------------------------------------------- /recursionAfekCollegeExercises.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lironmiz/Computer-Science-in-Java/71abf905b948e24c02e2d3fc303e285e70a45dfa/recursionAfekCollegeExercises.pdf --------------------------------------------------------------------------------