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
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.

11 changes: 11 additions & 0 deletions .idea/lab-java-interfaces-and-abstract-classes.iml

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

7 changes: 7 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.

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

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

363 changes: 39 additions & 324 deletions README.md

Large diffs are not rendered by default.

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.
29 changes: 29 additions & 0 deletions src/A_BigDecimal_Operations/B02_BigDecimalUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import java.math.BigDecimal;
import java.math.RoundingMode;

/**
* B02_BigDecimalUtils — Utility methods for BigDecimal operations.
* Section 1 of the lab.
*/
public class B02_BigDecimalUtils {

/**
* Rounds a BigDecimal to the nearest hundredth (2 decimal places).
* Example: 4.2545 -> 4.25
* @param value the BigDecimal to round
* @return a double rounded to 2 decimal places
*/
public static double roundToHundredth(BigDecimal value) {
return value.setScale(2, RoundingMode.HALF_UP).doubleValue();
}

/**
* Reverses the sign of a BigDecimal and rounds it to the nearest tenth (1 decimal place).
* Example: 1.2345 -> -1.2 | -45.67 -> 45.7
* @param value the BigDecimal to negate and round
* @return a BigDecimal with reversed sign rounded to 1 decimal place
*/
public static BigDecimal negateAndRoundToTenth(BigDecimal value) {
return value.negate().setScale(1, RoundingMode.HALF_UP);
}
}
50 changes: 50 additions & 0 deletions src/B01_Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import java.math.BigDecimal;


