Adds lecture note for SO in SOLID.

This commit is contained in:
Tanmay
2022-09-07 15:55:55 +01:00
parent 3f99684ed7
commit d24d8dc670
3 changed files with 293 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
package com.scaler.lld.questions;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
@AllArgsConstructor
@Getter
@Setter
public class Book {
private String name;
private String authorName;
private int year;
private int price;
private String isbn;
}

View File

@@ -0,0 +1,34 @@
package com.scaler.lld.questions;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class Invoice {
private Book book;
private Integer quantity;
private Double discountRate;
private Double taxRate;
@Getter(AccessLevel.NONE)
private double total; // Will not generate a getter
public Double getTotal() {
double price = ((book.getPrice() - book.getPrice() * discountRate) * this.quantity);
return price * (1 + taxRate);
}
public void printInvoice() {
System.out.println(quantity + "x " + book.getName() + " " + book.getPrice() + "$");
System.out.println("Discount Rate: " + discountRate);
System.out.println("Tax Rate: " + taxRate);
System.out.println("Total: " + total);
}
public void saveToFile(String filename) {
// Creates a file with given name and writes the invoice
}
}