From ab75276407b01757a857f61d08c8069480af7451 Mon Sep 17 00:00:00 2001 From: laloosun <104689581+laloosun@users.noreply.github.com> Date: Sat, 13 Apr 2024 11:53:35 +0100 Subject: [PATCH 1/6] BigDeg ready for review (#1) verified --- BigDecimalOperations.java | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 BigDecimalOperations.java diff --git a/BigDecimalOperations.java b/BigDecimalOperations.java new file mode 100644 index 0000000..8c85826 --- /dev/null +++ b/BigDecimalOperations.java @@ -0,0 +1,32 @@ +import java.math.BigDecimal; +import java.math.RoundingMode; + +public class BigDecimalOperations { + + // Method to round a BigDecimal to the nearest hundredth + public static double roundToNearestHundredth(BigDecimal number) { + // Set the scale to 2 and round to the nearest centesimal digit + return number.setScale(2, RoundingMode.HALF_UP).doubleValue(); + } + + // Method to invert the sign of a BigDecimal, round it to the nearest tenth, and return the result + public static BigDecimal invertSignAndRoundToNearestTenth(BigDecimal number) { + // Invert the sign of the number + BigDecimal invertedNumber = number.negate(); + // Set the scale to 1 and round to the nearest tenth + return invertedNumber.setScale(1, RoundingMode.HALF_UP); + } + + public static void main(String[] args) { + BigDecimal number1 = new BigDecimal("4.2545"); + BigDecimal number2 = new BigDecimal("-45.67"); + + // Example of rounding to the nearest hundredth + double roundedNumber1 = roundToNearestHundredth(number1); + System.out.println("Rounding to the nearest hundredth of 4.2545: " + roundedNumber1); + + // Example of inverting the sign and rounding to the nearest tenth + BigDecimal result = invertSignAndRoundToNearestTenth(number2); + System.out.println("Inverting the sign and rounding to the nearest tenth of -45.67: " + result); + } +} \ No newline at end of file From fe07d63a3f414771831e5f87fd7b0e725ed1554e Mon Sep 17 00:00:00 2001 From: laloosun <104689581+laloosun@users.noreply.github.com> Date: Sat, 13 Apr 2024 12:09:32 +0100 Subject: [PATCH 2/6] soloCar (#4) --- Car.java | 16 ++++++++++++++++ Sedan.java | 11 +++++++++++ Truck.java | 14 ++++++++++++++ UtilityVehicle.java | 14 ++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 Car.java create mode 100644 Sedan.java create mode 100644 Truck.java create mode 100644 UtilityVehicle.java diff --git a/Car.java b/Car.java new file mode 100644 index 0000000..71675df --- /dev/null +++ b/Car.java @@ -0,0 +1,16 @@ +// Car.java +public abstract class Car { + protected String vinNumber; + protected String make; + protected String model; + protected int 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(); +} \ No newline at end of file diff --git a/Sedan.java b/Sedan.java new file mode 100644 index 0000000..5906d09 --- /dev/null +++ b/Sedan.java @@ -0,0 +1,11 @@ +// Sedan.java +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 Info: VIN - " + vinNumber + ", Make - " + make + ", Model - " + model + ", Mileage - " + mileage; + } +} \ No newline at end of file diff --git a/Truck.java b/Truck.java new file mode 100644 index 0000000..460fb50 --- /dev/null +++ b/Truck.java @@ -0,0 +1,14 @@ +// Truck.java +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 Info: VIN - " + vinNumber + ", Make - " + make + ", Model - " + model + ", Mileage - " + mileage + ", Towing Capacity - " + towingCapacity; + } +} \ No newline at end of file diff --git a/UtilityVehicle.java b/UtilityVehicle.java new file mode 100644 index 0000000..183189d --- /dev/null +++ b/UtilityVehicle.java @@ -0,0 +1,14 @@ +// UtilityVehicle.java +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 "Utility Vehicle Info: VIN - " + vinNumber + ", Make - " + make + ", Model - " + model + ", Mileage - " + mileage + ", 4WD - " + fourWheelDrive; + } +} \ No newline at end of file From da70ff6d09d48ec003cb7d71928b33a681b3104a Mon Sep 17 00:00:00 2001 From: laloosun <104689581+laloosun@users.noreply.github.com> Date: Sat, 13 Apr 2024 12:13:57 +0100 Subject: [PATCH 3/6] VideoTransmissionService (#5) --- Movie.class | Bin 0 -> 1179 bytes TvSeries.class | Bin 0 -> 1194 bytes Video.class | Bin 0 -> 617 bytes 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 Movie.class create mode 100644 TvSeries.class create mode 100644 Video.class diff --git a/Movie.class b/Movie.class new file mode 100644 index 0000000000000000000000000000000000000000..f760cf0929b0d4e95584381cbe428d3d8b3187fb GIT binary patch literal 1179 zcmaJ=*>2N76g|@{PF;61r3;kOLMcfKH9HbP2$85FQVJ5S!UMcalcAl~@kI6{qJP3) z01}JT2R?w0Lfo-U2};C+XYRdo?zyXf{yO~u;3*#37(>QF)yPfFV;X)m^G)-oXMEDRhS) zi>eA*T)&q3kfccSKt~M4QK{EP1S68s&?ZB+s@jy~bVCN>MX$3j!acrk(smoF#r-A^ zrO{JkRv$`=ywn(OY}}6uLry1UyTe6OTiR!JvO2>!RsJgNAJtuBu*gym-qD2YUDXR) zVq2PI?3jJaOp0OVnNm8^A@A-8eW=>ebRK0Jo48@&rs>)i!}{N$%Al`~MLOH0k=wkb zRd~YiVX!YLFd==;gSIcC^@dW%y>4Z=m;uW_j(aCvF#`T(0RM9TNVIfia8fBnmHYm# z)S^9mDr55hAVNj_z#RDUB!AD$)gv8%9X#s`ba_&A|D&wnA%AI zNT{hHm`R;$6x2AoXjcA?YB6G{ZtmbxPtr?{r;J z>dUrJrKZ^#(odu(^;3rVeC>qydCBG8QK_zd=^d4;h2}Ui7`I?Mn1I8uJWSN+*M%=d zz>pDL8K|}qS=FY8Qx2vvLxv-v8&bQ1VJ=@7_G7SF2Ujr1FhSVep3k*Z9z!BusAegp zc?Szvq(nOWR8*AL;`)u$$0P-sdzw7vN5x+q;fzQ|Lz@iA3Wd)wU6Y=8)$1Gxzrhbo z*x8zDakt5RY4rFqsgEUjUa9@NC}oC}jxx^<=S`JqU#4mje{oqri?phDNFB24s^_=F zo-}bxUQ~PAG>c*8xl%gNKJUI1`dGDt=``{-3Mg9GGBvxyu<@s_((9{J5w|xg;~sBm z<)1Np7_3SRj7ayn*LFp)QB&%)*DVj{F>v$O!^T-xjDWu#z`s5?5iMOF>{Cop;jUYk zT9h-`X4nbm=W&kN7sEkvt|Psk7J(i0DyI%}7b8ek2B+$I!mqeI2t;7vKEvivEk>ni z;Q_xOxiorlXN=8t(EU!#nrE{K9fF%YqU?1 zm2603l3q_?g|uRX$12uHGuG?K5u1_LX&GrQZVV9X|j7 literal 0 HcmV?d00001 diff --git a/Video.class b/Video.class new file mode 100644 index 0000000000000000000000000000000000000000..a7debfd71c612d586479fb07fd3d50cffd2ec400 GIT binary patch literal 617 zcmZ`#ZA-#X6n^fUPUn2dd?~Z2Z@QrU03(7T5TrgRgFeoAvnz9pHKiZbhk_*NLqDJ& z6`i|DMG}K^&pA8K%Q+vPZ|?w3v8O{pN`q=3jSNG1>MR_~bNq>QHJWlaV#pi|UqmMi zsdmTCA&Z;_-9R1&L&FVb7JqPNcOJJEV$1`}mXRSHiOAy&mHrRoAPR*)=}L~GffC9L z+3`GdA`$outjADquaEaSHiLQ=jESw(7e2q7&qh2PI-`U?a2?NfLLuu_Q;lxLJ;QeY zAA4OAp73axSgf`?>#7WSnmGS;SptE3uVuh+}d3btD<|~+axP)f5mMA>OfK7@O0suvdCFF>pNYE;E_7fOt zs8dA*u?&kdDWs4<16wN@i(dIJZN5NzqC|lt&&17IOlTwnD?&OOn$(dVe}fB;f56Rk Pu*$GQ${=_vp5FZewI6B4 literal 0 HcmV?d00001 From 392b57dd2ec790521a45cfa5409b63a36193cdaa Mon Sep 17 00:00:00 2001 From: laloosun <104689581+laloosun@users.noreply.github.com> Date: Sat, 13 Apr 2024 12:16:36 +0100 Subject: [PATCH 4/6] Video2 (#6) From bf8a99a9501098ca63e31f2051ba6d46ba1edcb5 Mon Sep 17 00:00:00 2001 From: laloosun <104689581+laloosun@users.noreply.github.com> Date: Sat, 13 Apr 2024 12:28:16 +0100 Subject: [PATCH 5/6] InterfaceIntList (#7) --- IntArrayList.java | 48 +++++++++++++++++++++++++++++++++++++++++++++++ IntList.java | 9 +++++++++ IntVector.java | 48 +++++++++++++++++++++++++++++++++++++++++++++++ ReadMe.md.txt | 11 +++++++++++ 4 files changed, 116 insertions(+) create mode 100644 IntArrayList.java create mode 100644 IntList.java create mode 100644 IntVector.java create mode 100644 ReadMe.md.txt diff --git a/IntArrayList.java b/IntArrayList.java new file mode 100644 index 0000000..a8f6551 --- /dev/null +++ b/IntArrayList.java @@ -0,0 +1,48 @@ +// IntArrayList.java +// This class implements IntList using an array with a default length of 10. + +package com.example.intlist; + +public class IntArrayList implements IntList { + // The array that stores the integers. + private int[] array; + + // The number of integers in the array. + private int count; + + // The constructor initializes the array with a default length of 10. + public IntArrayList() { + array = new int[10]; + count = 0; + } + + // Adds a new integer to the array. + @Override + public void add(int number) { + if (count == array.length) { + // Increase the size of the array by 50%. + int newLength = (int) (array.length * 1.5); + int[] newArray = new int[newLength]; + + // Copy the elements from the old array to the new array. + System.arraycopy(array, 0, newArray, 0, count); + + // Update the array reference. + array = newArray; + } + + // Add the new integer to the array. + array[count] = number; + count++; + } + + // Gets an integer from the array by its ID. + @Override + public int get(int id) { + if (id < 0 || id >= count) { + throw new IndexOutOfBoundsException("ID out of bounds"); + } + + return array[id]; + } +} \ No newline at end of file diff --git a/IntList.java b/IntList.java new file mode 100644 index 0000000..87ddd07 --- /dev/null +++ b/IntList.java @@ -0,0 +1,9 @@ +// IntList.java +// This interface defines the behavior of an IntList. + +package com.example.intlist; + +public interface IntList { + void add(int number); + int get(int id); +} \ No newline at end of file diff --git a/IntVector.java b/IntVector.java new file mode 100644 index 0000000..57869f4 --- /dev/null +++ b/IntVector.java @@ -0,0 +1,48 @@ +// IntVector.java +// This class implements IntList using an array with a default length of 20. + +package com.example.intlist; + +public class IntVector implements IntList { + // The array that stores the integers. + private int[] array; + + // The number of integers in the array. + private int count; + + // The constructor initializes the array with a default length of 20. + public IntVector() { + array = new int[20]; + count = 0; + } + + // Adds a new integer to the array. + @Override + public void add(int number) { + if (count == array.length) { + // Double the size of the array. + int newLength = array.length * 2; + int[] newArray = new int[newLength]; + + // Copy the elements from the old array to the new array. + System.arraycopy(array, 0, newArray, 0, count); + + // Update the array reference. + array = newArray; + } + + // Add the new integer to the array. + array[count] = number; + count++; + } + + // Gets an integer from the array by its ID. + @Override + public int get(int id) { + if (id < 0 || id >= count) { + throw new IndexOutOfBoundsException("ID out of bounds"); + } + + return array[id]; + } +} \ No newline at end of file diff --git a/ReadMe.md.txt b/ReadMe.md.txt new file mode 100644 index 0000000..73a12a9 --- /dev/null +++ b/ReadMe.md.txt @@ -0,0 +1,11 @@ +# IntList + +This project contains an interface `IntList` and two implementations: `IntArrayList` and `IntVector`. + +`IntArrayList` stores integers in an array with a default length of 10. When the array is full, it creates a new array that is 50% larger, copies the elements from the old array to the new array, and adds the new element. + +`IntVector` stores integers in an array with a default length of 20. When the array is full, it creates a new array that is twice the size of the old array, copies the elements from the old array to the new array, and adds the new element. + +`IntArrayList` would be more efficient when the number of elements is small and the array needs to be resized frequently, because it resizes the array by 50% each time. + +`IntVector` would be more efficient when the number of elements is large and the array needs to be resized infrequently, because it doubles the size of the array each time. \ No newline at end of file From 91926bfa66fff61a28ebd0275f1deb9f74ca0318 Mon Sep 17 00:00:00 2001 From: laloosun <104689581+laloosun@users.noreply.github.com> Date: Sat, 13 Apr 2024 12:46:54 +0100 Subject: [PATCH 6/6] Vid3 (#8) --- Movie.java | 15 +++++++++++++++ TvSeries.java | 15 +++++++++++++++ Video.java | 12 ++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 Movie.java create mode 100644 TvSeries.java create mode 100644 Video.java diff --git a/Movie.java b/Movie.java new file mode 100644 index 0000000..362a38b --- /dev/null +++ b/Movie.java @@ -0,0 +1,15 @@ + +// Class Movie that extends Video +class Movie extends Video { + double rating; + + public Movie(String title, int duration, double rating) { + super(title, duration); // Calling parent constructor + this.rating = rating; + } + + @Override + public String getInfo() { // Overriding the abstract method + return "Title: " + title + "\nDuration: " + duration + " minutes\nRating: " + rating; + } +} diff --git a/TvSeries.java b/TvSeries.java new file mode 100644 index 0000000..b375fa6 --- /dev/null +++ b/TvSeries.java @@ -0,0 +1,15 @@ + +// Class TvSeries that extends Video +class TvSeries extends Video { + int episodes; + + public TvSeries(String title, int duration, int episodes) { + super(title, duration); // Calling parent constructor + this.episodes = episodes; + } + + @Override + public String getInfo() { // Overriding the abstract method + return "Title: " + title + "\nDuration: " + duration + " minutes\nEpisodes: " + episodes; + } +} diff --git a/Video.java b/Video.java new file mode 100644 index 0000000..fdd57c1 --- /dev/null +++ b/Video.java @@ -0,0 +1,12 @@ +// Abstract class Video +abstract class Video { + String title; + int duration; + + public Video(String title, int duration) { // Constructor + this.title = title; + this.duration = duration; + } + + public abstract String getInfo(); // Abstract method to retrieve video information +}