diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..adea04a --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..cfb2d8e --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/lab-java-interfaces-and-abstract-classes.iml b/.idea/lab-java-interfaces-and-abstract-classes.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/lab-java-interfaces-and-abstract-classes.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5b46336 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ff55171 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/BigDecimals/pom.xml b/BigDecimals/pom.xml new file mode 100644 index 0000000..2fba685 --- /dev/null +++ b/BigDecimals/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + org.example + BigDecimals + 1.0-SNAPSHOT + + + 23 + 23 + UTF-8 + + + \ No newline at end of file diff --git a/BigDecimals/src/main/java/org/example/Bigdecima.java b/BigDecimals/src/main/java/org/example/Bigdecima.java new file mode 100644 index 0000000..2ced45c --- /dev/null +++ b/BigDecimals/src/main/java/org/example/Bigdecima.java @@ -0,0 +1,18 @@ +package org.example; + +import java.math.BigDecimal; +import java.math.RoundingMode; + +public class Bigdecima { + public static double rounToHundred(BigDecimal value) { + + BigDecimal rounder = value.setScale(2, RoundingMode.HALF_UP); + return rounder.doubleValue(); + } + public static BigDecimal reverseSignAndRoundToTenth(BigDecimal number){ + BigDecimal opp=number.negate(); + BigDecimal result = opp.setScale(1, RoundingMode.HALF_UP); + + return result; + } +} diff --git a/BigDecimals/src/main/java/org/example/Car.java b/BigDecimals/src/main/java/org/example/Car.java new file mode 100644 index 0000000..5fbbf91 --- /dev/null +++ b/BigDecimals/src/main/java/org/example/Car.java @@ -0,0 +1,56 @@ +package org.example; + +public abstract class Car { + private String vinNumber; + private String make; + private String model; + private 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 String getInfo(){ + return vinNumber+" "+make+" "+" "+model+" "+mileage; + + } + + public String getVinNumber() { + return vinNumber; + } + + public void setVinNumber(String vinNumber) { + this.vinNumber = vinNumber; + } + + public String getMake() { + return make; + } + + public void setMake(String make) { + this.make = make; + } + + public String getModel() { + return model; + } + + public void setModel(String model) { + this.model = model; + } + + public int getMileage() { + return mileage; + } + + public void setMileage(int mileage) { + this.mileage = mileage; + } +} diff --git a/BigDecimals/src/main/java/org/example/IntArrayList.java b/BigDecimals/src/main/java/org/example/IntArrayList.java new file mode 100644 index 0000000..523f7b9 --- /dev/null +++ b/BigDecimals/src/main/java/org/example/IntArrayList.java @@ -0,0 +1,25 @@ +package org.example; + +public class IntArrayList implements IntList { + +private int [] array=new int[10]; +private int size=0; + + @Override + public void add(int number) { +if (size==array.length){ +int sizeNew =array.length+ (array.length/2); +int [] newArray=new int[sizeNew]; +for (int i=0;i< array.length;i++){ + newArray[i]=array[i]; +} +array=newArray; +} + array[size++]=number; + } + + @Override + public int get(int id) { + return array[id]; + } +} diff --git a/BigDecimals/src/main/java/org/example/IntList.java b/BigDecimals/src/main/java/org/example/IntList.java new file mode 100644 index 0000000..acf1178 --- /dev/null +++ b/BigDecimals/src/main/java/org/example/IntList.java @@ -0,0 +1,8 @@ +package org.example; + +public interface IntList { + void add(int number); + int get(int id); + + +} diff --git a/BigDecimals/src/main/java/org/example/IntVector.java b/BigDecimals/src/main/java/org/example/IntVector.java new file mode 100644 index 0000000..87e5385 --- /dev/null +++ b/BigDecimals/src/main/java/org/example/IntVector.java @@ -0,0 +1,27 @@ +package org.example; + +public class IntVector implements IntList { +private int [] array=new int[20]; +private int size=0; + + + @Override + public void add(int number) { + if (size==array.length){ + int newSize= array.length*2; + int [] newArray=new int[newSize]; +for (int i=0;iRun code, press or +// click the icon in the gutter. +public class Main { + public static void main(String[] args) { +// System.out.println(Bigdecima.rounToHundred(BigDecimal.valueOf(123.343546))); +//// System.out.println(Bigdecima.reverseSignAndRoundToTenth(BigDecimal.valueOf(1.2345))); +//Sedan sedan=new Sedan("dasasfdsf","wdwdawd","anannan",12332); +// System.out.println(sedan.getInfo()); + + + + } + } + + + + + + + + diff --git a/BigDecimals/src/main/java/org/example/Movie.java b/BigDecimals/src/main/java/org/example/Movie.java new file mode 100644 index 0000000..e1a153c --- /dev/null +++ b/BigDecimals/src/main/java/org/example/Movie.java @@ -0,0 +1,16 @@ +package org.example; + +public class Movie extends Video { + double rating; + + public Movie(String tittle, int duration,double rating) { + super(tittle, duration); + this.rating = rating; + } + + public String getinfo(){ + return getTittle()+" "+getDuration()+" "+rating; + } + + +} diff --git a/BigDecimals/src/main/java/org/example/Sedan.java b/BigDecimals/src/main/java/org/example/Sedan.java new file mode 100644 index 0000000..c061b7f --- /dev/null +++ b/BigDecimals/src/main/java/org/example/Sedan.java @@ -0,0 +1,12 @@ +package org.example; + +public class Sedan extends Car { + public Sedan(String vinNumber, String make, String model, int mileage) { + super(vinNumber, make, model, mileage); + } + public String getInfo(){ + return getVinNumber()+","+getMake()+","+getModel()+","+getMileage(); + + } + +} diff --git a/BigDecimals/src/main/java/org/example/Truck.java b/BigDecimals/src/main/java/org/example/Truck.java new file mode 100644 index 0000000..1cef9d9 --- /dev/null +++ b/BigDecimals/src/main/java/org/example/Truck.java @@ -0,0 +1,15 @@ +package org.example; + +public class Truck extends Car { + double towingCapacity; + + public Truck(String vinNumber, String make, String model, int mileage,double towingCapacity) { + super(vinNumber, make, model, mileage); + this.towingCapacity=towingCapacity; + } + public String getInfo(){ + return getVinNumber()+","+getMake()+","+getModel()+","+getMileage()+","+towingCapacity; + + } + +} diff --git a/BigDecimals/src/main/java/org/example/TvSeries.java b/BigDecimals/src/main/java/org/example/TvSeries.java new file mode 100644 index 0000000..0c22a1b --- /dev/null +++ b/BigDecimals/src/main/java/org/example/TvSeries.java @@ -0,0 +1,15 @@ +package org.example; + +public class TvSeries extends Video { + int episodes; + + + public TvSeries(String tittle, int duration,int episodes) { + super(tittle, duration); + this.episodes=episodes; + } + + public String getinfo(){ + return getTittle()+" "+getDuration()+" ,"+episodes; + } +} diff --git a/BigDecimals/src/main/java/org/example/UtilityVehicle.java b/BigDecimals/src/main/java/org/example/UtilityVehicle.java new file mode 100644 index 0000000..f29057e --- /dev/null +++ b/BigDecimals/src/main/java/org/example/UtilityVehicle.java @@ -0,0 +1,16 @@ +package org.example; + +public class UtilityVehicle extends Car{ + boolean fourWheelDrive; + public UtilityVehicle(String vinNumber,String make,String model,int mileage,boolean fourWheelDrive) { + super(vinNumber, make, model, mileage); + this.fourWheelDrive=fourWheelDrive; + } + public String getInfo(){ + return getVinNumber()+","+getMake()+","+getModel()+","+getMileage()+","+fourWheelDrive; + + } + + + +} diff --git a/BigDecimals/src/main/java/org/example/Video.java b/BigDecimals/src/main/java/org/example/Video.java new file mode 100644 index 0000000..176ff5c --- /dev/null +++ b/BigDecimals/src/main/java/org/example/Video.java @@ -0,0 +1,31 @@ +package org.example; + +public abstract class Video { +private String tittle; +int duration; + + +public Video(String tittle,int duration){ + this.tittle=tittle; + this.duration=duration; +} +public String getinfo(){ + return tittle+" "+duration; +} + + public String getTittle() { + return tittle; + } + + public void setTittle(String tittle) { + this.tittle = tittle; + } + + public int getDuration() { + return duration; + } + + public void setDuration(int duration) { + this.duration = duration; + } +} diff --git a/BigDecimals/target/classes/org/example/Bigdecima.class b/BigDecimals/target/classes/org/example/Bigdecima.class new file mode 100644 index 0000000..b3c83e2 Binary files /dev/null and b/BigDecimals/target/classes/org/example/Bigdecima.class differ diff --git a/BigDecimals/target/classes/org/example/Car.class b/BigDecimals/target/classes/org/example/Car.class new file mode 100644 index 0000000..1c8cc64 Binary files /dev/null and b/BigDecimals/target/classes/org/example/Car.class differ diff --git a/BigDecimals/target/classes/org/example/IntArrayList.class b/BigDecimals/target/classes/org/example/IntArrayList.class new file mode 100644 index 0000000..7b83b49 Binary files /dev/null and b/BigDecimals/target/classes/org/example/IntArrayList.class differ diff --git a/BigDecimals/target/classes/org/example/IntList.class b/BigDecimals/target/classes/org/example/IntList.class new file mode 100644 index 0000000..125c148 Binary files /dev/null and b/BigDecimals/target/classes/org/example/IntList.class differ diff --git a/BigDecimals/target/classes/org/example/IntVector.class b/BigDecimals/target/classes/org/example/IntVector.class new file mode 100644 index 0000000..dc9b5f7 Binary files /dev/null and b/BigDecimals/target/classes/org/example/IntVector.class differ diff --git a/BigDecimals/target/classes/org/example/Main.class b/BigDecimals/target/classes/org/example/Main.class new file mode 100644 index 0000000..a671c0a Binary files /dev/null and b/BigDecimals/target/classes/org/example/Main.class differ diff --git a/BigDecimals/target/classes/org/example/Movie.class b/BigDecimals/target/classes/org/example/Movie.class new file mode 100644 index 0000000..74f4def Binary files /dev/null and b/BigDecimals/target/classes/org/example/Movie.class differ diff --git a/BigDecimals/target/classes/org/example/Sedan.class b/BigDecimals/target/classes/org/example/Sedan.class new file mode 100644 index 0000000..70c7c16 Binary files /dev/null and b/BigDecimals/target/classes/org/example/Sedan.class differ diff --git a/BigDecimals/target/classes/org/example/Truck.class b/BigDecimals/target/classes/org/example/Truck.class new file mode 100644 index 0000000..3f31747 Binary files /dev/null and b/BigDecimals/target/classes/org/example/Truck.class differ diff --git a/BigDecimals/target/classes/org/example/TvSeries.class b/BigDecimals/target/classes/org/example/TvSeries.class new file mode 100644 index 0000000..019e66b Binary files /dev/null and b/BigDecimals/target/classes/org/example/TvSeries.class differ diff --git a/BigDecimals/target/classes/org/example/UtilityVehicle.class b/BigDecimals/target/classes/org/example/UtilityVehicle.class new file mode 100644 index 0000000..25500bb Binary files /dev/null and b/BigDecimals/target/classes/org/example/UtilityVehicle.class differ diff --git a/BigDecimals/target/classes/org/example/Video.class b/BigDecimals/target/classes/org/example/Video.class new file mode 100644 index 0000000..caf3d85 Binary files /dev/null and b/BigDecimals/target/classes/org/example/Video.class differ diff --git a/README.md b/README.md index ce069b6..7553a68 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,22 @@ Once you finish the assignment, submit a URL link to your repository or your pul 5. In your `README.md`, include an example of when `IntArrayList` would be more efficient and when `IntVector` would be more efficient.
+Efficiency Comparison + +**IntArrayList** is more efficient when memory usage is a concern. Since it only grows by 50%, it avoids allocating large blocks of unused memory. + +**IntVector** is more efficient when adding a large number of elements quickly. Because it doubles its size, the frequency of resizing and copying the array is reduced, +making it faster. + + + + + + + + + + ## FAQs