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 modified .DS_Store
Binary file not shown.
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.

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.

52 changes: 52 additions & 0 deletions .idea/workspace.xml

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

11 changes: 11 additions & 0 deletions CS151.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$/homework/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
2 changes: 1 addition & 1 deletion homework/src/HW1/submissions/partA/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Add your submissions for part A of the homework here.
Edward's submission for HW1 Part A
5 changes: 5 additions & 0 deletions homework/src/HW1/submissions/partA/airbnb/BookingService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package HW1.submissions.partA.airbnb;

public interface BookingService {
int calculateTotalPrice(HotelInterface hotel, int numberOfNights);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package HW1.submissions.partA.airbnb;

public class BookingServiceImpl implements BookingService{
@Override
public int calculateTotalPrice(HotelInterface hotel, int numberOfNights){
int totalPrice = hotel.calculateTotalPrice(numberOfNights);
return totalPrice;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package HW1.submissions.partA.airbnb;

public class DiscountedHotel implements HotelInterface{
@Override
public int calculateTotalPrice(int numberOfNights){
return numberOfNights*50;
}
}
8 changes: 8 additions & 0 deletions homework/src/HW1/submissions/partA/airbnb/Hotel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package HW1.submissions.partA.airbnb;

public class Hotel implements HotelInterface{
@Override
public int calculateTotalPrice(int numberOfNights){
return numberOfNights*100;
}
}
5 changes: 5 additions & 0 deletions homework/src/HW1/submissions/partA/airbnb/HotelInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package HW1.submissions.partA.airbnb;

public interface HotelInterface {
int calculateTotalPrice(int numberOfNights);
}
15 changes: 15 additions & 0 deletions homework/src/HW1/submissions/partA/airbnb/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package HW1.submissions.partA.airbnb;

public class Main {
public static void main(String[] args){
HotelInterface regularHotel = new Hotel();
HotelInterface discountedHotel = new DiscountedHotel();

BookingService bookingService = new BookingServiceImpl();
int regularHotelTotalPrice = bookingService.calculateTotalPrice(regularHotel, 3);
int discountedHotelTotalPrice = bookingService.calculateTotalPrice(discountedHotel, 3);

System.out.println("Regular Hotel Total Price: $"+regularHotelTotalPrice);
System.out.println("Discounted Hotel Total Price: $"+discountedHotelTotalPrice);
}
}
7 changes: 7 additions & 0 deletions homework/src/HW1/submissions/partA/airbnb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Q) which SOLID principle(s) is this company violating?
A) this company violates Liskov Substitution Principle and Open Closed Principle.

Q) Your approach to making changes to fix the violation
A) LSP is satisfied by introducing an interface HotelInterface which is implemented by the class Hotel and the class DiscountedHotel.
Consequently, in the interface BookingService and the class BookingServiceImpl, the method calculateTotalPrice takes a parameter of type HotelInterface rather than type Hotel.
OCP is satisfied as further additions of hotels/ specific hotel features can now be done without modifying existing classes or class contents but rather just extending them.
13 changes: 13 additions & 0 deletions homework/src/HW1/submissions/partA/doordash/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package HW1.submissions.partA.doordash;

public class Customer {
private String name;

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

public String getName(){
return name;
}
}
5 changes: 5 additions & 0 deletions homework/src/HW1/submissions/partA/doordash/Deliverable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package HW1.submissions.partA.doordash;

