Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
90001e3
Update Hotel.java
Achur260 Nov 23, 2023
13a7bb4
Update Hotel.java
Achur260 Nov 23, 2023
ea71675
Create acyutaraman
Achur260 Nov 24, 2023
365c8ef
Add files via upload
Achur260 Nov 24, 2023
be0acef
Create .gitkeep
Achur260 Nov 24, 2023
294fe0a
Delete homework/src/HW1/submissions/partA/acyutaraman
Achur260 Nov 24, 2023
f905fc3
Create .gitkeep
Achur260 Nov 24, 2023
9be5f5c
Delete homework/src/HW1/submissions/partA/acyutaraman/.gitkeep
Achur260 Nov 24, 2023
8170d34
Create .gitkeep
Achur260 Nov 24, 2023
bf691f3
Create .gitkeep
Achur260 Nov 24, 2023
bd6bc4f
Create .gitkeep
Achur260 Nov 24, 2023
adbe86f
Create .gitkeep
Achur260 Nov 24, 2023
7e50779
Create .gitkeep
Achur260 Nov 24, 2023
bb729da
Create .gitkeep
Achur260 Nov 24, 2023
55cbf67
Add files via upload
Achur260 Nov 24, 2023
1b18917
Add files via upload
Achur260 Nov 24, 2023
85b27af
Add files via upload
Achur260 Nov 24, 2023
579e08e
Add files via upload
Achur260 Nov 24, 2023
f11d242
Add files via upload
Achur260 Nov 24, 2023
dc5aafc
Delete homework/src/HW1/submissions/partA/Account.java
Achur260 Nov 24, 2023
7d271a8
Delete homework/src/HW1/submissions/partA/BookingService.java
Achur260 Nov 24, 2023
52857c9
Delete homework/src/HW1/submissions/partA/BookingServiceImpl.java
Achur260 Nov 24, 2023
0c365fd
Delete homework/src/HW1/submissions/partA/DeliveryService.java
Achur260 Nov 24, 2023
939f84e
Delete homework/src/HW1/submissions/partA/Customer.java
Achur260 Nov 24, 2023
3a886c3
Delete homework/src/HW1/submissions/partA/DiscountedHotel.java
Achur260 Nov 24, 2023
4b96f24
Delete homework/src/HW1/submissions/partA/FiveStarHotel.java
Achur260 Nov 24, 2023
d576d77
Delete homework/src/HW1/submissions/partA/FoodDeliveryAndTrackingServ…
Achur260 Nov 24, 2023
0d33959
Delete homework/src/HW1/submissions/partA/Hotel.java
Achur260 Nov 24, 2023
be702e3
Delete homework/src/HW1/submissions/partA/Main.java
Achur260 Nov 24, 2023
e0667ae
Delete homework/src/HW1/submissions/partA/PayPalGateway.java
Achur260 Nov 24, 2023
706e4bd
Delete homework/src/HW1/submissions/partA/PaymentProcessor.java
Achur260 Nov 24, 2023
c949956
Delete homework/src/HW1/submissions/partA/Post.java
Achur260 Nov 24, 2023
eb12f85
Delete homework/src/HW1/submissions/partA/Post1.java
Achur260 Nov 24, 2023
0a2422c
Delete homework/src/HW1/submissions/partA/Post2.java
Achur260 Nov 24, 2023
e752ac6
Delete homework/src/HW1/submissions/partA/RegularHotel.java
Achur260 Nov 24, 2023
bd612a9
Delete homework/src/HW1/submissions/partA/Restaurant.java
Achur260 Nov 24, 2023
884d26e
Delete homework/src/HW1/submissions/partA/RideManager.java
Achur260 Nov 24, 2023
d1c9383
Delete homework/src/HW1/submissions/partA/TrackingService.java
Achur260 Nov 24, 2023
551182d
Delete homework/src/HW1/submissions/partA/acyutaramanw directory
Achur260 Nov 24, 2023
b80f5d3
Update RideManager.java
Achur260 Nov 25, 2023
8e890c3
Delete homework/src/HW1/submissions/partA/acyutaraman/airbnb/.gitkeep
Achur260 Nov 27, 2023
221e628
Create README.md
Achur260 Nov 27, 2023
59a9683
Delete homework/src/HW1/submissions/partA/acyutaraman/doordash/.gitkeep
Achur260 Nov 27, 2023
45e98d1
Create README.md
Achur260 Nov 27, 2023
cf6558b
Create README.md
Achur260 Nov 27, 2023
951db37
Delete homework/src/HW1/submissions/partA/acyutaraman/facebook/.gitkeep
Achur260 Nov 27, 2023
446ccc0
Delete homework/src/HW1/submissions/partA/acyutaraman/paypal/.gitkeep
Achur260 Nov 27, 2023
3703583
Create README.md
Achur260 Nov 27, 2023
94c2e7f
Delete homework/src/HW1/submissions/partA/acyutaraman/uber/.gitkeep
Achur260 Nov 27, 2023
b96f66b
Create README.md
Achur260 Nov 27, 2023
d025451
Update README.md
Achur260 Nov 27, 2023
46a3382
Update README.md
Achur260 Nov 28, 2023
e194489
Update README.md
Achur260 Nov 28, 2023
8af7409
Update README.md
Achur260 Nov 28, 2023
90fd8c4
Create README.md
Achur260 Nov 28, 2023
e77d0be
Update README.md
Achur260 Nov 28, 2023
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
1 change: 1 addition & 0 deletions homework/src/HW1/submissions/partA/acyutaraman/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

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

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

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

