-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
132 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,5 @@ | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class App { | ||
public static void main(String[] args) throws Exception { | ||
System.out.println("Hello!"); | ||
|
||
Stock( new Item("lolodmc69", 1000, 2)); | ||
Stock( new Item("jeo9", 1000, 2)); | ||
System.out.println("Hello, World!"); | ||
} | ||
} | ||
class Item { | ||
String code; | ||
double price; | ||
double quantity; | ||
|
||
public Item(String code, double price, double quantity) { | ||
this.code = code; | ||
this.price = price; | ||
this.quantity = quantity; | ||
} | ||
|
||
} | ||
|
||
public static class Stock{ | ||
public Stock( List<Item> items){ | ||
items.add(new Item(code, price, quantity)); | ||
items | ||
} | ||
public boolean isAvailableQuantity(Item x){ | ||
if (items.equals(x.code) && Items.quantity < x.quantity) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
class ShopingCart{ | ||
public ShopingCart( List<Item> cartItems){ | ||
cartItems.add(new Item(code, price, quantity)); | ||
} | ||
public void removeFromCart(Item item){ | ||
if (cartItems.contains(item)) { | ||
cartItems.remove(item); | ||
} | ||
} | ||
|
||
public boolean add(Item item){ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
public class Book { | ||
String name; | ||
String authorName; | ||
int year; | ||
int price; | ||
String isbn; | ||
|
||
public Book(String name, String authorName, int year, int price, String isbn) { | ||
this.name = name; | ||
this.authorName = authorName; | ||
this.year = year; | ||
this.price = price; | ||
this.isbn = isbn; | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
SingleResponsibilityPrinciple/src/InvoiceBestPractice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
public class InvoiceBestPractice { | ||
private Book book; | ||
private int quantity; | ||
private double discountRate; | ||
private double taxRate; | ||
private double total; | ||
|
||
public InvoiceBestPractice(Book book, int quantity, double discountRate, double taxRate, double total) { | ||
this.book = book; | ||
this.quantity = quantity; | ||
this.discountRate = discountRate; | ||
this.taxRate = taxRate; | ||
this.total = total; | ||
} | ||
|
||
public double calculateTotal() { | ||
double price = ((book.price - book.price * discountRate) * this.quantity); | ||
double priceWithTaxes = price * (1 + taxRate); | ||
return priceWithTaxes; | ||
} | ||
|
||
public Book getBook() { | ||
return this.book; | ||
} | ||
|
||
public void setBook(Book book) { | ||
this.book = book; | ||
} | ||
|
||
public int getQuantity() { | ||
return this.quantity; | ||
} | ||
|
||
public void setQuantity(int quantity) { | ||
this.quantity = quantity; | ||
} | ||
|
||
public double getDiscountRate() { | ||
return this.discountRate; | ||
} | ||
|
||
public void setDiscountRate(double discountRate) { | ||
this.discountRate = discountRate; | ||
} | ||
|
||
public double getTaxRate() { | ||
return this.taxRate; | ||
} | ||
|
||
public void setTaxRate(double taxRate) { | ||
this.taxRate = taxRate; | ||
} | ||
|
||
public double getTotal() { | ||
return this.total; | ||
} | ||
|
||
public void setTotal(double total) { | ||
this.total = total; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
public class InvoicePersistence { | ||
InvoiceBestPractice invoice; | ||
public InvoicePersistence(InvoiceBestPractice invoice){ | ||
this.invoice = invoice; | ||
} | ||
public void saveToFile(String fileName){ | ||
//Creates a file with given name and writes the invoice | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public class InvoicePrinter { | ||
InvoiceBestPractice invoice; | ||
public void InvoicePrinter(InvoiceBestPractice invoice){ | ||
this.invoice = invoice; | ||
} | ||
public void print(){ | ||
System.out.println(invoice.getQuantity() +" x "+invoice.getBook().name+" "+invoice.getBook().price+" $ "); | ||
System.out.println("Discount Rate :" + invoice.getDiscountRate()); | ||
System.out.println("Tax Rate :" + invoice.getTaxRate()); | ||
System.out.println("Total :"+ invoice.getTotal()); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
SingleResponsibilityPrinciple/src/InvoiceWorsePractice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
public class InvoiceWorsePractice { | ||
// WORSE PRACTICE | ||
private Book book; | ||
private int quantity; | ||
private double discountRate; | ||
private double taxRate; | ||
private double total; | ||
|
||
|
||
public InvoiceWorsePractice(Book book, int quantity, double discountRate, double taxRate, double total) { | ||
this.book = book; | ||
this.quantity = quantity; | ||
this.discountRate = discountRate; | ||
this.taxRate = taxRate; | ||
this.total = total; | ||
} | ||
|
||
public double calculateTotal(){ | ||
double price = ((book.price - book.price*discountRate)*this.quantity); | ||
double priceWithTaxes = price * (1 + taxRate); | ||
return priceWithTaxes; | ||
} | ||
public void printInvoice(){ | ||
System.out.println(quantity+" x "+book.name+" "+book.price+" $ "); | ||
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 | ||
} | ||
} |