Funktion zur Margenermittlung

This commit is contained in:
Shan Ruhhammer
2023-06-23 12:40:36 +02:00
parent 82a0569e9d
commit dce001f1b3

View File

@@ -1,6 +1,7 @@
package de.rwu.easydrop; package de.rwu.easydrop;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
@@ -26,9 +27,36 @@ import de.rwu.easydrop.util.ProductsConfig;
* die den Preis eines Produkts von den jeweiligen API's abruft. * die den Preis eines Produkts von den jeweiligen API's abruft.
*/ */
public final class PriceFetcher { public final class PriceFetcher {
static List<Double> api1Prices = new ArrayList<>();
static List<Double> api2Prices = new ArrayList<>();
private static final Logger LOGGER = LoggerFactory.getLogger(PriceFetcher.class); private static final Logger LOGGER = LoggerFactory.getLogger(PriceFetcher.class);
//Methode, um Preise der Prdukte zu vergleichen -> MArgen ermitteln
public static void comparePrices() throws ConfigurationException {
List<Double> api1Prices = new ArrayList<>();
List<Double> api2Prices = new ArrayList<>();
for (int i = 0; i < api1Prices.size(); i++) {
double api1Price = api1Prices.get(i);
double api2Price = api2Prices.get(i);
String productId = "Product " + (i + 1);
if (api1Price < api2Price) {
double priceDifference = api2Price - api1Price;
LOGGER.info("API 1 hat einen günstigeren Preis für " + productId +
". Der Preisunterschied beträgt: " + priceDifference);
} else if (api2Price < api1Price) {
double priceDifference = api1Price - api2Price;
LOGGER.info("API 2 hat einen günstigeren Preis für " + productId +
". Der Preisunterschied beträgt: " + priceDifference);
} else {
LOGGER.info("Beide APIs haben den gleichen Preis für " + productId);
}
}
}
// Methode, um Preise der Produkte zu ermitteln
public static void getProductPrice(final String[] args) throws ConfigurationException{ public static void getProductPrice(final String[] args) throws ConfigurationException{
Config config = Config.getInstance(); Config config = Config.getInstance();
@@ -55,7 +83,14 @@ public final class PriceFetcher {
String productId = product.getProductId(); String productId = product.getProductId();
double price = product.getCurrentPrice(); double price = product.getCurrentPrice();
LOGGER.info("Product ID: " + productId + ", Price: " + price); LOGGER.info("Product ID: " + productId + ", Price: " + price);
if (productId == "B096Y2TYKV") {
api1Prices.add(price);
} else if (productId == "Gigabyte GeForce RTX 3060") {
api2Prices.add(price);
}
} }
} }
} }
} }