public class DiscountedHotel implements Hotel {

@Override
public int calculateTotalPrice(int numberOfNights) {
return 100*numberOfNights - 50;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package airbnb;

public class FiveStarHotel implements Hotel {

@Override
public int calculateTotalPrice(int numberOfNights) {
return 200*numberOfNights;
}

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

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

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

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

System.out.println("Regular Hotel Total Price: $" + regularHotelTotalPrice);
System.out.println("Discounted Hotel Total Price: $" + discountedHotelTotalPrice);
System.out.println("Five Star Hotel Total Price: $" + fiveStarHotelTotalPrice);



}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1) Airbnb violated the Open/Closed principle in SOLID. The DiscountedHotel class was a subclass of the Hotel class, and it overrides its calculateTotalPrice() method. Despite doing this,
the DiscountedHotel class can still access the calculateTotalPrice method of its superclass. Therefore, it violates the Open/Closed principle in SOLID.

2) I fixed this violation by removing the Hotel class and instead creating a Hotel interface. I, then, created a Regular Hotel class to replace the previous Hotel class. I then made
both DiscountedHotel and the new RegularHotel classes implement the new Hotel interface. The Hotel interface has the abstract method calculateTotalPrice, which is implemented differently
in both DiscountedHotel and RegularHotel. I also added a new FiveStarHotel class that implements Hotel and charges at a higher hourly rate than RegularHotel. Its higher rate is displayed in
its calculateTotalPrice() method.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package airbnb;

