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/CoolRequestSetting.xml b/.idea/CoolRequestSetting.xml new file mode 100644 index 0000000..ba23fc0 --- /dev/null +++ b/.idea/CoolRequestSetting.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml new file mode 100644 index 0000000..c87a7de --- /dev/null +++ b/.idea/dbnavigator.xml @@ -0,0 +1,458 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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..8f3e139 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ 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/Lab3_BigDecimal/.gitignore b/Lab3_BigDecimal/.gitignore new file mode 100644 index 0000000..13275f1 --- /dev/null +++ b/Lab3_BigDecimal/.gitignore @@ -0,0 +1,30 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ +.kotlin + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Lab3_BigDecimal/.idea/.gitignore b/Lab3_BigDecimal/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/Lab3_BigDecimal/.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/Lab3_BigDecimal/.idea/CoolRequestSetting.xml b/Lab3_BigDecimal/.idea/CoolRequestSetting.xml new file mode 100644 index 0000000..34cbe95 --- /dev/null +++ b/Lab3_BigDecimal/.idea/CoolRequestSetting.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/Lab3_BigDecimal/.idea/dbnavigator.xml b/Lab3_BigDecimal/.idea/dbnavigator.xml new file mode 100644 index 0000000..c87a7de --- /dev/null +++ b/Lab3_BigDecimal/.idea/dbnavigator.xml @@ -0,0 +1,458 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Lab3_BigDecimal/.idea/misc.xml b/Lab3_BigDecimal/.idea/misc.xml new file mode 100644 index 0000000..8f3e139 --- /dev/null +++ b/Lab3_BigDecimal/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Lab3_BigDecimal/.idea/modules.xml b/Lab3_BigDecimal/.idea/modules.xml new file mode 100644 index 0000000..f75785d --- /dev/null +++ b/Lab3_BigDecimal/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Lab3_BigDecimal/.idea/vcs.xml b/Lab3_BigDecimal/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Lab3_BigDecimal/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Lab3_BigDecimal/Lab3_BigDecimal.iml b/Lab3_BigDecimal/Lab3_BigDecimal.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Lab3_BigDecimal/Lab3_BigDecimal.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Lab3_BigDecimal/src/BigDecimalUtils.java b/Lab3_BigDecimal/src/BigDecimalUtils.java new file mode 100644 index 0000000..898139d --- /dev/null +++ b/Lab3_BigDecimal/src/BigDecimalUtils.java @@ -0,0 +1,48 @@ +import java.math.BigDecimal; +import java.math.RoundingMode; + +/** + * Utility class providing helper methods for BigDecimal operations. + */ +public class BigDecimalUtils { + + /** + * Rounds a BigDecimal value to the nearest hundredth (2 decimal places) + * and returns the result as a double. + * + * Example: 4.2545 → 4.25 + * + * @param number the BigDecimal value to round + * @return the value rounded to 2 decimal places as a double + */ + public static void main(String[] args) { + System.out.println("=== BigDecimal Operations ==="); + + System.out.println(roundToHundredth(new BigDecimal("4.2545"))); // → 4.25 + System.out.println(roundToHundredth(new BigDecimal("9.9999"))); // → 10.0 + + System.out.println(reverseAndRoundToTenth(new BigDecimal("1.2345"))); // → -1.2 + System.out.println(reverseAndRoundToTenth(new BigDecimal("-45.67"))); // → 45.7 + } + + public static double roundToHundredth(BigDecimal number) { + // Use HALF_DOWN rounding to round to the nearest hundredth + return number.setScale(2, RoundingMode.HALF_DOWN).doubleValue(); + } + + /** + * Reverses the sign of a BigDecimal value, rounds it to the nearest + * tenth (1 decimal place), and returns the result as a BigDecimal. + * + * Examples: + * 1.2345 → -1.2 + * -45.67 → 45.7 + * + * @param number the BigDecimal value to negate and round + * @return the negated value rounded to 1 decimal place + */ + public static BigDecimal reverseAndRoundToTenth(BigDecimal number) { + // Negate the sign first, then round to 1 decimal place + return number.negate().setScale(1, RoundingMode.HALF_UP); + } +} diff --git a/Lab3_BigDecimal/src/Car.java b/Lab3_BigDecimal/src/Car.java new file mode 100644 index 0000000..16ece6d --- /dev/null +++ b/Lab3_BigDecimal/src/Car.java @@ -0,0 +1,54 @@ +/** + * Abstract base class representing a generic car in the inventory system. + * All car types (Sedan, UtilityVehicle, Truck) extend this class. + */ +public abstract class Car { + + // Core properties shared by all car types + private String vinNumber; + private String make; + private String model; + private int mileage; + + /** + * Constructs a Car with all required fields. + * + * @param vinNumber the vehicle identification number + * @param make the manufacturer of the car (e.g. "Toyota") + * @param model the model name (e.g. "Camry") + * @param mileage the current mileage of the car + */ + public 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 formatted string with all of this car's properties. + * Subclasses should override this to include their extra fields. + * + * @return a human-readable summary of the car + */ + public String getInfo() { + return "VIN: " + vinNumber + + " | Make: " + make + + " | Model: " + model + + " | Mileage: " + mileage + " miles"; + } +} diff --git a/Lab3_BigDecimal/src/IntArrayList.java b/Lab3_BigDecimal/src/IntArrayList.java new file mode 100644 index 0000000..52654c2 --- /dev/null +++ b/Lab3_BigDecimal/src/IntArrayList.java @@ -0,0 +1,97 @@ +/** + * An IntList implementation backed by an array that starts at size 10 + * and grows by 50% whenever capacity is reached. + * + * Best used when: you expect a relatively small or predictable number of + * insertions and want to conserve memory. The 50% growth minimizes wasted + * space compared to doubling. + */ +public class IntArrayList implements IntList { + + // Default starting capacity + private static final int DEFAULT_CAPACITY = 10; + + private int[] data; // Internal storage array + private int size; // Number of elements currently stored + + /** + * Constructs an IntArrayList with a default capacity of 10. + */ + public static void main(String[] args) { + IntArrayList list = new IntArrayList(); + + // Add 12 elements to trigger a resize (default capacity is 10) + for (int i = 1; i <= 12; i++) { + list.add(i * 10); + } + + System.out.print("Elements: "); + for (int i = 0; i < list.size(); i++) { + System.out.print(list.get(i) + " "); + } + System.out.println("\nSize: " + list.size()); + } + + public IntArrayList() { + data = new int[DEFAULT_CAPACITY]; + size = 0; + } + + /** + * Adds a new integer to the list. + * If the array is full, it is resized to 150% of its current length + * before adding the new element. + * + * @param number the integer to add + */ + @Override + public void add(int number) { + // Check if we need to resize before adding + if (size == data.length) { + resize(); + } + data[size] = number; + size++; + } + + /** + * Retrieves the element at the given index. + * + * @param id the zero-based index + * @return the integer stored at that index + * @throws IndexOutOfBoundsException if id is out of range + */ + @Override + public int get(int id) { + if (id < 0 || id >= size) { + throw new IndexOutOfBoundsException("Index " + id + " is out of bounds. Size: " + size); + } + return data[id]; + } + + /** + * Grows the internal array by 50% to accommodate more elements. + * All existing elements are copied to the new array. + */ + private void resize() { + // Calculate new capacity: current length + 50% + int newCapacity = data.length + (data.length / 2); + int[] newData = new int[newCapacity]; + + // Copy all existing elements to the new array + for (int i = 0; i < size; i++) { + newData[i] = data[i]; + } + + data = newData; + } + + /** + * Returns the number of elements currently in the list. + * + * @return current element count + */ + public int size() { + return size; + } +} diff --git a/Lab3_BigDecimal/src/IntList.java b/Lab3_BigDecimal/src/IntList.java new file mode 100644 index 0000000..d53db00 --- /dev/null +++ b/Lab3_BigDecimal/src/IntList.java @@ -0,0 +1,21 @@ +/** + * Interface defining a basic list of integers. + * Implementations handle their own internal storage and resizing strategies. + */ +public interface IntList { + + /** + * Adds a new integer to the list. + * + * @param number the integer to add + */ + void add(int number); + + /** + * Retrieves an element by its index (ID). + * + * @param id the zero-based index of the element + * @return the integer at the specified index + */ + int get(int id); +} diff --git a/Lab3_BigDecimal/src/IntVector.java b/Lab3_BigDecimal/src/IntVector.java new file mode 100644 index 0000000..077edee --- /dev/null +++ b/Lab3_BigDecimal/src/IntVector.java @@ -0,0 +1,96 @@ +/** + * An IntList implementation backed by an array that starts at size 20 + * and doubles in size whenever capacity is reached. + * + * Best used when: you expect a large or rapidly growing number of insertions. + * Doubling the array less frequently means fewer expensive copy operations + * at the cost of potentially using more memory. + */ +public class IntVector implements IntList { + + // Default starting capacity + private static final int DEFAULT_CAPACITY = 20; + + private int[] data; // Internal storage array + private int size; // Number of elements currently stored + + /** + * Constructs an IntVector with a default capacity of 20. + */ + public static void main(String[] args) { + IntVector vector = new IntVector(); + + // Add 22 elements to trigger a resize (default capacity is 20) + for (int i = 1; i <= 22; i++) { + vector.add(i * 5); + } + + System.out.print("Elements: "); + for (int i = 0; i < vector.size(); i++) { + System.out.print(vector.get(i) + " "); + } + System.out.println("\nSize: " + vector.size()); + } + + public IntVector() { + data = new int[DEFAULT_CAPACITY]; + size = 0; + } + + /** + * Adds a new integer to the list. + * If the array is full, it is doubled in size before adding the new element. + * + * @param number the integer to add + */ + @Override + public void add(int number) { + // Check if we need to double capacity before adding + if (size == data.length) { + resize(); + } + data[size] = number; + size++; + } + + /** + * Retrieves the element at the given index. + * + * @param id the zero-based index + * @return the integer stored at that index + * @throws IndexOutOfBoundsException if id is out of range + */ + @Override + public int get(int id) { + if (id < 0 || id >= size) { + throw new IndexOutOfBoundsException("Index " + id + " is out of bounds. Size: " + size); + } + return data[id]; + } + + /** + * Doubles the internal array size to accommodate more elements. + * All existing elements are copied to the new array. + */ + private void resize() { + // New capacity is exactly double the current length + int newCapacity = data.length * 2; + int[] newData = new int[newCapacity]; + + // Copy all existing elements to the new array + for (int i = 0; i < size; i++) { + newData[i] = data[i]; + } + + data = newData; + } + + /** + * Returns the number of elements currently in the list. + * + * @return current element count + */ + public int size() { + return size; + } +} diff --git a/Lab3_BigDecimal/src/Main.java b/Lab3_BigDecimal/src/Main.java new file mode 100644 index 0000000..3d87d6e --- /dev/null +++ b/Lab3_BigDecimal/src/Main.java @@ -0,0 +1,13 @@ +//TIP To Run code, press or +// click the icon in the gutter. +void main() { + //TIP Press with your caret at the highlighted text + // to see how IntelliJ IDEA suggests fixing it. + IO.println(String.format("Hello and welcome!")); + + for (int i = 1; i <= 5; i++) { + //TIP Press to start debugging your code. We have set one breakpoint + // for you, but you can always add more by pressing . + IO.println("i = " + i); + } +} diff --git a/Lab3_BigDecimal/src/Movie.java b/Lab3_BigDecimal/src/Movie.java new file mode 100644 index 0000000..2da99ff --- /dev/null +++ b/Lab3_BigDecimal/src/Movie.java @@ -0,0 +1,43 @@ +/** + * Represents a movie on the streaming service. + * Adds a rating property to the base Video fields. + */ +public class Movie extends Video { + + // Viewer/critic rating (e.g. out of 10.0) + private double rating; + + /** + * Constructs a Movie with the standard Video properties plus a rating. + * + * @param title the title of the movie + * @param duration the duration in minutes + * @param rating the movie's rating (e.g. 8.5 out of 10) + */ + public static void main(String[] args) { + Movie movie1 = new Movie("Inception", 148, 8.8); + System.out.println(movie1.getInfo()); + + Movie movie2 = new Movie("The Dark Knight", 152, 9.0); + System.out.println(movie2.getInfo()); + } + + public 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; } + + /** + * Returns a formatted string describing this Movie, + * including its rating. + * + * @return a human-readable summary + */ + @Override + public String getInfo() { + return "[Movie] " + super.getInfo() + " | Rating: " + rating + "/10"; + } +} diff --git a/Lab3_BigDecimal/src/README.md b/Lab3_BigDecimal/src/README.md new file mode 100644 index 0000000..dfcd619 --- /dev/null +++ b/Lab3_BigDecimal/src/README.md @@ -0,0 +1,35 @@ +# Java Lab – README + +## IntList Implementations: When to Use Each + +### `IntArrayList` (grows by 50%) + +**Use when:** You're working with a list that grows **slowly or predictably** and memory efficiency matters. + +**Example scenario:** +You're storing the IDs of active support tickets in a small customer service app. You start with a few tickets and rarely exceed 20–30 at a time. Because `IntArrayList` only grows by 50% at a time, it wastes less memory — an array that hits capacity at 10 grows to 15, not 20. Over many small lists, this adds up to meaningful memory savings. + +**Trade-off:** More frequent resizes if the list grows quickly, which means more array-copy operations. + +--- + +### `IntVector` (doubles in size) + +**Use when:** You expect **rapid or large-scale growth** and performance is more important than memory. + +**Example scenario:** +You're collecting real-time sensor readings from an IoT device — thousands of integers arriving per second. Because `IntVector` doubles its capacity on each resize (e.g., 20 → 40 → 80 → 160), it resizes far less often than `IntArrayList`. Fewer resizes means fewer expensive copy operations, so the list keeps up with the high-volume input without slowing down. + +**Trade-off:** May allocate more memory than is currently needed, since the array can be up to twice the size of the actual data. + +--- + +## Summary Table + +| Feature | `IntArrayList` | `IntVector` | +|-----------------------|---------------------|----------------------| +| Default size | 10 | 20 | +| Growth strategy | +50% on resize | ×2 on resize | +| Memory efficiency | ✅ Better | ❌ Can waste space | +| Speed (many inserts) | ❌ More resizes | ✅ Fewer resizes | +| Best for | Small/slow-growing | Large/fast-growing | diff --git a/Lab3_BigDecimal/src/Sedan.java b/Lab3_BigDecimal/src/Sedan.java new file mode 100644 index 0000000..d9171c1 --- /dev/null +++ b/Lab3_BigDecimal/src/Sedan.java @@ -0,0 +1,33 @@ +/** + * Represents a Sedan in the car inventory system. + * Sedans have no extra properties beyond those defined in Car. + */ +public class Sedan extends Car { + + /** + * Constructs a Sedan with the standard Car properties. + * + * @param vinNumber the vehicle identification number + * @param make the manufacturer of the car + * @param model the model name + * @param mileage the current mileage + */ + public static void main(String[] args) { + Sedan sedan = new Sedan("1HGBH41JXMN109186", "Honda", "Civic", 32000); + System.out.println(sedan.getInfo()); + } + + public Sedan(String vinNumber, String make, String model, int mileage) { + super(vinNumber, make, model, mileage); + } + + /** + * Returns a formatted string describing this Sedan. + * + * @return a human-readable summary including vehicle type + */ + @Override + public String getInfo() { + return "[Sedan] " + super.getInfo(); + } +} diff --git a/Lab3_BigDecimal/src/Truck.java b/Lab3_BigDecimal/src/Truck.java new file mode 100644 index 0000000..203a496 --- /dev/null +++ b/Lab3_BigDecimal/src/Truck.java @@ -0,0 +1,46 @@ +/** + * Represents a Truck in the car inventory system. + * Adds a towingCapacity property to the base Car fields. + */ +public class Truck extends Car { + + // Maximum towing capacity in pounds (or relevant unit) + private double towingCapacity; + + /** + * Constructs a Truck with standard Car properties plus towing capacity. + * + * @param vinNumber the vehicle identification number + * @param make the manufacturer of the truck + * @param model the model name + * @param mileage the current mileage + * @param towingCapacity the maximum towing capacity + */ + public static void main(String[] args) { + Truck truck = new Truck("3GCPCREC0EG999999", "Chevrolet", "Silverado", 48000, 12500.0); + System.out.println(truck.getInfo()); + + Truck truck2 = new Truck("1FTFW1ET5EKE99999", "Ford", "F-150", 61000, 8200.0); + System.out.println(truck2.getInfo()); + } + + public 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; } + + /** + * Returns a formatted string describing this Truck, + * including its towing capacity. + * + * @return a human-readable summary + */ + @Override + public String getInfo() { + return "[Truck] " + super.getInfo() + + " | Towing Capacity: " + towingCapacity + " lbs"; + } +} diff --git a/Lab3_BigDecimal/src/TvSeries.java b/Lab3_BigDecimal/src/TvSeries.java new file mode 100644 index 0000000..d224eb9 --- /dev/null +++ b/Lab3_BigDecimal/src/TvSeries.java @@ -0,0 +1,43 @@ +/** + * Represents a TV series on the streaming service. + * Adds an episodes property to the base Video fields. + */ +public class TvSeries extends Video { + + // Total number of episodes in the series + private int episodes; + + /** + * Constructs a TvSeries with the standard Video properties plus episode count. + * + * @param title the title of the series + * @param duration the total duration in minutes + * @param episodes the number of episodes + */ + public static void main(String[] args) { + TvSeries series1 = new TvSeries("Breaking Bad", 2700, 62); + System.out.println(series1.getInfo()); + + TvSeries series2 = new TvSeries("The Office", 3120, 201); + System.out.println(series2.getInfo()); + } + + public 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; } + + /** + * Returns a formatted string describing this TvSeries, + * including the episode count. + * + * @return a human-readable summary + */ + @Override + public String getInfo() { + return "[TV Series] " + super.getInfo() + " | Episodes: " + episodes; + } +} diff --git a/Lab3_BigDecimal/src/UtilityVehicle.java b/Lab3_BigDecimal/src/UtilityVehicle.java new file mode 100644 index 0000000..b655837 --- /dev/null +++ b/Lab3_BigDecimal/src/UtilityVehicle.java @@ -0,0 +1,46 @@ +/** + * Represents a Utility Vehicle (SUV/crossover) in the car inventory system. + * Adds a fourWheelDrive property to the base Car fields. + */ +public class UtilityVehicle extends Car { + + // Whether this vehicle has four-wheel drive capability + private boolean fourWheelDrive; + + /** + * Constructs a UtilityVehicle with standard Car properties plus 4WD status. + * + * @param vinNumber the vehicle identification number + * @param make the manufacturer of the car + * @param model the model name + * @param mileage the current mileage + * @param fourWheelDrive true if the vehicle has four-wheel drive + */ + public static void main(String[] args) { + UtilityVehicle suv = new UtilityVehicle("2T1BURHE0JC043821", "Toyota", "RAV4", 15000, true); + System.out.println(suv.getInfo()); + + UtilityVehicle suv2 = new UtilityVehicle("5XYZU3LB8FG999999", "Hyundai", "Tucson", 22000, false); + System.out.println(suv2.getInfo()); + } + + public 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; } + + /** + * Returns a formatted string describing this UtilityVehicle, + * including its four-wheel drive status. + * + * @return a human-readable summary + */ + @Override + public String getInfo() { + return "[Utility Vehicle] " + super.getInfo() + + " | 4WD: " + (fourWheelDrive ? "Yes" : "No"); + } +} diff --git a/Lab3_BigDecimal/src/Video.java b/Lab3_BigDecimal/src/Video.java new file mode 100644 index 0000000..5f80838 --- /dev/null +++ b/Lab3_BigDecimal/src/Video.java @@ -0,0 +1,39 @@ +/** + * Abstract base class representing a video in the streaming service. + * All video types (TvSeries, Movie) extend this class. + */ +public abstract class Video { + + // Shared properties for all video content + private String title; + private int duration; // Duration in minutes + + /** + * Constructs a Video with a title and duration. + * + * @param title the title of the video + * @param duration the duration in minutes + */ + public 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 formatted string with this video's properties. + * Subclasses should override to include their additional fields. + * + * @return a human-readable summary of the video + */ + public String getInfo() { + return "Title: " + title + " | Duration: " + duration + " min"; + } +}