From f6511309b118cb72abed38214eb52d4865a5ee19 Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 16:55:28 +0100 Subject: [PATCH] Optimizing: Price of Item is float now --- projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Item.java | 6 +++--- .../src/test/java/de/hs_fulda/ciip/projjpn/ItemTest.java | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Item.java b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Item.java index c92998d..3311467 100644 --- a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Item.java +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Item.java @@ -2,7 +2,7 @@ package de.hs_fulda.ciip.projjpn; public class Item { - private int price; + private float price; // customerReview // productTitle // description @@ -17,11 +17,11 @@ public class Item { availability = newAmount; } - public void updatePrice(int price) { + public void updatePrice(float price) { this.price = price; } - public int getCurrentPrice() { + public float getCurrentPrice() { return price; } } diff --git a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/ItemTest.java b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/ItemTest.java index d06afe2..cc367c9 100644 --- a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/ItemTest.java +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/ItemTest.java @@ -29,20 +29,19 @@ public class ItemTest extends TestCase { // Given Item item = new Item(); int quantity = 3; - int price = 5; + float price = 5; item.updateAvailability(quantity); item.updatePrice(price); // When - int expectedPrice = quantity * price; + float expectedPrice = quantity * price; // Then - int actualPrice = 0; + float actualPrice = 0; for(int i = 0; i < quantity; i++) { actualPrice += item.getCurrentPrice(); } - assertEquals(expectedPrice, actualPrice); } }