Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Product {
- private int catId;
- private int channelPrice;
- public Product(int catId) {
- this.catId = catId;
- this.channelPrice = -1;
- }
- public Product(int catId, int channelPrice) {
- this.catId = catId;
- this.channelPrice = channelPrice;
- }
- public int getCatId() {
- return this.catId
- }
- public int getChannelPrice() {
- return this.channelPrice;
- }
- }
- class Category {
- private int id;
- public Category parent;
- private int price;
- public Category(int id, Category parent) {
- this.id = id;
- this.parent = parent;
- this.price = -1;
- }
- public Category(int id, Category parent, int price) {
- this.id = id;
- this.parent = parent;
- this.price = price;
- }
- public int getId() {
- return this.id;
- }
- public int getPrice() {
- return this.price;
- }
- public void setPrice(int price) {
- this.price = price;
- }
- }
- class FindPrice {
- public int findFinalPrice (List<Category> categories, Product item) {
- Category currentCat = null;
- for (Category cat : categories) {
- if (cat.getId() == item.getCatId()) {
- currentCat = cat;
- break;
- }
- }
- if (currentCat != null) {
- Category tmpCat = currentCat;
- while (currentCat.getPrice() == -1) {
- tmpCat = tmpCat.parent;
- }
- }
- return tmpCat.getPrice() > Product.getChannelPrice() ? tmpCat.getPrice() : Product.getChannelPrice();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement