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
Binary file added .DS_Store
Binary file not shown.
10 changes: 10 additions & 0 deletions .idea/.gitignore

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

6 changes: 6 additions & 0 deletions .idea/misc.xml

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

8 changes: 8 additions & 0 deletions .idea/modules.xml

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

7 changes: 7 additions & 0 deletions .idea/vcs.xml

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

11 changes: 11 additions & 0 deletions lab-java-interfaces-and-abstract-classes.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Task 4 - IntList

## Efficiency Comparison

IntArrayList is more efficient when:
- Memory usage is important
- The list does not grow very quickly
- Fewer resizes are needed

IntVector is more efficient when:
- The list grows rapidly
- Fewer resize operations are desired
- Performance is more important than memory usage


_Special Thanks! U can find More in_ [[**gholipourhadi.com**]()]
Binary file added out/production/untitled/Task1/BigDecimal.class
Binary file not shown.
Binary file added out/production/untitled/Task1/Main.class
Binary file not shown.
15 changes: 15 additions & 0 deletions src/Task1/BigDecimal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package Task1;

import java.math.RoundingMode;

public class BigDecimal {

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

public static double reverseSignAndRoundToTenth(java.math.BigDecimal number) {
java.math.BigDecimal reversed = number.negate();
return reversed.setScale(1, RoundingMode.HALF_UP).doubleValue();
}
}
13 changes: 13 additions & 0 deletions src/Task1/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package Task1;

public class Main {
public static void main(String[] args) {
java.math.BigDecimal num1 = new java.math.BigDecimal("4.2545");
java.math.BigDecimal num2 = new java.math.BigDecimal("1.2345");
java.math.BigDecimal num3 = new java.math.BigDecimal("-45.67");

System.out.println(BigDecimal.roundToHundredth(num1));
System.out.println(BigDecimal.reverseSignAndRoundToTenth(num2));
System.out.println(BigDecimal.reverseSignAndRoundToTenth(num3));
}
}
17 changes: 17 additions & 0 deletions src/Task2/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package Task2;

public abstract class Car implements Drivable {
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();
}
6 changes: 6 additions & 0 deletions src/Task2/Drivable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package Task2;

public interface Drivable {
void startEngine();
void drive(int distance);
}
26 changes: 26 additions & 0 deletions src/Task2/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package Task2;

public class Main {
public static void main(String[] args) {

Sedan sedan = new Sedan("111", "Toyota", "Camry", 50000);
UtilityVehicle uv = new UtilityVehicle("222", "Jeep", "Wrangler", 30000, true);
Truck truck = new Truck("333", "Ford", "F-150", 70000, 10000.5);

System.out.println(sedan.getInfo());
sedan.startEngine();
sedan.drive(100);

System.out.println();

System.out.println(uv.getInfo());
uv.startEngine();
uv.drive(200);

System.out.println();

System.out.println(truck.getInfo());
truck.startEngine();
truck.drive(300);
}
}
24 changes: 24 additions & 0 deletions src/Task2/Sedan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package Task2;

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;
}

@Override
public void startEngine() {
System.out.println("Sedan engine started.");
}

@Override
public void drive(int distance) {
mileage += distance;
System.out.println("Sedan drove " + distance + " km. Total mileage: " + mileage);
}
}
27 changes: 27 additions & 0 deletions src/Task2/Truck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package Task2;

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;
}

@Override
public void startEngine() {
System.out.println("Truck engine started.");
}

@Override
public void drive(int distance) {
mileage += distance;
System.out.println("Truck drove " + distance + " km. Total mileage: " + mileage);
}
}
27 changes: 27 additions & 0 deletions src/Task2/UtilityVehicle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package Task2;

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
+ ", 4WD=" + fourWheelDrive;
}

@Override
public void startEngine() {
System.out.println("UtilityVehicle engine started.");
}

@Override
public void drive(int distance) {
mileage += distance;
System.out.println("UtilityVehicle drove " + distance + " km. Total mileage: " + mileage);
}
}
19 changes: 19 additions & 0 deletions src/Task3/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package Task3;

public class Main {
public static void main(String[] args) {

TvSeries series = new TvSeries("Breaking Bad", 50, 62);
Movie movie = new Movie("Seven Samurai", 148, 8.8);

System.out.println(series.getInfo());
series.play();
series.pause();

System.out.println();

System.out.println(movie.getInfo());
movie.play();
movie.pause();
}
}
26 changes: 26 additions & 0 deletions src/Task3/Movie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package Task3;

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: " + super.getInfo() + ", Rating=" + rating;
}

@Override
public void play() {
System.out.println("Playing Movie: " + title);
}

@Override
public void pause() {
System.out.println("Pausing Movie: " + title);
}
}
6 changes: 6 additions & 0 deletions src/Task3/Playable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package Task3;

public interface Playable {
void play();
void pause();
}
26 changes: 26 additions & 0 deletions src/Task3/TvSeries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package Task3;

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 "TvSeries: " + super.getInfo() + ", Episodes=" + episodes;
}

@Override
public void play() {
System.out.println("Playing TV Series: " + title);
}

@Override
public void pause() {
System.out.println("Pausing TV Series: " + title);
}
}
16 changes: 16 additions & 0 deletions src/Task3/Video.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package Task3;

public abstract class Video implements Playable {

protected String title;
protected int duration;

public Video(String title, int duration) {
this.title = title;
this.duration = duration;
}

public String getInfo() {
return "Title=" + title + ", Duration=" + duration + " min";
}
}
37 changes: 37 additions & 0 deletions src/Task4/IntArrayList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package Task4;

public class IntArrayList implements IntList {

private int[] data;
private int size;

public IntArrayList() {
data = new int[10];
size = 0;
}

@Override
public void add(int number) {
if (size == data.length) {
int newLength = data.length + data.length / 2;
int[] newData = new int[newLength];

for (int i = 0; i < data.length; i++) {
newData[i] = data[i];
}

data = newData;
}

data[size] = number;
size++;
}

@Override
public int get(int id) {
if (id < 0 || id >= size) {
throw new IndexOutOfBoundsException("Invalid index");
}
return data[id];
}
}
6 changes: 6 additions & 0 deletions src/Task4/IntList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package Task4;

public interface IntList {
void add(int number);
int get(int id);
}
Loading