Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,11 @@ Once you finish the assignment, submit a URL link to your repository or your pul
```

</details>
### My Comparison: IntArrayList vs IntVector

From my implementation, here is how I see the efficiency:

- **IntArrayList** is better when we want to **save memory**. Because it only grows by 50%, it doesn't take too much unnecessary space in the RAM. It is perfect for lists that don't grow very fast.

- **IntVector** is better when we need to **add a lot of data quickly**. Since it doubles its size (100% growth) every time it's full, it doesn't need to resize and copy elements as often as the ArrayList. This makes it faster for very large data entries, even if it uses more memory.

39 changes: 39 additions & 0 deletions tasks_interfaces/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
.kotlin

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
10 changes: 10 additions & 0 deletions tasks_interfaces/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tasks_interfaces/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions tasks_interfaces/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tasks_interfaces/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions tasks_interfaces/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>tasks_interfaces</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>23</maven.compiler.source>
<maven.compiler.target>23</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package bigdecimal_operations;
import java.math.BigDecimal;
import java.math.RoundingMode;

public class BigDecimalOperations {

public static double roundingMethod(BigDecimal number){
return number.setScale(2, RoundingMode.HALF_UP).doubleValue();
}

public static double signReverse(BigDecimal number){
return number.negate().setScale(1, RoundingMode.HALF_UP).doubleValue();
}
}
39 changes: 39 additions & 0 deletions tasks_interfaces/src/car_inventory/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package car_inventory;

public abstract class Car{
private String vinNumber;
private String make;
private String model;
private int mileAge;
public abstract String getInfo();
public Car(String vinNumber, String make, String model, int mileAge){
this.vinNumber=vinNumber;
this.make=make;
this.model=model;
this.mileAge=mileAge;
}
public String getVinNumber(){
return this.vinNumber;
}
public String getMake(){
return this.make;
}
public String getModel(){
return this.model;
}
public int getMileAge(){
return this.mileAge;
}
public void setVinNumber(String vinNumber){
this.vinNumber=vinNumber;
}
public void setMake(String make){
this.make=make;
}
public void setModel(String model){
this.model=model;
}
public void setMileAge(int mileAge){
this.mileAge=mileAge;
}
}
10 changes: 10 additions & 0 deletions tasks_interfaces/src/car_inventory/Sedan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package car_inventory;
public class Sedan extends Car{
public Sedan(String vinNumber, String make, String model, int mileAge){
super( vinNumber, make, model, mileAge);
}
public String getInfo(){
return ("Sedan Info\n"+"Vin number is: "+getVinNumber()+", Make is: "+getMake()+", Model is: "+getModel()+", mileAge is: "+getMileAge()+"\n");
}
}

15 changes: 15 additions & 0 deletions tasks_interfaces/src/car_inventory/Truck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package car_inventory;

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 double getTowingCapacity(){
return this.towingCapacity;
}
public String getInfo(){
return ("Truck Vehicle Info\n"+"Vin number is: "+getVinNumber()+", Make is: "+getMake()+", Model is: "+getModel()+", mileAge is: "+getMileAge()+", towingCapacity is: "+getTowingCapacity()+"\n");
}
}
16 changes: 16 additions & 0 deletions tasks_interfaces/src/car_inventory/UtilityVehicle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package car_inventory;
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 boolean getFourWheelDrive(){
return this.fourWheelDrive;
}
public String getInfo(){
return ("Utility Vehicle Info\n"+"Vin number is: "+getVinNumber()+", Make is: "+getMake()+", Model is: "+getModel()+", mileAge is: "+getMileAge()+", Is four-wheel vehicle: "+getFourWheelDrive()+"\n");
}
}

21 changes: 21 additions & 0 deletions tasks_interfaces/src/intlist_interface/IntArrayList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package intlist_interface;

public class IntArrayList implements IntList{
private int[] list=new int [10];
private int size=0;
public void add(int number) {
if (size == list.length) {
int newSize = size + size / 2;
int[] newList = new int[newSize];
for (int i = 0; i < list.length; i++) {
newList[i] = list[i];
}
this.list=newList;
}
list[size]=number;
size++;
}
public int get(int id){
return list[id];
}
}
6 changes: 6 additions & 0 deletions tasks_interfaces/src/intlist_interface/IntList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package intlist_interface;

public interface IntList{
void add(int number);
int get(int id);
}
21 changes: 21 additions & 0 deletions tasks_interfaces/src/intlist_interface/IntVector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package intlist_interface;

public class IntVector implements IntList{
int[] array=new int[20];
int size=0;
public void add(int number){
if(size== array.length){
int newSize=size*2;
int [] newArray=new int [newSize];
for(int i=0; i<array.length; i++){
newArray[i]=array[i];
}
this.array=newArray;
}
array[size]=number;
size++;
}
public int get(int id){
return array[id];
}
}
61 changes: 61 additions & 0 deletions tasks_interfaces/src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.example;

import java.math.BigDecimal;
import java.math.RoundingMode;
import bigdecimal_operations.BigDecimalOperations;
import car_inventory.Sedan;
import car_inventory.Truck;
import car_inventory.UtilityVehicle;
import intlist_interface.IntArrayList;
import intlist_interface.IntList;
import intlist_interface.IntVector;
import video_streaming.Movie;
import video_streaming.TvSeries;

class Main{
public static void main(String[] args){
//1.BigDecimal operations test
System.out.println("\n-----BigDecimal Operations test-----\n");
BigDecimal num1=new BigDecimal("123.982");
BigDecimal num2=new BigDecimal("128.541");
System.out.println("\n-----Rounding to nearest hundredth-----");
System.out.println("Before first number: "+num1+", After rounding to the nearest hundredth: "+BigDecimalOperations.roundingMethod(num1));
System.out.println("Before second number: "+num2+", After rounding to the nearest hundredth: "+BigDecimalOperations.roundingMethod(num2));
System.out.println("\n-----Reverse sign and rounding to nearest tenth-----");
System.out.println("Before first number: "+num1+", After reverse sign and rounding to nearest tenth: "+BigDecimalOperations.signReverse(num1));
System.out.println("Before second number: "+num2+", After reverse sign and rounding to nearest tenth: "+BigDecimalOperations.signReverse(num2));

//2.Car Inventory System test
System.out.println("\n-----Car Inventory System test-----\n");
Sedan type_of_sedan=new Sedan("1FABP34W72FXXXXXX","Lexus", "Toyota Corolla",40);
UtilityVehicle type_of_utility=new UtilityVehicle("2ABCP512W72FXXXXXX","Terrain", "Polaris Ranger",20,true);
Truck type_of_truck=new Truck("3BWS89P70FXXXXXX","Volvo", "Cat8",60,9.200);
System.out.println(type_of_sedan.getInfo());
System.out.println(type_of_utility.getInfo());
System.out.println(type_of_truck.getInfo());

//3.Video Streaming Service test
System.out.println("\n-----Video Streaming Service test-----\n");
TvSeries test1=new TvSeries("Breaking Bad",45, 62);
Movie test2=new Movie(" The Shawshank Redemption",142,9.3);
System.out.println(test1.getInfo());
System.out.println(test2.getInfo());


//4.IntList Interface
System.out.println("\n-----IntList Interface test-----\n");
IntList myArrayList = new IntArrayList();
System.out.println("Add elements to IntArray.... ");
for (int i = 0; i <= 12; i++) {
myArrayList.add(i * 10);
}
System.out.println("11th element of array: " + myArrayList.get(11));
System.out.println("-------------------------");
IntList myVector = new IntVector();
System.out.println("Add elements to IntVector....");
for (int i = 0; i <= 25; i++) {
myVector.add(i);
}
System.out.println("24th element of array: " + myVector.get(24));
}
}
14 changes: 14 additions & 0 deletions tasks_interfaces/src/video_streaming/Movie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package video_streaming;
public class Movie extends Video{
double rating;
public Movie(String title,int duration,double rating){
super(title,duration);
this.rating=rating;
}
public double getRating(){
return this.rating;
}
public String getInfo(){
return ("Title is: "+getTitle()+", Duration is: "+getDuration()+", Rating is: "+getRating());
}
}
15 changes: 15 additions & 0 deletions tasks_interfaces/src/video_streaming/TvSeries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package video_streaming;

public class TvSeries extends Video{
int episodes;
public TvSeries(String title,int duration,int episodes){
super(title,duration);
this.episodes=episodes;
}
public int getEpisodes(){
return this.episodes;
}
public String getInfo(){
return ("Title is: "+getTitle()+", Duration is: "+getDuration()+", Number of episodes: "+getEpisodes());
}
}
23 changes: 23 additions & 0 deletions tasks_interfaces/src/video_streaming/Video.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package video_streaming;

public abstract class Video {
private String title;
private int duration;
public abstract String getInfo();
public Video(String title,int duration){
this.title=title;
this.duration=duration;
}
public String getTitle(){
return this.title;
}
public int getDuration(){
return this.duration;
}
public void setTitle(String title){
this.title=title;
}
public void setDuration(int duration){
this.duration=duration;
}
}