public interface Deliverable {
void deliverPackage(Seller seller, Customer customer);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package HW1.submissions.partA.doordash;

public class FoodDeliveryService implements Deliverable{
@Override
public void deliverPackage(Seller seller, Customer customer) {
if(seller instanceof Restaurant that) {
System.out.println("Food delivered from " + that.getName() + " to " + customer.getName());
}
else{
System.out.println("We support only restaurant orders for now!");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package HW1.submissions.partA.doordash;

public class FoodTrackingService implements Trackable{
@Override
public void trackPackage(String trackingNumber) {
System.out.println("Package with tracking number " + trackingNumber + "is being tracked.");
}
}
13 changes: 13 additions & 0 deletions homework/src/HW1/submissions/partA/doordash/GroceryStore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package HW1.submissions.partA.doordash;

public class GroceryStore implements Seller{
private String name;

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

public String getName(){
return name;
}
}
12 changes: 12 additions & 0 deletions homework/src/HW1/submissions/partA/doordash/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package HW1.submissions.partA.doordash;

public class Main {
public static void main(String[] args){
FoodDeliveryService foodDeliveryService = new FoodDeliveryService();
FoodTrackingService foodTrackingService = new FoodTrackingService();

foodDeliveryService.deliverPackage(new Restaurant("McDonalds"), new Customer("Anant"));
foodDeliveryService.deliverPackage(new GroceryStore("Safeway"), new Customer("Edward"));
foodTrackingService.trackPackage("5E96MQ3XPL");
}
}
11 changes: 11 additions & 0 deletions homework/src/HW1/submissions/partA/doordash/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
1) which SOLID principle(s) is this company violating?
This company violates Single Responsibility Principle and Interface Segregation Principle.


2) Your approach to making changes to fix the violation
ISP is satisfied by breaking down the interface DeliveryService into more client-specific interfaces Deliverable and Trackable.
Consequently, the class FoodDeliveryAndTrackingService is also broken down into class FoodDeliveryService and class FoodTrackingService
with each correspondingly implementing Deliverable interface and Trackable interface, thus making SRP satisfied. While not violating yet, based on the recent
capabilities, using Restaurant class my potentially violate LSP since items beyond food can be ordered on DoorDash, so I created an interface Seller
with the class Restaurant implementing it for future expansions. I also made use of instanceof operator and 'that' keyword to verify
this recent version supports only the restaurant orders for now.
13 changes: 13 additions & 0 deletions homework/src/HW1/submissions/partA/doordash/Restaurant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package HW1.submissions.partA.doordash;

public class Restaurant implements Seller{
private String name;

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

public String getName(){
return name;
}
}
5 changes: 5 additions & 0 deletions homework/src/HW1/submissions/partA/doordash/Seller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package HW1.submissions.partA.doordash;

public interface Seller {

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

public interface Trackable {
void trackPackage(String trackingNumber);
}
13 changes: 13 additions & 0 deletions homework/src/HW1/submissions/partA/facebook/Image.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package HW1.submissions.partA.facebook;

public class Image {
private String imageUrl;
private boolean isImage;

public Image(String imageUrl){
this.imageUrl = imageUrl;
this.isImage = true;
}
public String getImageUrl(){return imageUrl;}
public boolean isImage(){return isImage;}
}
15 changes: 15 additions & 0 deletions homework/src/HW1/submissions/partA/facebook/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package HW1.submissions.partA.facebook;

public class Main {
public static void main(String[] args){
Post post1 = new Post(new Text("text-only post"));
Post post2 = new Post(new Text("text and image post"), new Image("...some image url..."));
Post post3 = new Post(new Text("text and video post"), new Video("...some video url..."));
Post post4 = new Post(new Text("text, image, and video post"), new Image("...some image url..."), new Video("...some video url..."));

System.out.println(post1);
System.out.println(post2);
System.out.println(post3);
System.out.println(post4);
}
}
35 changes: 35 additions & 0 deletions homework/src/HW1/submissions/partA/facebook/Post.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package HW1.submissions.partA.facebook;

public class Post {
private Text text;
private Image image;
private Video video;

public Post(Text text){
this.text = text;
}
public Post(Text text, Image image){
this.text = text;
this.image = image;
}
public Post(Text text, Video video){
this.text = text;
this.video = video;
}
public Post(Text text, Image image, Video video){
this.text = text;
this.image = image;
this.video = video;
}

public void displayText(){
System.out.println(text.getText());
}

@Override
public String toString(){
return "Post: " + text.getText() + "\n" +
"Image: " + (image != null ? image.getImageUrl() : "NO image url provided") + "\n" +
"Video: " + (video != null ? video.getVideoUrl() : "NO video url provided") + "\n";
}
}
7 changes: 7 additions & 0 deletions homework/src/HW1/submissions/partA/facebook/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1) which SOLID principle(s) is this company violating?
This company violates Single Responsibility Principle.

2) Your approach to making changes to fix the violations.
Post2 class violates SRP because it looks 'fat' with multiple sets of related attributes.
Once implemented with methods, such class layout can easily get swamped with multiple methods that function differently on various not-so-related attributes.
I split the class Post2 into classes - Post, Text, Image and Video - each of which can be configured with more specific attributes and methods for further development while also allowing each to either extend a superclass or implement interfaces to provide more enriched features.
8 changes: 8 additions & 0 deletions homework/src/HW1/submissions/partA/facebook/Text.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package HW1.submissions.partA.facebook;

public class Text {
private String text;

public Text(String text){this.text = text;}
public String getText(){return text;}
}
13 changes: 13 additions & 0 deletions homework/src/HW1/submissions/partA/facebook/Video.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package HW1.submissions.partA.facebook;

public class Video {
private String videoUrl;
private boolean isVideo;

public Video(String videoUrl){
this.videoUrl = videoUrl;
this.isVideo = true;
}
public String getVideoUrl(){return videoUrl;}
public boolean isVideo(){return isVideo;}
}
11 changes: 11 additions & 0 deletions homework/src/HW1/submissions/partA/paypal/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package HW1.submissions.partA.paypal;

public class Account {
private String accountID;

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

public String getAccountID(){return accountID;}
}
16 changes: 16 additions & 0 deletions homework/src/HW1/submissions/partA/paypal/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package HW1.submissions.partA.paypal;

public class Main {
public static void main(String[] args){
PayEntity payEntity = new PayEntity();

payEntity.setPaymentProcessorService(new PaymentProcessor(new Account("123456789")));
payEntity.process(150);

payEntity.setPaymentProcessorService(new PayPalGateway(new Account("987654321")));
payEntity.process(300);

payEntity.setPaymentProcessorService(null);
payEntity.process(500);
}
}
Loading