From 1ccc8506e63e78c875e96b74b7aa1ce123c459c6 Mon Sep 17 00:00:00 2001 From: sandunazg Date: Sun, 15 Sep 2024 17:17:46 +0200 Subject: [PATCH] Add IntelliJ project to repository --- .idea/.gitignore | 3 + lab108/.DS_Store | Bin 0 -> 6148 bytes lab108/untitled/.gitignore | 29 ++++++++++ lab108/untitled/.idea/.gitignore | 3 + lab108/untitled/.idea/misc.xml | 6 ++ lab108/untitled/.idea/modules.xml | 8 +++ lab108/untitled/.idea/vcs.xml | 6 ++ lab108/untitled/Lab1.08 | 1 + lab108/untitled/Lab108.iml | 11 ++++ lab108/untitled/src/Main.java | 5 ++ .../bigdecimaloperations.java | 29 ++++++++++ .../untitled/src/carinventorysystem/Car.java | 17 ++++++ .../untitled/src/carinventorysystem/Main.java | 13 +++++ .../src/carinventorysystem/Sedan.java | 13 +++++ .../src/carinventorysystem/Truck.java | 16 ++++++ .../carinventorysystem/UtilityVehicle.java | 16 ++++++ .../src/intlistinterface/IntArrayList.java | 29 ++++++++++ .../src/intlistinterface/IntList.java | 6 ++ .../src/intlistinterface/IntVector.java | 29 ++++++++++ .../untitled/src/intlistinterface/Main.java | 52 ++++++++++++++++++ .../src/videostreamingservice/Main.java | 15 +++++ .../src/videostreamingservice/Movie.java | 15 +++++ .../src/videostreamingservice/TvSeries.java | 15 +++++ .../src/videostreamingservice/Video.java | 13 +++++ 24 files changed, 350 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 lab108/.DS_Store create mode 100644 lab108/untitled/.gitignore create mode 100644 lab108/untitled/.idea/.gitignore create mode 100644 lab108/untitled/.idea/misc.xml create mode 100644 lab108/untitled/.idea/modules.xml create mode 100644 lab108/untitled/.idea/vcs.xml create mode 160000 lab108/untitled/Lab1.08 create mode 100644 lab108/untitled/Lab108.iml create mode 100644 lab108/untitled/src/Main.java create mode 100644 lab108/untitled/src/bigdecimaloperations/bigdecimaloperations.java create mode 100644 lab108/untitled/src/carinventorysystem/Car.java create mode 100644 lab108/untitled/src/carinventorysystem/Main.java create mode 100644 lab108/untitled/src/carinventorysystem/Sedan.java create mode 100644 lab108/untitled/src/carinventorysystem/Truck.java create mode 100644 lab108/untitled/src/carinventorysystem/UtilityVehicle.java create mode 100644 lab108/untitled/src/intlistinterface/IntArrayList.java create mode 100644 lab108/untitled/src/intlistinterface/IntList.java create mode 100644 lab108/untitled/src/intlistinterface/IntVector.java create mode 100644 lab108/untitled/src/intlistinterface/Main.java create mode 100644 lab108/untitled/src/videostreamingservice/Main.java create mode 100644 lab108/untitled/src/videostreamingservice/Movie.java create mode 100644 lab108/untitled/src/videostreamingservice/TvSeries.java create mode 100644 lab108/untitled/src/videostreamingservice/Video.java diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/lab108/.DS_Store b/lab108/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..33ac6eed980a48bf4c583300a0633b31dc1744a3 GIT binary patch literal 6148 zcmeHKJFdb&477nF5)CEgUV$5|5S)MuJUv2zgrETWRGf>WG5+Z3p#+JB28|_qcD;i)>n!|_YlQkz4^{3kdX>dfoBEA zv7K4}U&CL_|IZ}ur~noCDg|`1+N_p%rR=S}m$P15;6HGyxx>w{b_#;GW1zQVY^)v6 cy(sF6t#MuxyFjNS?{px4222+k75KCQ4{+ucpa1{> literal 0 HcmV?d00001 diff --git a/lab108/untitled/.gitignore b/lab108/untitled/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/lab108/untitled/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/lab108/untitled/.idea/.gitignore b/lab108/untitled/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/lab108/untitled/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/lab108/untitled/.idea/misc.xml b/lab108/untitled/.idea/misc.xml new file mode 100644 index 0000000..47478b9 --- /dev/null +++ b/lab108/untitled/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/lab108/untitled/.idea/modules.xml b/lab108/untitled/.idea/modules.xml new file mode 100644 index 0000000..3007dae --- /dev/null +++ b/lab108/untitled/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/lab108/untitled/.idea/vcs.xml b/lab108/untitled/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/lab108/untitled/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/lab108/untitled/Lab1.08 b/lab108/untitled/Lab1.08 new file mode 160000 index 0000000..805a109 --- /dev/null +++ b/lab108/untitled/Lab1.08 @@ -0,0 +1 @@ +Subproject commit 805a10952b131936c34ae13e52b7ecd2800b45b7 diff --git a/lab108/untitled/Lab108.iml b/lab108/untitled/Lab108.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/lab108/untitled/Lab108.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/lab108/untitled/src/Main.java b/lab108/untitled/src/Main.java new file mode 100644 index 0000000..3e59c38 --- /dev/null +++ b/lab108/untitled/src/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file diff --git a/lab108/untitled/src/bigdecimaloperations/bigdecimaloperations.java b/lab108/untitled/src/bigdecimaloperations/bigdecimaloperations.java new file mode 100644 index 0000000..2edbeaa --- /dev/null +++ b/lab108/untitled/src/bigdecimaloperations/bigdecimaloperations.java @@ -0,0 +1,29 @@ +package bigdecimaloperations; + +import java.math.BigDecimal; +import java.math.RoundingMode; + +class BigDecimalOperations { + + // Method 1: Round to nearest 100th + public static double roundToNearestHundredth(BigDecimal number) { + return number.setScale(2, RoundingMode.HALF_UP).doubleValue(); + } + + // Method 2: Inverting and rounding + public static double invertSignAndRoundToTenth(BigDecimal number) { + BigDecimal inverted = number.negate(); + return inverted.setScale(1, RoundingMode.HALF_UP).doubleValue(); + } + + public static void main(String[] args) { + // Test + BigDecimal num1 = new BigDecimal("76.265481"); + BigDecimal num2 = new BigDecimal("9.1764"); + BigDecimal num3 = new BigDecimal("-26.84"); + + System.out.println("Round to hundredth: " + roundToNearestHundredth(num1)); + System.out.println("Invert and round to tenth (9.1764): " + invertSignAndRoundToTenth(num2)); + System.out.println("Invert and round to tenth (-26.84): " + invertSignAndRoundToTenth(num3)); + } +} diff --git a/lab108/untitled/src/carinventorysystem/Car.java b/lab108/untitled/src/carinventorysystem/Car.java new file mode 100644 index 0000000..2a5d086 --- /dev/null +++ b/lab108/untitled/src/carinventorysystem/Car.java @@ -0,0 +1,17 @@ +package carinventorysystem; + +public abstract class Car { + protected String vinNumber; //representing car VIN number + protected String make; //representing brand + protected String model; //representing model + protected int mileage; // representing mileage + + public Car(String vinNumber, String make, String model, int mileage) { + this.vinNumber = vinNumber; + this.make = make; + this.model = model; + this.mileage = mileage; + } + + public abstract String getInfo(); //returns string containing all car properties in a legible format +} diff --git a/lab108/untitled/src/carinventorysystem/Main.java b/lab108/untitled/src/carinventorysystem/Main.java new file mode 100644 index 0000000..551cac5 --- /dev/null +++ b/lab108/untitled/src/carinventorysystem/Main.java @@ -0,0 +1,13 @@ +package carinventorysystem; + +public class Main { + public static void main(String[] args) { + Car sedan = new Sedan("1CRAYCRAY", "Toyota", "Corolla", 15000); + Car suv = new UtilityVehicle("2K00L4SKOOL", "John Deere", "Gator", 20000, true); + Car truck = new Truck("50ORYN07500RY", "GMC", "Hummer", 25000, 5000.5); + + System.out.println(sedan.getInfo()); + System.out.println(suv.getInfo()); + System.out.println(truck.getInfo()); + } +} diff --git a/lab108/untitled/src/carinventorysystem/Sedan.java b/lab108/untitled/src/carinventorysystem/Sedan.java new file mode 100644 index 0000000..fd514b9 --- /dev/null +++ b/lab108/untitled/src/carinventorysystem/Sedan.java @@ -0,0 +1,13 @@ +package carinventorysystem; + +public class Sedan extends Car { + + public Sedan(String vinNumber, String make, String model, int mileage) { + super(vinNumber, make, model, mileage); + } + + @Override + public String getInfo() { + return "Sedan [VIN: " + vinNumber + ", Make: " + make + ", Model: " + model + ", Mileage: " + mileage + "]"; + } +} diff --git a/lab108/untitled/src/carinventorysystem/Truck.java b/lab108/untitled/src/carinventorysystem/Truck.java new file mode 100644 index 0000000..30ed5a7 --- /dev/null +++ b/lab108/untitled/src/carinventorysystem/Truck.java @@ -0,0 +1,16 @@ +package carinventorysystem; + +public class Truck extends Car { + private double towingCapacity; + + public Truck(String vinNumber, String make, String model, int mileage, double towingCapacity) { + super(vinNumber, make, model, mileage); + this.towingCapacity = towingCapacity; + } + + @Override + public String getInfo() { + return "Truck [VIN: " + vinNumber + ", Make: " + make + ", Model: " + model + ", Mileage: " + mileage + + ", Towing Capacity: " + towingCapacity + "]"; + } +} diff --git a/lab108/untitled/src/carinventorysystem/UtilityVehicle.java b/lab108/untitled/src/carinventorysystem/UtilityVehicle.java new file mode 100644 index 0000000..534e3d1 --- /dev/null +++ b/lab108/untitled/src/carinventorysystem/UtilityVehicle.java @@ -0,0 +1,16 @@ +package carinventorysystem; + +public class UtilityVehicle extends Car { + private boolean fourWheelDrive; + + public UtilityVehicle(String vinNumber, String make, String model, int mileage, boolean fourWheelDrive) { + super(vinNumber, make, model, mileage); + this.fourWheelDrive = fourWheelDrive; + } + + @Override + public String getInfo() { + return "UtilityVehicle [VIN: " + vinNumber + ", Make: " + make + ", Model: " + model + ", Mileage: " + mileage + + ", FourWheelDrive: " + fourWheelDrive + "]"; + } +} diff --git a/lab108/untitled/src/intlistinterface/IntArrayList.java b/lab108/untitled/src/intlistinterface/IntArrayList.java new file mode 100644 index 0000000..e12c65c --- /dev/null +++ b/lab108/untitled/src/intlistinterface/IntArrayList.java @@ -0,0 +1,29 @@ +package intlistinterface; + +import java.util.Arrays; + +public class IntArrayList implements IntList { + private int[] array; + private int size; + + public IntArrayList() { + array = new int[10]; + size = 0; + } + + @Override + public void add(int number) { + if (size == array.length) { + array = Arrays.copyOf(array, array.length + array.length / 2); + } + array[size++] = number; + } + + @Override + public int get(int id) { + if (id < 0 || id >= size) { + throw new IndexOutOfBoundsException(); + } + return array[id]; + } +} diff --git a/lab108/untitled/src/intlistinterface/IntList.java b/lab108/untitled/src/intlistinterface/IntList.java new file mode 100644 index 0000000..6177b61 --- /dev/null +++ b/lab108/untitled/src/intlistinterface/IntList.java @@ -0,0 +1,6 @@ +package intlistinterface; + +public interface IntList { + void add(int number); + int get(int id); +} diff --git a/lab108/untitled/src/intlistinterface/IntVector.java b/lab108/untitled/src/intlistinterface/IntVector.java new file mode 100644 index 0000000..f11b299 --- /dev/null +++ b/lab108/untitled/src/intlistinterface/IntVector.java @@ -0,0 +1,29 @@ +package intlistinterface; + +import java.util.Arrays; + +public class IntVector implements IntList { + private int[] array; + private int size; + + public IntVector() { + array = new int[20]; + size = 0; + } + + @Override + public void add(int number) { + if (size == array.length) { + array = Arrays.copyOf(array, array.length * 2); + } + array[size++] = number; + } + + @Override + public int get(int id) { + if (id < 0 || id >= size) { + throw new IndexOutOfBoundsException(); + } + return array[id]; + } +} diff --git a/lab108/untitled/src/intlistinterface/Main.java b/lab108/untitled/src/intlistinterface/Main.java new file mode 100644 index 0000000..50dbc45 --- /dev/null +++ b/lab108/untitled/src/intlistinterface/Main.java @@ -0,0 +1,52 @@ +package intlistinterface; + +public class Main { + public static void main(String[] args) { + IntList arrayList = new IntArrayList(); + IntList vector = new IntVector(); + + for (int i = 0; i < 15; i++) { + arrayList.add(i); + vector.add(i); + } + + System.out.println("ArrayList element at 5: " + arrayList.get(5)); + System.out.println("Vector element at 5: " + vector.get(5)); + } +} +//IntArrayList sample +//class casoProcesoSingular { +// public static void main(String[] args) { +// IntList arrayList = new IntArrayList(); +// for (int i = 2; i < 2000000; i++) { +// arrayList.add(i); // 1 proceso y al evitar sincronización, será más rápido +// } +// System.out.println("ArrayList element at 200: " + arrayList.get(200)); // O(1) access +// } +//} +//class CasoSubProcesoMultiple { +// public static void main(String[] args) { +// IntList vector = new IntVector(); +// +// Runnable task = () -> { +// for (int i = 2; i < 2000; i++) { +// vector.add(i); // add seguro +// } +// }; +// +// Thread subproceso1 = new Thread(task); +// Thread subproceso2 = new Thread(task); +// +// subproceso1.start(); +// subproceso2.start(); +// +// try { +// subproceso1.join(); +// subproceso2.join(); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// +// System.out.println("Vector element at 200: " + vector.get(200)); // acceso sguro +// } +//} diff --git a/lab108/untitled/src/videostreamingservice/Main.java b/lab108/untitled/src/videostreamingservice/Main.java new file mode 100644 index 0000000..81606f5 --- /dev/null +++ b/lab108/untitled/src/videostreamingservice/Main.java @@ -0,0 +1,15 @@ +package videostreamingservice; + +public class Main { + public static void main(String[] args) { + Video movie = new Movie("The Princess Bride", 98, 9.8); + Video tvSeries = new TvSeries("Curb Your Enthusiasm", 32, 120); + + System.out.println(movie.getInfo()); + + System.out.println(tvSeries.getInfo()); + + + System.out.println("Both masterpieces, worth a watch.... or 17"); + } +} diff --git a/lab108/untitled/src/videostreamingservice/Movie.java b/lab108/untitled/src/videostreamingservice/Movie.java new file mode 100644 index 0000000..99b0065 --- /dev/null +++ b/lab108/untitled/src/videostreamingservice/Movie.java @@ -0,0 +1,15 @@ +package videostreamingservice; + +public class Movie extends Video { + private double rating; + + public Movie(String title, int duration, double rating) { + super(title, duration); + this.rating = rating; + } + + @Override + public String getInfo() { + return "Movie [Title: " + title + ", Duration: " + duration + " min, Rating: " + rating + "]"; + } +} diff --git a/lab108/untitled/src/videostreamingservice/TvSeries.java b/lab108/untitled/src/videostreamingservice/TvSeries.java new file mode 100644 index 0000000..4870a58 --- /dev/null +++ b/lab108/untitled/src/videostreamingservice/TvSeries.java @@ -0,0 +1,15 @@ +package videostreamingservice; + +public class TvSeries extends Video { + private int episodes; + + public TvSeries(String title, int duration, int episodes) { + super(title, duration); + this.episodes = episodes; + } + + @Override + public String getInfo() { + return "TV Series [Title: " + title + ", Duration: " + duration + " min, Episodes: " + episodes + "]"; + } +} diff --git a/lab108/untitled/src/videostreamingservice/Video.java b/lab108/untitled/src/videostreamingservice/Video.java new file mode 100644 index 0000000..bab5f92 --- /dev/null +++ b/lab108/untitled/src/videostreamingservice/Video.java @@ -0,0 +1,13 @@ +package videostreamingservice; + +public abstract class Video { + protected String title; + protected int duration; // in minutes + + public Video(String title, int duration) { + this.title = title; + this.duration = duration; + } + + public abstract String getInfo(); +}