diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/README.md b/homework/src/HW1/submissions/partA/BenjaminLe/README.md new file mode 100644 index 0000000..64722e2 --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/README.md @@ -0,0 +1,86 @@ +# Problem: Airbnb + +## pt.1 What SOLID(s) principle is being violated? + +- Liskov Substitution Principle: Discounted Hotel is unable to replace Hotel because it uses the super. method and if the Hotel class is gone then super. won't have anything to inherit thus it no longer works +- Open Closed Principle: I have to extend and modify the hotel class every time I want to add a different house to the airbnb. + +## pt.2 How do you fix the identified issues above? + +- Change super.calculateTotalPrice(numberOfNights) to numberOfNights * 100. This way even if Hotel disappears we still have + +- Create an interface that holds the calculateTotalPrice() function so that different hotel types can implement it. This way the prices of different hotels can still be customized (open) while the original code cannot be modified (closed). + +## pt.3 Additional Functionality + +- Allows users to see how much the total bill is with California tax and a tip amount of their choice. + + +# Problem: DoorDash + +## pt.1 What SOLID(s) principle is being violated? + +- Interface Separation Principle: We only need to deliver food and not track packages so it's necessary to force users to implement a trackPackage function +- Single Responsibility Principle: FoodDeliveryAndTrackingService class has 2 different responsibilities: food delivery and tracking packages + + +## pt.2 How do you fix the identified issues above? + +- Move the “track package” function from the DeliveryService interface into a different interface +- Split the FoodDeliveryAndTrackingService into 2 different classes with 1 responsibility each: Class FoodDelivery and Class Tracking Service + +## pt.3 Additional Functionality +- Allows users to see what orders still need to be delivered to a specific address of the customer. + + +# Problem: Facebook + +## pt.1 What SOLID(s) principle is being violated? + +- Single Responsibility Principle: Post2 has too many responsibilities working with images, videos, text, etc + +## pt.2 How do you fix the identified issues above? + +- Split the Post2 class into 3 different classes: images, text, videos + +## pt.3 Additional Functionality + +- Turned Post1 into an interface to ensure that if we want to create different posts in the future like posting gifs then we can easily implement it. Along with that I added a “display()” function for each class that just displays the url of each image/video. This is to set up for future functionality when we have the code to import and display the actual image/video. + + +# Problem: PayPal + +## pt.1 What SOLID(s) principle is being violated? + +- Dependency Inversion Principle: PayPalProcessor is a high level module that's dependent on PayPalGateway which is a low level module + + - PaymentProcessor is a high-level module because it orchestrates the payment processing logic and is more abstract + + - PayPalGateway is a lower-level module because it handles the specific implementation details of processing payments via PayPal. + + +## pt.2 How do you fix the identified issues above? + +- To align with the Dependency Inversion Principle the high-level module class should be dependent on an interface or an abstract class rather than a concrete lower level module class like PayPalGateway. To fix this I created an interface called PayPalBarrier for both of them to implement. + +## pt.3 Additional Functionality + +- You can now request a refund of a specific amount from a specific account + + +# Problem: Uber + +## pt.1 What SOLID(s) principle is being violated? + +- Open-Closed Principle: the RideManager class only calculates the rideFare for a normal Ride class. If I wanted to ride in a deluxe uber then it might cost more. However, in order to calculate the ride fare I would have to modify the RideManager class directly which violates the Open-Closed principle. + + +## pt.2 How do you fix the identified issues above? +- I created an interface to hold the calculateRideFare function. This way if I want to find out the cost of a different kind of uber like a deluxe uber then I can easily implement it without having to modify the initial RideManager class. + +## pt.3 Additional Functionality + +- There’s a new RideManagerDeluxe class that allows you to calculate the ride fare of what a deluxe uber would cost with the same distance in miles and duration in minutes. + + + diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/airbnb/BookingService.java b/homework/src/HW1/submissions/partA/BenjaminLe/airbnb/BookingService.java new file mode 100644 index 0000000..6982da2 --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/airbnb/BookingService.java @@ -0,0 +1,8 @@ +package airbnb; + +public interface BookingService { + int calculateTotalPrice(Hotel hotel, int numberOfNights); + + double totalBill(int tip); +} + diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/airbnb/BookingServiceImpl.java b/homework/src/HW1/submissions/partA/BenjaminLe/airbnb/BookingServiceImpl.java new file mode 100644 index 0000000..aeb71da --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/airbnb/BookingServiceImpl.java @@ -0,0 +1,20 @@ +package airbnb; + +public class BookingServiceImpl implements BookingService { + int totalCost = 0; + + @Override + public int calculateTotalPrice(Hotel hotel, int numberOfNights) { + totalCost = 0; + int totalPrice = hotel.calculateTotalPrice(numberOfNights); + totalCost += totalPrice; + return totalPrice; + } + + @Override + public double totalBill(int tip) { + //total cost + tax (because 7.25% is california's hotel tax) + tip amount you want to put) + return totalCost + (totalCost*0.0725) + tip; + } + +} \ No newline at end of file diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/airbnb/DiscountedHotel.java b/homework/src/HW1/submissions/partA/BenjaminLe/airbnb/DiscountedHotel.java new file mode 100644 index 0000000..3cc25aa --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/airbnb/DiscountedHotel.java @@ -0,0 +1,15 @@ +package airbnb; + +public class DiscountedHotel extends Hotel { + + @Override + public int calculateTotalPrice(int numberOfNights) { + + /*by turning the super method into numberOfNights * 100 + * we ensure that this method still functions by itself even + * if the hotel class were to disappear since we've overriden + * its functionality + */ + return numberOfNights * 100 - 50; + } +} \ No newline at end of file diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/airbnb/Hotel.java b/homework/src/HW1/submissions/partA/BenjaminLe/airbnb/Hotel.java new file mode 100644 index 0000000..7e28862 --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/airbnb/Hotel.java @@ -0,0 +1,14 @@ +package airbnb; + +public class Hotel implements hotelPrices{ + + + + @Override + public int calculateTotalPrice(int numberOfNights) { + + return numberOfNights * 100; + } + + +} \ No newline at end of file diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/airbnb/Main.java b/homework/src/HW1/submissions/partA/BenjaminLe/airbnb/Main.java new file mode 100644 index 0000000..4608992 --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/airbnb/Main.java @@ -0,0 +1,23 @@ +package airbnb; + + +public class Main { + public static void main(String[] args) { + Hotel regularHotel = new Hotel(); + DiscountedHotel discountedHotel = new DiscountedHotel(); + + BookingService bookingService = new BookingServiceImpl(); + int regularHotelTotalPrice = bookingService.calculateTotalPrice(regularHotel, 3); + double regAndTip = bookingService.totalBill(20); + System.out.println("Regular Hotel Total Price: $" + regularHotelTotalPrice); + System.out.println("Regular Hotel Price WITH TAX & TIP: $" + regAndTip); + + int discountedHotelTotalPrice = bookingService.calculateTotalPrice(discountedHotel, 3); + + double disAndTip = bookingService.totalBill(30); + + System.out.println("Discounted Hotel Total Price: $" + discountedHotelTotalPrice); + System.out.println("Discounted Hotel Price WITH TAX & TIP: $" + disAndTip); + + } +} diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/airbnb/hotelPrices.java b/homework/src/HW1/submissions/partA/BenjaminLe/airbnb/hotelPrices.java new file mode 100644 index 0000000..8eb0a1f --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/airbnb/hotelPrices.java @@ -0,0 +1,11 @@ +package airbnb; + +public interface hotelPrices { + /*this way we enforce the open/closed principle since + * the initial calculateTotalPrice is closed from modification + * but open to modification if we want to find out the prices from + * different hotel types. + */ + int calculateTotalPrice(int numberOfNights); + +} \ No newline at end of file diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/doordash/Customer.java b/homework/src/HW1/submissions/partA/BenjaminLe/doordash/Customer.java new file mode 100644 index 0000000..44be870 --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/doordash/Customer.java @@ -0,0 +1,18 @@ +package doordash; + +public class Customer { + private String name; + private String address; + + public Customer(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public String getAddress() { + return address; + } +} diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/doordash/DeliveryService.java b/homework/src/HW1/submissions/partA/BenjaminLe/doordash/DeliveryService.java new file mode 100644 index 0000000..e311bfe --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/doordash/DeliveryService.java @@ -0,0 +1,7 @@ +package doordash; + +public interface DeliveryService { + void deliverFood(Restaurant restaurant, Customer customer); + void uberEats(Restaurant restaurant, Customer customer); + +} diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/doordash/FoodDelivery.java b/homework/src/HW1/submissions/partA/BenjaminLe/doordash/FoodDelivery.java new file mode 100644 index 0000000..b607409 --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/doordash/FoodDelivery.java @@ -0,0 +1,13 @@ +package doordash; + +public class FoodDelivery implements DeliveryService { + @Override + public void deliverFood(Restaurant restaurant, Customer customer) { + System.out.println("Food delivered from " + restaurant.getName() + " to " + customer.getName()); + } + public void uberEats(Restaurant restaurant, Customer customer){ + System.out.println("" + customer.getName() + "food order needs to be delivered from " + restaurant.getName() + " to " + customer.getAddress()); + } + + +} \ No newline at end of file diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/doordash/Restaurant.java b/homework/src/HW1/submissions/partA/BenjaminLe/doordash/Restaurant.java new file mode 100644 index 0000000..6523484 --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/doordash/Restaurant.java @@ -0,0 +1,14 @@ +package doordash; + +public class Restaurant { + private String name; + + public Restaurant(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} + diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/doordash/TrackingService.java b/homework/src/HW1/submissions/partA/BenjaminLe/doordash/TrackingService.java new file mode 100644 index 0000000..2fe3ad9 --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/doordash/TrackingService.java @@ -0,0 +1,8 @@ +package doordash; + +public class TrackingService implements trackPackages { + @Override + public void trackPackage(String trackingNumber) { + System.out.println("Package with tracking number " + trackingNumber + " is being tracked."); + } +} diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/doordash/trackPackages.java b/homework/src/HW1/submissions/partA/BenjaminLe/doordash/trackPackages.java new file mode 100644 index 0000000..7731f4b --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/doordash/trackPackages.java @@ -0,0 +1,5 @@ +package doordash; + +public interface trackPackages { + void trackPackage(String trackingNumber); +} diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/facebook/Post1.java b/homework/src/HW1/submissions/partA/BenjaminLe/facebook/Post1.java new file mode 100644 index 0000000..afb492d --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/facebook/Post1.java @@ -0,0 +1,8 @@ +package facebook; + +//This was the original post class, that was implemented for our "Facebook". + +public interface Post1 { + + void display(); +} diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/facebook/postImages.java b/homework/src/HW1/submissions/partA/BenjaminLe/facebook/postImages.java new file mode 100644 index 0000000..ba67fbb --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/facebook/postImages.java @@ -0,0 +1,36 @@ +package facebook; + +public class postImages implements Post1{ + + private String imageUrl; + + private boolean isImage; + + public String getImageUrl() { + return imageUrl; + } + + public void setImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } + + public boolean isImage() { + return isImage; + } + + public void setImage(boolean image) { + isImage = image; + } + + public postImages(String imageUrl, boolean isImage) { + if(isImage) { + this.imageUrl = imageUrl; + this.isImage = true; + } + } + + public void display() { + System.out.println(imageUrl); + } + +} diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/facebook/postText.java b/homework/src/HW1/submissions/partA/BenjaminLe/facebook/postText.java new file mode 100644 index 0000000..87eb769 --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/facebook/postText.java @@ -0,0 +1,35 @@ +package facebook; + + +//This is the new post class, that was implemented for our "Facebook" to help support images and videos. + +public class postText implements Post1 { + + private String text; + + + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + + + + public postText(String text) { + this.text = text; + } + + + void displayText() { + System.out.println(text); + } + + public void display() { + System.out.println(text); + } +} diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/facebook/postVideo.java b/homework/src/HW1/submissions/partA/BenjaminLe/facebook/postVideo.java new file mode 100644 index 0000000..f8309ff --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/facebook/postVideo.java @@ -0,0 +1,39 @@ +package facebook; + +public class postVideo implements Post1 { + + private String videoUrl; + + private boolean isVideo; + + public String getVideoUrl() { + return videoUrl; + } + + public void setVideoUrl(String videoUrl) { + this.videoUrl = videoUrl; + } + + + public boolean isVideo() { + return isVideo; + } + + + public void setVideo(boolean video) { + isVideo = video; + } + + + public postVideo(String videoUrl, boolean isVideo){ + if(isVideo) { + this.videoUrl = videoUrl; + this.isVideo = true; + } + } + + public void display() { + System.out.println(videoUrl); + } + +} diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/paypal/Account.java b/homework/src/HW1/submissions/partA/BenjaminLe/paypal/Account.java new file mode 100644 index 0000000..e9408db --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/paypal/Account.java @@ -0,0 +1,13 @@ +package paypal; + +public class Account { + private String accountID; + + public Account(String accountID) { + this.accountID = accountID; + } + + public String getAccountID() { + return accountID; + } +} diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/paypal/Main.java b/homework/src/HW1/submissions/partA/BenjaminLe/paypal/Main.java new file mode 100644 index 0000000..31e056b --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/paypal/Main.java @@ -0,0 +1,11 @@ +package paypal; + +public class Main { + public static void main(String[] args) { + PaymentProcessor paymentProcessor = new PaymentProcessor(); + Account account = new Account("1"); + Account account2 = new Account("2"); + paymentProcessor.processPayment(account,100.0); + paymentProcessor.requestRefund(account2,50.0); + } +} diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/paypal/PayPalBarrier.java b/homework/src/HW1/submissions/partA/BenjaminLe/paypal/PayPalBarrier.java new file mode 100644 index 0000000..08e4c7a --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/paypal/PayPalBarrier.java @@ -0,0 +1,5 @@ +package paypal; + +public class PayPalBarrier { + +} diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/paypal/PayPalGateway.java b/homework/src/HW1/submissions/partA/BenjaminLe/paypal/PayPalGateway.java new file mode 100644 index 0000000..2f2ecd8 --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/paypal/PayPalGateway.java @@ -0,0 +1,13 @@ +package paypal; + +public class PayPalGateway extends PayPalBarrier{ + + + public void processPayment(Account account, double amount) { + System.out.println("Processing payment of $" + amount + " for account " + account.getAccountID() + " using PayPal."); + } + + public void requestRefund(Account account, double amount) { + System.out.println("Requesting refund of $" + amount + " from account " + account.getAccountID() + " using PayPal."); + } +} diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/paypal/PaymentProcessor.java b/homework/src/HW1/submissions/partA/BenjaminLe/paypal/PaymentProcessor.java new file mode 100644 index 0000000..2739863 --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/paypal/PaymentProcessor.java @@ -0,0 +1,18 @@ +package paypal; + +public class PaymentProcessor extends PayPalBarrier{ + private PayPalGateway payPalGateway; + + PaymentProcessor() { + this.payPalGateway = new PayPalGateway(); + } + + public void processPayment(Account account, double amount) { + payPalGateway.processPayment(account,amount); + } + + public void requestRefund(Account account, double amount) { + payPalGateway.requestRefund(account,amount); + } + +} \ No newline at end of file diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/uber/Main.java b/homework/src/HW1/submissions/partA/BenjaminLe/uber/Main.java new file mode 100644 index 0000000..58f8808 --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/uber/Main.java @@ -0,0 +1,19 @@ +package uber; + +public class Main { + public static void main(String[] args) { + Ride ride = new Ride(1,1); + User user = new User(); + user.setUsername("john_doe"); + + RideManager rideManager = new RideManager(); + + deluxeRideManager delRideManager = new deluxeRideManager(); + + double fare = rideManager.calculateRideFare(ride); + double deluxeFare = delRideManager.calculateRideFare(ride); + + rideManager.sendNotification(user, "Your ride fare is: $" + fare); + delRideManager.sendNotification(user, "Your deluxe ride fare is: $" + deluxeFare); + } +} \ No newline at end of file diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/uber/RideManager.java b/homework/src/HW1/submissions/partA/BenjaminLe/uber/RideManager.java new file mode 100644 index 0000000..103a95c --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/uber/RideManager.java @@ -0,0 +1,100 @@ +package uber; + +class RideManager implements carRideCost { + private final double BASE_FARE = 5.0; // Base fare in dollars + private final double PER_MILE_RATE = 2.0; // Fare per mile in dollars + private final double PER_MINUTE_RATE = 0.5; // Fare per minute in dollars + + public double calculateRideFare(Ride ride) { + double distanceInMiles = ride.getDistanceInMiles(); + int durationInMinutes = ride.getDurationInMinutes(); + + // Calculate fare based on distance and time + double distanceFare = distanceInMiles * PER_MILE_RATE; + double timeFare = durationInMinutes * PER_MINUTE_RATE; + + // Calculate total fare including base fare + double totalFare = BASE_FARE + distanceFare + timeFare; + + return totalFare; + } + + void sendNotification(User user, String message) { + // Code for sending notifications to the user + System.out.println("Notification sent to user: " + user.getUsername() + " - " + message); + } +} + + +class deluxeRideManager implements carRideCost { + private final double BASE_FARE = 10.0; // Base fare in dollars + private final double PER_MILE_RATE = 4.0; // Fare per mile in dollars + private final double PER_MINUTE_RATE = 1.0; // Fare per minute in dollars + + //deluxe just cost a bunch more money but since we're implementing from carRideCost + // ->I'm still following the open-closed principle since I don't have ot modify the RideManager Class anymore + + public double calculateRideFare(Ride ride) { + double distanceInMiles = ride.getDistanceInMiles(); + int durationInMinutes = ride.getDurationInMinutes(); + + // Calculate fare based on distance and time + double distanceFare = distanceInMiles * PER_MILE_RATE; + double timeFare = durationInMinutes * PER_MINUTE_RATE; + + // Calculate total fare including base fare + double totalFare = BASE_FARE + distanceFare + timeFare; + + return totalFare*2; + } + + void sendNotification(User user, String message) { + // Code for sending notifications to the user + System.out.println("Notification sent to user: " + user.getUsername() + " - " + message); + } +} + + +class Ride { + private double distanceInMiles; + private int durationInMinutes; + + public Ride(double distanceInMiles, int durationInMinutes) { + this.distanceInMiles = distanceInMiles; + this.durationInMinutes = durationInMinutes; + } + + public double getDistanceInMiles() { + return distanceInMiles; + } + + public void setDistanceInMiles(double distanceInMiles) { + this.distanceInMiles = distanceInMiles; + } + + public int getDurationInMinutes() { + return durationInMinutes; + } + + public void setDurationInMinutes(int durationInMinutes) { + this.durationInMinutes = durationInMinutes; + } + +} + +class User { + // User details + private String username; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + +} + + diff --git a/homework/src/HW1/submissions/partA/BenjaminLe/uber/carRideCost.java b/homework/src/HW1/submissions/partA/BenjaminLe/uber/carRideCost.java new file mode 100644 index 0000000..46bb568 --- /dev/null +++ b/homework/src/HW1/submissions/partA/BenjaminLe/uber/carRideCost.java @@ -0,0 +1,5 @@ +package uber; + +public interface carRideCost { + double calculateRideFare(Ride ride); +} diff --git a/homework/src/HW1/submissions/partA/README.md b/homework/src/HW1/submissions/partA/README.md deleted file mode 100644 index cd40819..0000000 --- a/homework/src/HW1/submissions/partA/README.md +++ /dev/null @@ -1 +0,0 @@ -Add your submissions for part A of the homework here. \ No newline at end of file diff --git a/homework/src/HW1/submissions/partB/BenjaminLe/myJavaFXGitHub.txt b/homework/src/HW1/submissions/partB/BenjaminLe/myJavaFXGitHub.txt new file mode 100644 index 0000000..9691d34 --- /dev/null +++ b/homework/src/HW1/submissions/partB/BenjaminLe/myJavaFXGitHub.txt @@ -0,0 +1 @@ +Link to part B: https://github.com/bluegoat2/CS151HW1PartB diff --git a/homework/src/HW1/submissions/partB/README.md b/homework/src/HW1/submissions/partB/README.md deleted file mode 100644 index e4aa9c2..0000000 --- a/homework/src/HW1/submissions/partB/README.md +++ /dev/null @@ -1 +0,0 @@ -Add your submissions for part B of the homework here. \ No newline at end of file