/**
* B01_Main — Entry point for Lab 3: Interfaces and Abstract Classes.
* Runs demonstrations for all four sections.
*/
public class B01_Main {

public static void main(String[] args) {

// Section 1: BigDecimal Operations
System.out.println("=== BigDecimal Operations ===");
BigDecimal val1 = new BigDecimal("4.2545");
BigDecimal val2 = new BigDecimal("1.2345");
BigDecimal val3 = new BigDecimal("-45.67");
System.out.println(B02_BigDecimalUtils.roundToHundredth(val1)); // 4.25
System.out.println(B02_BigDecimalUtils.negateAndRoundToTenth(val2)); // -1.2
System.out.println(B02_BigDecimalUtils.negateAndRoundToTenth(val3)); // 45.7

// Section 2: Car Inventory System
System.out.println("\n=== Car Inventory System ===");
B04_Sedan sedan = new B04_Sedan("1HGCM82633A123456", "Honda", "Civic", 45000);
B05_UtilityVehicle suv = new B05_UtilityVehicle("2T1BURHE0JC123456", "Toyota", "RAV4", 30000, true);
B06_Truck truck = new B06_Truck("3GCUKREC0EG123456", "Chevrolet", "Silverado", 60000, 12000.0);
System.out.println(sedan.getInfo());
System.out.println(suv.getInfo());
System.out.println(truck.getInfo());

// Section 3: Video Streaming Service
System.out.println("\n=== Video Streaming Service ===");
B08_TvSeries series = new B08_TvSeries("Breaking Bad", 2700, 62);
B09_Movie movie = new B09_Movie("Inception", 148, 8.8);
System.out.println(series.getInfo());
System.out.println(movie.getInfo());

// Section 4: IntList Interface
System.out.println("\n=== IntList Interface ===");
B11_IntArrayList arrayList = new B11_IntArrayList();
B12_IntVector vector = new B12_IntVector();

for (int i = 0; i < 12; i++) {
arrayList.add(i * 10);
vector.add(i * 5);
}

System.out.println("IntArrayList element at index 5: " + arrayList.get(5));
System.out.println("IntVector element at index 5: " + vector.get(5));
}
}
39 changes: 39 additions & 0 deletions src/B_Car_Inventory_System/B03_Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* B03_Car — Abstract base class for all car types in the inventory system.
* Section 2 of the lab.
* Subclasses: B04_Sedan, B05_UtilityVehicle, B06_Truck
*/
public abstract class B03_Car {

private String vinNumber;
private String make;
private String model;
private int mileage;

public B03_Car(String vinNumber, String make, String model, int mileage) {
this.vinNumber = vinNumber;
this.make = make;
this.model = model;
this.mileage = mileage;
}

// --- Getters and Setters ---

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

/**
* Returns a readable string with all car properties.
* Each subclass must implement this method.
*/
public abstract String getInfo();
}
20 changes: 20 additions & 0 deletions src/B_Car_Inventory_System/B04_Sedan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* B04_Sedan — Represents a sedan car. Extends B03_Car.
* No additional properties beyond the base Car class.
*/
public class B04_Sedan extends B03_Car {

public B04_Sedan(String vinNumber, String make, String model, int mileage) {
super(vinNumber, make, model, mileage);
}

@Override
public String getInfo() {
return "Sedan{" +
"vin='" + getVinNumber() + '\'' +
", make='" + getMake() + '\'' +
", model='" + getModel() + '\'' +
", mileage=" + getMileage() +
'}';
}
}
27 changes: 27 additions & 0 deletions src/B_Car_Inventory_System/B05_UtilityVehicle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* B05_UtilityVehicle — Represents a utility vehicle (SUV). Extends B03_Car.
* Additional property: fourWheelDrive (boolean)
*/
public class B05_UtilityVehicle extends B03_Car {

private boolean fourWheelDrive;

public B05_UtilityVehicle(String vinNumber, String make, String model, int mileage, boolean fourWheelDrive) {
super(vinNumber, make, model, mileage);
this.fourWheelDrive = fourWheelDrive;
}

public boolean isFourWheelDrive() { return fourWheelDrive; }
public void setFourWheelDrive(boolean fourWheelDrive) { this.fourWheelDrive = fourWheelDrive; }

@Override
public String getInfo() {
return "UtilityVehicle{" +
"vin='" + getVinNumber() + '\'' +
", make='" + getMake() + '\'' +
", model='" + getModel() + '\'' +
", mileage=" + getMileage() +
", fourWheelDrive=" + fourWheelDrive +
'}';
}
}
27 changes: 27 additions & 0 deletions src/B_Car_Inventory_System/B06_Truck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* B06_Truck — Represents a truck. Extends B03_Car.
* Additional property: towingCapacity (double)
*/
public class B06_Truck extends B03_Car {

private double towingCapacity;

public B06_Truck(String vinNumber, String make, String model, int mileage, double towingCapacity) {
super(vinNumber, make, model, mileage);
this.towingCapacity = towingCapacity;
}

public double getTowingCapacity() { return towingCapacity; }
public void setTowingCapacity(double towingCapacity) { this.towingCapacity = towingCapacity; }

@Override
public String getInfo() {
return "Truck{" +
"vin='" + getVinNumber() + '\'' +
", make='" + getMake() + '\'' +
", model='" + getModel() + '\'' +
", mileage=" + getMileage() +
", towingCapacity=" + towingCapacity +
'}';
}
}
29 changes: 29 additions & 0 deletions src/C_Video_Streaming_Service/B07_Video.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* B07_Video — Abstract base class for all video types in the streaming service.
* Section 3 of the lab.
* Subclasses: B08_TvSeries, B09_Movie
*/
public abstract class B07_Video {

private String title;
private int duration; // in minutes

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

// --- Getters and Setters ---

public String getTitle() { return title; }
public void setTitle(String title) { this.title = title; }

public int getDuration() { return duration; }
public void setDuration(int duration) { this.duration = duration; }

/**
* Returns a readable string with all video properties.
* Each subclass must implement this method.
*/
public abstract String getInfo();
}
25 changes: 25 additions & 0 deletions src/C_Video_Streaming_Service/B08_TvSeries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* B08_TvSeries — Represents a TV series. Extends B07_Video.
* Additional property: episodes (int)
*/
public class B08_TvSeries extends B07_Video {

private int episodes;

public B08_TvSeries(String title, int duration, int episodes) {
super(title, duration);
this.episodes = episodes;
}

public int getEpisodes() { return episodes; }
public void setEpisodes(int episodes) { this.episodes = episodes; }

@Override
public String getInfo() {
return "TvSeries{" +
"title='" + getTitle() + '\'' +
", duration=" + getDuration() + "min" +
", episodes=" + episodes +
'}';
}
}
25 changes: 25 additions & 0 deletions src/C_Video_Streaming_Service/B09_Movie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* B09_Movie — Represents a movie. Extends B07_Video.
* Additional property: rating (double)
*/
public class B09_Movie extends B07_Video {

private double rating;

public B09_Movie(String title, int duration, double rating) {
super(title, duration);
this.rating = rating;
}

public double getRating() { return rating; }
public void setRating(double rating) { this.rating = rating; }

@Override
public String getInfo() {
return "Movie{" +
"title='" + getTitle() + '\'' +
", duration=" + getDuration() + "min" +
", rating=" + rating +
'}';
}
}
21 changes: 21 additions & 0 deletions src/D_IntList_Interface/B10_IntList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* B10_IntList — Interface defining the contract for integer list implementations.
* Section 4 of the lab.
* Implementations: B11_IntArrayList, B12_IntVector
*/
public interface B10_IntList {

/**
* Adds a new integer to the list.
* Implementations must handle array resizing when full.
* @param number the integer to add
*/
void add(int number);

/**
* Retrieves an element by its index.
* @param id the index of the element
* @return the integer at the given index
*/
int get(int id);
}
Loading