public class RegularHotel implements Hotel{

@Override
public int calculateTotalPrice(int numberOfNights) {

return 100*numberOfNights;
}

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

public class Customer {

private String name;

public Customer(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 interface DeliveryService {

void deliverFood(Restaurant restaurant, Customer customer);

void cancelDelivery(Restaurant restaurant, Customer customer);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package doordash;

public class FoodDeliveryAndTrackingService implements DeliveryService, TrackingService {

@Override
public void deliverFood(Restaurant restaurant, Customer customer) {
System.out.println("Food delivered from " + restaurant.getName() + " to " + customer.getName());
}

@Override
public void trackPackage(String trackingNumber) {
System.out.println("Package with tracking number " + trackingNumber + " is being tracked.");
}

@Override
public void cancelDelivery(Restaurant restaurant, Customer customer) {
System.out.println("Food delivery canceled: from " + restaurant.getName() + " to " + customer.getName());

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

1) Doordash violates the Interface Segregation Principle of SOLID because it keeps both the deliverFood() and trackPackage() methods
in the DeliveryService interface instead of separating the methods across two different interfaces(a deliveryService and a trackingService interface).

2) To solve this, I created a new TrackingService interface and moved the trackPackage() method from the original DeliveryService interface to it.
I then made the FoodDeliveryAndTrackingService class implement both the TrackingService and the DeliveryService interfaces, and had it implement
both the deliverFood() and trackPackage() methods. I even added a cancelDelivery() method to DeliveryService and concretely implemented it in
FoodDeliveryAndTrackingService.
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,6 @@
package doordash;

public interface TrackingService {

void trackPackage(String trackingNumber);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package facebook;

public interface Post {

void display();

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

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

class Post1 implements Post {
private String text;

public Post1(String text)
{
this.text = text;
}

public void setText(String text)
{
this.text = text;
}

public String getText()
{
return text;
}
// Constructor, getters, and setters for text

public void display() {
System.out.println(text);
// Code for displaying text post
}
}
84 changes: 84 additions & 0 deletions homework/src/HW1/submissions/partA/acyutaraman/facebook/Post2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package facebook;


//This is the new post class, that was implemented for our "Facebook" to help support images and videos.

public class Post2 implements Post{

private String text;
private String imageUrl;

private String videoUrl;
private boolean isImage;

private boolean isVideo;

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}

public String getImageUrl() {
return imageUrl;
}

public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}

public String getVideoUrl() {
return videoUrl;
}

public void setVideoUrl(String videoUrl) {
this.videoUrl = videoUrl;
}

public boolean isImage() {
return isImage;
}

public void setImage(boolean image) {
isImage = image;
}

public boolean isVideo() {
return isVideo;
}

public void setVideo(boolean video) {
isVideo = video;
}

public Post2(String text) {
this.text = text;
}

public Post2(String imageUrl, boolean isImage) {
if(isImage) {
this.imageUrl = imageUrl;
this.isImage = true;
}
}

public Post2(String videoUrl, boolean isImage, boolean isVideo){
if(isVideo && !isImage) {
this.videoUrl = videoUrl;
this.isImage = false;
this.isVideo = true;
}
}


public void display() {

if(isImage())
System.out.println(imageUrl);
if(isVideo())
System.out.println(videoUrl);
System.out.println(text);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

1) This class violates the Dependency Inversion Principle because of how it doesn't have any abstract interfaces to base the Post1 and Post2 off of. If you were to make the Post1 class
the superclass of Post2, Post2 would still be able to access methods from Post1 that it shouldn't be accessing. In this scenario, that would lead to a violation of the Open/Closed principle.

2) I fixed this by creating an abstract interface called Post that both Post1 and Post2 implement. The Post interface has one method called display, which is implemented differently in
Post1 and Post2. I added getter and setter methods for the text in Post1. For the display method in Post1, it just prints out the text in the post. For the display method in Post2, It returns the video url and the text in separate lines if it is a video post, it returns the image url and the text if it is an image post, and it returns just the text if it is neither a video post or an audio post.
13 changes: 13 additions & 0 deletions homework/src/HW1/submissions/partA/acyutaraman/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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package paypal;

public class Main {
public static void main(String[] args) {
PayPalGateway paymentProcessor = new PaymentProcessor();
Account account = new Account("1");
paymentProcessor.processPayment(account,100.0, 101);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package paypal;

public interface PayPalGateway {
void processPayment(Account account, double amount);
void processPayment(Account account, double amount, double balance);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package paypal;

public class PaymentProcessor implements PayPalGateway{



@Override
public void processPayment(Account account, double amount) {
System.out.println("Processing payment of $" + amount + " for acocunt " + account.getAccountID() + " using PayPal.");
}

@Override
public void processPayment(Account account, double amount, double balance) {

if(balance >= amount)
System.out.println("Processing payment of $" + amount + " for acocunt " + account.getAccountID() + " using PayPal.");
else
System.out.println("For account " + account + ": the amount you are attempting to pay is more than that which is present in your balance." );
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

1) Paypal violates the Dependency Inversion principle because of how it lacks an interface/ abstract entity as a base entity. It just has a PayPalGateWay object used in PayPalProcessor,
without any inheritance or abstraction involved.

2) I fixed this violation by making the PayPalGateWay an interface with the abstract method processPayment. I then had the PayPalProcessor class implement the interface, and had
the default processMethod() method print out the original line that was supposed to be printed out. I added functionality in the sense that I overloaded the processMethod() method.
The original one takes in only the account and the amount, and prints out a line. I added a new version of that method that takes in the account, the amount, and the balance. This
new version prints out an error message if the amount(for the payment) is greater than the balance in the user's account.
15 changes: 15 additions & 0 deletions homework/src/HW1/submissions/partA/acyutaraman/uber/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package uber;

public class Main {
public static void main(String[] args) {
Ride ride = new Ride(1,1);
User user = new User("jill");
user.setUsername("john_doe");

RideManager rideManager = new RideManager();

double fare = rideManager.calculateRideFare(ride);

rideManager.sendNotification(user, "Your ride fare is: $" + fare);
}
}
10 changes: 10 additions & 0 deletions homework/src/HW1/submissions/partA/acyutaraman/uber/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

1) Uber violates the Single Responsibility Principle of the SOLID principles. It does so because of its two methods, which are calculateRideFare() and sendNotification(). The calculateRideFate() method involves accessing the Ride class and making a calculation based off of that. The sendNotification() method accesses and intends to make modifications to the
User class. Since two different classes are being directly altered by the RideManagerClass, it violates the Single Responsiblity Principle.

2) I fixed this SOLID violation by creating the classes RideCalculator and NotificationSender, and having them handle the calculateRideFare() and sendNotifcation() methods respectively.
I placed a constructor for the RideCalculator class that takes in the amounts for minute_rate, mile_rate, and base_rate. The class then uses those values to calculate the fare value of
the given ride in its calculateRideFare() method. I also added message stack in the User class to contain all the messages. I added methods to initialize, add to, and read from the messages
stack. I then had the sendNotifcation() method in NotificationSender call the given User's addMessage() method to add the given message. It then prints out the given line it was initially
supposed to print. In the RideManager class, I initialized a RideCalculator object and a NotifcationSende object. For its calculateRideFare() method, it calls the calculateRideFare() method
for its RideCalculator object returns that value. That is how I added functionality to the RideManager class and fixed its violations. I also modified the main class.
Loading