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
86 changes: 86 additions & 0 deletions homework/src/HW1/submissions/partA/BenjaminLe/README.md
Original file line number Diff line number Diff line change
@@ -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.



Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package airbnb;

public interface BookingService {
int calculateTotalPrice(Hotel hotel, int numberOfNights);

double totalBill(int tip);
}

Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
}
14 changes: 14 additions & 0 deletions homework/src/HW1/submissions/partA/BenjaminLe/airbnb/Hotel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package airbnb;

public class Hotel implements hotelPrices{



@Override
public int calculateTotalPrice(int numberOfNights) {

return numberOfNights * 100;
}


}
23 changes: 23 additions & 0 deletions homework/src/HW1/submissions/partA/BenjaminLe/airbnb/Main.java
Original file line number Diff line number Diff line change
@@ -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);

}
}
Original file line number Diff line number Diff line change
@@ -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);

}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package doordash;

public interface DeliveryService {
void deliverFood(Restaurant restaurant, Customer customer);
void uberEats(Restaurant restaurant, Customer customer);

}
Original file line number Diff line number Diff line change
@@ -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());
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package doordash;

public class Restaurant {
private String name;

public Restaurant(String name) {
this.name = name;
}

public String getName() {
return name;
}
}

Original file line number Diff line number Diff line change
@@ -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.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package doordash;

public interface trackPackages {
void trackPackage(String trackingNumber);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package facebook;

//This was the original post class, that was implemented for our "Facebook".

public interface Post1 {

void display();
}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}

}
13 changes: 13 additions & 0 deletions homework/src/HW1/submissions/partA/BenjaminLe/paypal/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package paypal;

public class Account {
private String accountID;

public Account(String accountID) {
this.accountID = accountID;
}

public String getAccountID() {
return accountID;
}
}
Loading