diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..cd487c2 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..67e1e61 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/manuela/pom.xml b/manuela/pom.xml new file mode 100644 index 0000000..00fa07d --- /dev/null +++ b/manuela/pom.xml @@ -0,0 +1,46 @@ + + + tutorial-java + com.imalittletester + 1.0-SNAPSHOT + + 4.0.0 + + manuela + jar + + manuela + http://maven.apache.org + + + + org.apache.maven.plugins + maven-compiler-plugin + + 14 + 14 + + + + + + + UTF-8 + + + + + + org.apache.commons + commons-lang3 + 3.12.0 + + + + commons-io + commons-io + 2.11.0 + + + diff --git a/manuela/src/main/java/com/imalittletester/Assesment/EventData.java b/manuela/src/main/java/com/imalittletester/Assesment/EventData.java new file mode 100644 index 0000000..ff6df07 --- /dev/null +++ b/manuela/src/main/java/com/imalittletester/Assesment/EventData.java @@ -0,0 +1,28 @@ +package com.imalittletester.Assesment; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Locale; + +public class EventData { + public int steps; + public Calendar date; + + public EventData(int steps, Calendar date) { + this.steps = steps; + this.date = date; + } + + public EventData(int steps, String date) { + this.steps = steps; + Calendar cal = Calendar.getInstance(); + SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy hh:mm", Locale.ENGLISH); + try { + cal.setTime(sdf.parse(date)); + this.date = cal; + } catch (ParseException e) { + throw new RuntimeException(e); + } + } +} diff --git a/manuela/src/main/java/com/imalittletester/Assesment/Senzor.java b/manuela/src/main/java/com/imalittletester/Assesment/Senzor.java new file mode 100644 index 0000000..4675d04 --- /dev/null +++ b/manuela/src/main/java/com/imalittletester/Assesment/Senzor.java @@ -0,0 +1,103 @@ +package com.imalittletester.Assesment; + +import java.util.*; + +public class Senzor { + public List eventDataList; + public List uomAndDateList; + + public Senzor(List eventDataList, List uomAndDateList) { + this.eventDataList = eventDataList; + this.uomAndDateList = uomAndDateList; + } + + public int getStepCountByDate(Calendar date) { + int stepCount = 0; + for (int i = 0; i < eventDataList.size(); i++) { + if (date.get(Calendar.YEAR) == eventDataList.get(i).date.get(Calendar.YEAR) && + date.get(Calendar.MONTH) == eventDataList.get(i).date.get(Calendar.MONTH) && + date.get(Calendar.DATE) == eventDataList.get(i).date.get(Calendar.DATE) && + eventDataList.get(i).date.before(date)) { + stepCount = stepCount + eventDataList.get(i).steps; + } + } + return stepCount; + } + + public void createEventDataAndUomAndDataListRandom() { + this.eventDataList = new ArrayList<>(); + this.uomAndDateList = new ArrayList<>(); + Calendar date = Calendar.getInstance(); + Random rn = new Random(); + for (int day = 0; day <= 14; day++) { + for (int hour = 0; hour <= 23; hour++) { + for (int minute = 0; minute <= 59; minute++) { + int steps = rn.nextInt(20 - 1 + 1) + 1; + Calendar date1 = Calendar.getInstance(); + date1.set(Calendar.DATE, date.get(Calendar.DATE) - day); + date1.set(Calendar.HOUR, hour); + date1.set(Calendar.MINUTE, minute); + date1.set(Calendar.SECOND, 0); + date1.set(Calendar.MILLISECOND, 0); + date1.set(Calendar.MONTH, date.get(Calendar.MONTH)); + date1.set(Calendar.YEAR, date.get(Calendar.YEAR)); + eventDataList.add(new EventData(steps, date1)); + } + } + Calendar date2 = Calendar.getInstance(); + date2.set(Calendar.DATE, date.get(Calendar.DATE) - day); + date2.set(Calendar.SECOND, 0); + date2.set(Calendar.MILLISECOND, 0); + date2.set(Calendar.MONTH, date.get(Calendar.MONTH)); + date2.set(Calendar.YEAR, date.get(Calendar.YEAR)); + if (day % 2 == 0) { + uomAndDateList.add(new UomAndDate("km", date2, 1000)); + } else { + uomAndDateList.add(new UomAndDate("mi", date2, 1600)); + } + } + } + + public void createEventDataAndUomAndDataListSpecific() { + this.eventDataList = new ArrayList<>(); + this.uomAndDateList = new ArrayList<>(); + + uomAndDateList.add(new UomAndDate("km", "11-21-2022 15:12", 1000)); + uomAndDateList.add(new UomAndDate("km", "11-22-2022 15:12", 1000)); + uomAndDateList.add(new UomAndDate("mi", "11-23-2022 15:12", 1600)); + uomAndDateList.add(new UomAndDate("mi", "11-24-2022 15:12", 1600)); + uomAndDateList.add(new UomAndDate("mi", "11-25-2022 15:12", 1600)); + uomAndDateList.add(new UomAndDate("mi", "11-26-2022 15:12", 1600)); + uomAndDateList.add(new UomAndDate("mi", "11-27-2022 15:12", 1600)); + uomAndDateList.add(new UomAndDate("km", "11-28-2022 15:12", 1000)); + uomAndDateList.add(new UomAndDate("km", "11-29-2022 15:12", 1000)); + uomAndDateList.add(new UomAndDate("mi", "11-20-2022 15:12", 1600)); + uomAndDateList.add(new UomAndDate("mi", "11-19-2022 15:12", 1600)); + eventDataList.add(new EventData(7000, "11-29-2022 09:12")); + eventDataList.add(new EventData(15000, "11-28-2022 09:12")); + eventDataList.add(new EventData(7000, "11-27-2022 09:12")); + eventDataList.add(new EventData(15000, "11-26-2022 09:12")); + eventDataList.add(new EventData(7000, "11-25-2022 09:12")); + eventDataList.add(new EventData(15000, "11-24-2022 09:12")); + eventDataList.add(new EventData(11, "11-24-2022 09:12")); + eventDataList.add(new EventData(11, "11-23-2022 09:12")); + eventDataList.add(new EventData(1000, "11-23-2022 12:12")); + eventDataList.add(new EventData(1000, "11-23-2022 14:12")); + eventDataList.add(new EventData(11, "11-23-2022 18:12")); + eventDataList.add(new EventData(22, "11-23-2022 21:12")); + eventDataList.add(new EventData(1000, "11-22-2022 07:12")); + eventDataList.add(new EventData(500, "11-22-2022 11:12")); + eventDataList.add(new EventData(4000, "11-22-2022 15:12")); + eventDataList.add(new EventData(22, "11-22-2022 21:59")); + eventDataList.add(new EventData(11, "11-21-2022 11:12")); + eventDataList.add(new EventData(55, "11-21-2022 21:59")); + eventDataList.add(new EventData(7000, "11-21-2022 13:12")); + eventDataList.add(new EventData(11, "11-20-2022 15:12")); + eventDataList.add(new EventData(11, "11-20-2022 10:13")); + eventDataList.add(new EventData(55, "11-19-2022 15:12")); + eventDataList.add(new EventData(12, "11-19-2022 17:13")); + eventDataList.add(new EventData(11, "11-19-2022 19:14")); + eventDataList.add(new EventData(11, "11-19-2022 20:14")); + + } +} diff --git a/manuela/src/main/java/com/imalittletester/Assesment/UomAndDate.java b/manuela/src/main/java/com/imalittletester/Assesment/UomAndDate.java new file mode 100644 index 0000000..2defb61 --- /dev/null +++ b/manuela/src/main/java/com/imalittletester/Assesment/UomAndDate.java @@ -0,0 +1,31 @@ +package com.imalittletester.Assesment; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Locale; + +public class UomAndDate { + public String uom; + public Calendar date; + public int stepsPerUom; + + public UomAndDate(String uom, Calendar date, int stepsPerUom) { + this.uom = uom; + this.date = date; + this.stepsPerUom = stepsPerUom; + } + + public UomAndDate(String uom, String date, int stepsPerUom) { + this.uom = uom; + Calendar cal = Calendar.getInstance(); + SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy hh:mm", Locale.ENGLISH); + try { + cal.setTime(sdf.parse(date)); + this.date = cal; + } catch (ParseException e) { + throw new RuntimeException(e); + } + this.stepsPerUom = stepsPerUom; + } +} diff --git a/manuela/src/main/java/com/imalittletester/Assesment/UserData.java b/manuela/src/main/java/com/imalittletester/Assesment/UserData.java new file mode 100644 index 0000000..ef10904 --- /dev/null +++ b/manuela/src/main/java/com/imalittletester/Assesment/UserData.java @@ -0,0 +1,157 @@ +package com.imalittletester.Assesment; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; + +public class UserData { + public String userName; + public Senzor senzor; + public Calendar sleepTime; + public Calendar wakeTime; + + public UserData(String userName, Senzor senzor, String sleepTime, String wakeTime) { + this.userName = userName; + this.senzor = senzor; + Calendar cal = Calendar.getInstance(); + SimpleDateFormat sdf = new SimpleDateFormat("hh:mm", Locale.ENGLISH); + try { + cal.setTime(sdf.parse(sleepTime)); + this.sleepTime = cal; + } catch (ParseException e) { + throw new RuntimeException(e); + } + cal = Calendar.getInstance(); + try { + cal.setTime(sdf.parse(wakeTime)); + this.wakeTime = cal; + } catch (ParseException e) { + throw new RuntimeException(e); + } + } + + + public String getCurrentDayStepCount() { + int totalSteps = this.senzor.getStepCountByDate(Calendar.getInstance()); + return "The user: " + userName + " did " + totalSteps + " steps until now."; + } + + public String getCurrentDayDistance(Calendar date) { + int stepsPerUom = 0; + String uom = ""; + for (int i = 0; i < this.senzor.uomAndDateList.size(); i++) { + if (date.get(Calendar.YEAR) == this.senzor.uomAndDateList.get(i).date.get(Calendar.YEAR) && + date.get(Calendar.MONTH) == this.senzor.uomAndDateList.get(i).date.get(Calendar.MONTH) && + date.get(Calendar.DATE) == this.senzor.uomAndDateList.get(i).date.get(Calendar.DATE)) { + stepsPerUom = this.senzor.uomAndDateList.get(i).stepsPerUom; + uom = this.senzor.uomAndDateList.get(i).uom; + break; + } + } + int todaySteps = this.senzor.getStepCountByDate(Calendar.getInstance()); + double distance = 1.0 * todaySteps / stepsPerUom; + return "Today distance is: " + distance + " " + uom; + } + + public String nrOfCaloriesCurrentDay() { + int calories = 0; + int todaySteps = this.senzor.getStepCountByDate(Calendar.getInstance()); + calories = (5 * todaySteps) / 1000; + return "Today calories number is: " + calories; + } + + public String nrOfAlerts() { + + Calendar cal = Calendar.getInstance(); + Map stepsPerHour = new HashMap<>(); + for (int j = this.wakeTime.get(Calendar.HOUR_OF_DAY); j < this.sleepTime.get(Calendar.HOUR_OF_DAY); j++) { + stepsPerHour.put(j, 0); + for (int i = 0; i < this.senzor.eventDataList.size(); i++) { + if (cal.get(Calendar.YEAR) == this.senzor.eventDataList.get(i).date.get(Calendar.YEAR) && + cal.get(Calendar.MONTH) == this.senzor.eventDataList.get(i).date.get(Calendar.MONTH) && + cal.get(Calendar.DATE) == this.senzor.eventDataList.get(i).date.get(Calendar.DATE)) { + if (j == this.senzor.eventDataList.get(i).date.get(Calendar.HOUR_OF_DAY)) { + int st = stepsPerHour.get(j); + st = st + this.senzor.eventDataList.get(i).steps; + stepsPerHour.put(j, st); + } + } + } + } + int alertNumber = 0; + for (int i = this.wakeTime.get(Calendar.HOUR_OF_DAY); i < this.sleepTime.get(Calendar.HOUR_OF_DAY); i++) { + if (stepsPerHour.get(i) == 0) { + alertNumber++; + } + } + + return "The number of idle alerts for current day is: " + alertNumber; + } + + public void distance7Days() { + double distanceKm = 0; + double distanceMi = 0; + Calendar calendar = Calendar.getInstance(); + for (int j = 0; j < 7; j++) { + Calendar cal2 = Calendar.getInstance(); + cal2.set(Calendar.DATE, calendar.get(Calendar.DATE) - j); + //int stepsPerUom = 0; + // String uom = ""; + for (int i = 0; i < this.senzor.uomAndDateList.size(); i++) { + if (cal2.get(Calendar.YEAR) == this.senzor.uomAndDateList.get(i).date.get(Calendar.YEAR) && + cal2.get(Calendar.MONTH) == this.senzor.uomAndDateList.get(i).date.get(Calendar.MONTH) && + cal2.get(Calendar.DATE) == this.senzor.uomAndDateList.get(i).date.get(Calendar.DATE)) { + // stepsPerUom = this.senzor.uomAndDateList.get(i).stepsPerUom; + // uom = this.senzor.uomAndDateList.get(i).uom; + + //int todaySteps = this.senzor.getStepCountByDate(cal2); + // this.senzor.uomAndDateList.get(i).totalDistance += todaySteps; + // break; + int todaySteps = this.senzor.getStepCountByDate(cal2); + if (this.senzor.uomAndDateList.get(i).uom == "km") { + if (this.senzor.uomAndDateList.get(i).stepsPerUom != 0) { + distanceKm = 1.0 * todaySteps / this.senzor.uomAndDateList.get(i).stepsPerUom; + } + } else { + + if (this.senzor.uomAndDateList.get(i).stepsPerUom != 0) { + distanceMi = 1.0 * todaySteps / this.senzor.uomAndDateList.get(i).stepsPerUom; + } + } + } + } + } + + System.out.println("In the last 7 days the user did: " + distanceKm + " km, and " + distanceMi + " mi"); + } + + public void DateAndHour() { + Calendar cal = Calendar.getInstance(); + SimpleDateFormat format1 = new SimpleDateFormat("MMMM dd yyyy, HH:mm"); + String formatted = format1.format(cal.getTime()); + System.out.println("Current Date And Time : " + formatted); + } + + public void afisajTotal() { + System.out.println("----------------"); + this.senzor.createEventDataAndUomAndDataListRandom(); + System.out.println("Random By User: "); + System.out.println(this.getCurrentDayStepCount()); + System.out.println(getCurrentDayDistance(Calendar.getInstance())); + System.out.println(nrOfCaloriesCurrentDay()); + System.out.println(nrOfAlerts()); + distance7Days(); + + System.out.println("----------------"); + this.senzor.createEventDataAndUomAndDataListSpecific(); + System.out.println("Specific By User: "); + System.out.println(this.getCurrentDayStepCount()); + System.out.println(getCurrentDayDistance(Calendar.getInstance())); + System.out.println(nrOfCaloriesCurrentDay()); + System.out.println(nrOfAlerts()); + distance7Days(); + DateAndHour(); + } + +} + diff --git a/manuela/src/main/java/com/imalittletester/cookie/Cookie.java b/manuela/src/main/java/com/imalittletester/cookie/Cookie.java new file mode 100644 index 0000000..4ec34f3 --- /dev/null +++ b/manuela/src/main/java/com/imalittletester/cookie/Cookie.java @@ -0,0 +1,62 @@ +package com.imalittletester.cookie; + +import org.w3c.dom.ls.LSOutput; + +import java.sql.SQLOutput; + +public class Cookie { + public String name; + public String value; + public String domain; + public String path; + public String expires; + public int size; + public boolean httpOnly; + public boolean secure; + public String sameSite; + public boolean sameParty; + public String partitionKey; + public String priority; + + //priority can be an enum type + //default constructor + public Cookie() { + } + + //constructor only name and value + public Cookie(String domain) { + + this.domain = domain; + } + + public Cookie(String name, String value, String domain, String path, String expires, int size, boolean httpOnly, boolean secure, String sameSite, boolean sameParty, String partitionKey, String priority) { + this.name = name; + this.value = value; + this.domain = domain; + this.path = path; + this.expires = expires; + this.size = size; + this.httpOnly = httpOnly; + this.secure = secure; + this.sameSite = sameSite; + this.sameParty = sameParty; + this.partitionKey = partitionKey; + this.priority = priority; + } + + public void diplayCookie() { + System.out.println("The name of the cookie is " + name + "with the domain " + domain); + System.out.println("The value of the cookie is: " + value); + System.out.println("The domain of the cookie is: " + domain); + System.out.println("To access the cookie " + name + " use the path: " + path); + System.out.println("The cookie " + name + " with domain " + domain + " expires on " + expires); + } + + //Not sure about the requirements, but on CookieTest.java returns false or true based on entered value + public boolean isProvidedParamSubDomainOfDomain(String isSubDomainOfDomain) { + //if (domain.contains(isSubDomainOfDomain)) { + // return true; + //} else {// return false; + return domain.contains(isSubDomainOfDomain); + } +} \ No newline at end of file diff --git a/manuela/src/main/java/com/imalittletester/jam/AppricotJam.java b/manuela/src/main/java/com/imalittletester/jam/AppricotJam.java new file mode 100644 index 0000000..7e63c61 --- /dev/null +++ b/manuela/src/main/java/com/imalittletester/jam/AppricotJam.java @@ -0,0 +1,93 @@ +package com.imalittletester.jam; + +import org.apache.commons.lang3.builder.ToStringExclude; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +//inhierence +public class AppricotJam extends Jam { + + //fields +// public float apricotQty; +// public String apricotUom; + + public Jar jar; + + //method + //constructor + public AppricotJam() { + } + + public AppricotJam(String sweetener) { + super(sweetener); + } + +// public AppricotJam(String sweetener, float sweetenerQty, String sweetenerUom,List fruits, Jar jar) { +// super(sweetener, sweetenerQty, sweetenerUom, fruits); //the supper class Jam +// //super(fruitQty, fruitUom,sweetener, sweetenerQty, sweetenerUom, isDietetic); +//// this.apricotQty = apricotQty; +//// this.apricotUom = apricotUom; +// this.jar = jar; +// +// } + + + public AppricotJam(String sweetener, float sweetenerQty, String sweetenerUom, List fruits, Jar jar) { + super(sweetener, sweetenerQty, sweetenerUom, fruits); + this.jar = jar; + } + + @Override + public void makeJam() { + super.makeJam(); + fruits.add(new Fruits("appricot", 1.5, "kg")); + System.out.println("Also adding: " + fruits.get(0).fruitsQty + " " + fruits.get(0).fruitUom + " of " + fruits.get(0).fruitName); + //System.out.println("Also adding: " + fruitQty + " " + fruitUom + " of apricots"); + // System.out.println("Boiling for " + preparationTime() + " minutes"); + //System.out.println("Having " + jar.jarQty + " jars" + " " + "of capacity: " + jar.jarCapacity); + + } + + private int preparationTime() { + return 30; + } + + @Override + public String toString() { + return "AppricotJam{" + + "sweetener='" + sweetener + '\'' + + ", sweetenerQty=" + sweetenerQty + + ", sweetenerUom='" + sweetenerUom + '\'' + + // ", apricotQty=" + fruits.get(0).fruitsQty+ + /// ", apricotUom='" + fruits.get(0).fruitUom + '\'' + + //", apricotQty=" + fruitQty + + // ", apricotUom='" + fruitUom + '\'' + + ", jarQty=" + jar + + ", jarCapacity=" + jar + + ", isDietetic=" + isDietetic + + '}'; + } + +// @Override +// public boolean equals(Object o) { +// if (this == o) return true; +// if (o == null || getClass() != o.getClass()) return false; +// AppricotJam that = (AppricotJam) o; +// return Float.compare(that.fruits.get(0).fruitsQty, fruits.get(0).fruitsQty) == 0 && Objects.equals(fruits.get(0).fruitUom, that.fruits.get(0).fruitUom) && Objects.equals(jar, that.jar); +// } +// +// @Override +// public int hashCode() { +// return Objects.hash(apricotQty, apricotUom, jar); +// } + + public int howManyFullJars(int jamQtyInGrams) { + return jamQtyInGrams / jar.jarCapacity; + } + + public int remainderJam(int jamQtyInGrams) { + return jamQtyInGrams % jar.jarCapacity; + } +} diff --git a/manuela/src/main/java/com/imalittletester/jam/Bottle.java b/manuela/src/main/java/com/imalittletester/jam/Bottle.java new file mode 100644 index 0000000..41b0a93 --- /dev/null +++ b/manuela/src/main/java/com/imalittletester/jam/Bottle.java @@ -0,0 +1,11 @@ +package com.imalittletester.jam; + +public class Bottle { + public int bottleQty; //how many we have 7, 11 + public int bottleCapacity; //250, 200 + + public Bottle(int bottleQty, int bottleCapacity) { + this.bottleQty = bottleQty; + this.bottleCapacity = bottleCapacity; + } +} diff --git a/manuela/src/main/java/com/imalittletester/jam/Fruits.java b/manuela/src/main/java/com/imalittletester/jam/Fruits.java new file mode 100644 index 0000000..7da2f1b --- /dev/null +++ b/manuela/src/main/java/com/imalittletester/jam/Fruits.java @@ -0,0 +1,18 @@ +package com.imalittletester.jam; + +import java.util.ArrayList; +import java.util.List; + +public class Fruits { + public String fruitName; + public double fruitsQty; + public String fruitUom; + + public Fruits(String fruitName, double fruitsQty, String fruitUom) { + this.fruitName = fruitName; + this.fruitsQty = fruitsQty; + this.fruitUom = fruitUom; + } + + +} diff --git a/manuela/src/main/java/com/imalittletester/jam/Jam.java b/manuela/src/main/java/com/imalittletester/jam/Jam.java new file mode 100644 index 0000000..29bd3da --- /dev/null +++ b/manuela/src/main/java/com/imalittletester/jam/Jam.java @@ -0,0 +1,148 @@ +package com.imalittletester.jam; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class Jam { + + //Homework T3 + //public float fruitQty; +// public String fruitUom; +// public String fruitType; + +// public Jam(float fruitQty, String fruitUom, String fruitType, String sweetener, float sweetenerQty, String sweetenerUom, boolean isDietetic) { +// this.fruitQty = fruitQty; +// this.fruitUom = fruitUom; +// this.fruitType = fruitType; +// this.sweetener = sweetener; +// this.sweetenerQty = sweetenerQty; +// this.sweetenerUom = sweetenerUom; +// this.isDietetic = isDietetic; +// } + //In clasa AppricotJam - in constructorul cu toate valorile as scrie: + + //public AppricotJam(String sweetener, float sweetenerQty, String sweetenerUom, float fruitQty, String fruitUom, String fruitType, Jar jar, boolean isDietetic) + // { + // super(sweetener, sweetenerQty, sweetenerUom, fruitQty, fruitUom, fruitType, isDietetic); + // this.jar = jar; + // } + + //As inlocui astea unde mai este necesar in AppricotJam si MelonJam in loc de: + // public float melonQty; + // public String melonUom; + + public String sweetener; + public float sweetenerQty; + public String sweetenerUom; + + public boolean isDietetic; + public List fruits; + + // List fruits = new ArrayList<>(); +// public Jam(String sweetener, float sweetenerQty, String sweetenerUom, List fruits) { +// this.sweetener = sweetener; +// this.sweetenerQty = sweetenerQty; +// this.sweetenerUom = sweetenerUom; +// this.isDietetic = (this.sweetener == "stevia") || (this.sweetener == "sucralose"); +// this.fruits = fruits; +// } + + + public Jam(String sweetener, float sweetenerQty, String sweetenerUom, List fruits) { + this.sweetener = sweetener; + this.sweetenerQty = sweetenerQty; + this.sweetenerUom = sweetenerUom; + this.isDietetic = (this.sweetener == "stevia") || (this.sweetener == "sucralose"); + this.fruits = fruits; + } + + public Jam() { + } + + public Jam(String sweetener) { + this.sweetener = sweetener; + } + + + public void makeJam() { + + //System.out.println("Adding " + sweetenerQty + " " + sweetenerUom + " of " +sweetener); +// if(isDietetic){ +// System.out.println("Is jam dietetic? Yes"); +// } +// else{ +// System.out.println("Is jam dietetic? No"); +// } + //System.out.println("Is jam dietetic? " + isDietetic); + + + //using Simplified if + System.out.println(isDietetic ? "Is jam dietetic? Yes" : "Is jam dietetic? No"); + + } + + public double qtyInGramsUsingIf(String uom, double qty) { + double mustMultipleBy = 1; + //equalsIgnoreCase - nu tine cont de uppercase sau lowercase + if (uom.equalsIgnoreCase("kg") || uom.equalsIgnoreCase("kilograms")) { + mustMultipleBy = 1000; + } + if (uom.equalsIgnoreCase("micrograms")) { + mustMultipleBy = 0.0001; + } + return qty * mustMultipleBy; + } +// metoda ce arunca o eroare + public double qtyInGramsUsingIfSimple(String uom, double qty) { + if (uom.equalsIgnoreCase("kg") || uom.equalsIgnoreCase("kilograms")) { + return qty * 1000; //odata rulat return se iese din metoda si al doilea if nu se mai executa + } + if (uom.equalsIgnoreCase("micrograms")) { + return qty / 1000; + } + if (uom.equalsIgnoreCase("grams")){ + return qty; + } + throw new RuntimeException(("The unit of measure provided was not valid!")); + } + //kg, kilograms, micrograms, grams, jajs + public double qtyInGramsUsingSwitch(String uom, double qty){ + double valueToReturn = 0; + switch(uom.toLowerCase()){ + case "kg", "kilograms" -> {valueToReturn = qty * 1000;} + case "grams" -> {valueToReturn = qty;} + case "micrograms" -> {valueToReturn = qty / 1000;} + } + return valueToReturn; + } + + public double qtyInGramsUsingSwitchSimple(String uom, double qty){ + switch(uom.toLowerCase()) { + case "kg", "kilograms" -> {return qty * 1000;} + case "grams" -> {return qty;} + case "micrograms" -> {return qty / 1000;} + default -> {return 0;} + } + + } + public String getSweetener() { + return sweetener; + } + + public void setSweetener(String sweetener) { + this.sweetener = sweetener; + } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Jam jam = (Jam) o; + return Float.compare(jam.sweetenerQty, sweetenerQty) == 0 && isDietetic == jam.isDietetic && Objects.equals(sweetener, jam.sweetener) && Objects.equals(sweetenerUom, jam.sweetenerUom); + } + + @Override + public int hashCode() { + return Objects.hash(sweetener, sweetenerQty, sweetenerUom, isDietetic); + } +} diff --git a/manuela/src/main/java/com/imalittletester/jam/Jar.java b/manuela/src/main/java/com/imalittletester/jam/Jar.java new file mode 100644 index 0000000..52d5513 --- /dev/null +++ b/manuela/src/main/java/com/imalittletester/jam/Jar.java @@ -0,0 +1,11 @@ +package com.imalittletester.jam; + +public class Jar { + public int jarQty; + public int jarCapacity; + + public Jar(int jarQty, int jarCapacity) { + this.jarQty = jarQty; + this.jarCapacity = jarCapacity; + } +} diff --git a/manuela/src/main/java/com/imalittletester/jam/MelonJam.java b/manuela/src/main/java/com/imalittletester/jam/MelonJam.java new file mode 100644 index 0000000..a5b6f81 --- /dev/null +++ b/manuela/src/main/java/com/imalittletester/jam/MelonJam.java @@ -0,0 +1,50 @@ +package com.imalittletester.jam; + +import java.util.List; +import java.util.Objects; + +public class MelonJam extends Jam { + //attribute - properties of the object +// public float melonQty; +// public String melonUom; + + public Bottle bottle; + + public MelonJam(String sweetener, float sweetenerQty, String sweetenerUom, List fruits, Bottle bottle) { + super(sweetener, sweetenerQty, sweetenerUom, fruits); //the supper class Jam +// this.melonQty = melonQty; +// this.melonUom = melonUom; + this.bottle = bottle; + + } + + public MelonJam() { + } + + public MelonJam(String sweetener) { + super(sweetener); + } + +// @Override +// public boolean equals(Object o) { +// if (this == o) return true; +// if (o == null || getClass() != o.getClass()) return false; +// MelonJam melonJam = (MelonJam) o; +// return Float.compare(melonJam.melonQty, melonQty) == 0 && Objects.equals(melonUom, melonJam.melonUom) && Objects.equals(bottle, melonJam.bottle); +// } +// +// @Override +// public int hashCode() { +// return Objects.hash(melonQty, melonUom, bottle); +// } + + @Override + //method that does not return anything + public void makeJam() { + super.makeJam(); + fruits.add(new Fruits("melon", 2, "kg")); + System.out.println("Adding " + fruits.get(0).fruitsQty + " " + fruits.get(0).fruitUom + " of " + fruits.get(0).fruitName); + System.out.println("Bottling in: " + bottle.bottleQty + " bottles of capacity: " + bottle.bottleCapacity); + + } +} diff --git a/manuela/src/main/java/com/imalittletester/utils/UnitOfMeasureConverter.java b/manuela/src/main/java/com/imalittletester/utils/UnitOfMeasureConverter.java new file mode 100644 index 0000000..a07e90c --- /dev/null +++ b/manuela/src/main/java/com/imalittletester/utils/UnitOfMeasureConverter.java @@ -0,0 +1,61 @@ +package com.imalittletester.utils; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.spi.CalendarDataProvider; + +public class UnitOfMeasureConverter { + public int lastDayOfMonthDay; + + public UnitOfMeasureConverter(int lastDayOfMonthDay) { + this.lastDayOfMonthDay = lastDayOfMonthDay; + + } + + public double qtyInGramsUsingIf2(String uom, double qty) { + double mustMultipleBy = 1; + //equalsIgnoreCase - nu tine cont de uppercase sau lowercase + if (uom.equalsIgnoreCase("kg") || uom.equalsIgnoreCase("kilograms")) { + mustMultipleBy = 1000; + } + if (uom.equalsIgnoreCase("micrograms")) { + mustMultipleBy = 0.0001; + } + return qty * mustMultipleBy; + } + + public boolean lastDayOfProvidedMonth(String month, int day, int year) { + switch (month) { + case "Ianuarie", "Martie", "Mai", "Iulie", "August", "Octombrie", "Decembrie" -> { + if (day == 31) { + return true; + } + } + case "Aprilie", "Iunie", "Septembrie", "Noiembrie" -> { + if (day == 30) { + return true; + } + } + case "Februarie" -> { + if ((year % 4 == 0 && day == 29) || (year % 4 != 0 && day == 28)) { + return true; + } + } + default ->{return false;} + } + return false; + + } + public int divideBySeven(int providedNumber){ + int j=0; + for(int i =1; i<= providedNumber; i++){ + if(i%7==0){ + j++; + } + } + return j; + } + +} diff --git a/manuela/src/test/java/com/imalittletester/Assesment/AssesmentTests.java b/manuela/src/test/java/com/imalittletester/Assesment/AssesmentTests.java new file mode 100644 index 0000000..ecfc72e --- /dev/null +++ b/manuela/src/test/java/com/imalittletester/Assesment/AssesmentTests.java @@ -0,0 +1,16 @@ +package com.imalittletester.Assesment; + +import org.junit.jupiter.api.Test; + +public class AssesmentTests { + public UserData userData1 = new UserData("Manuela", new Senzor(null, null), "22:00", "06:00"); + public UserData userData2 = new UserData("Daniel", new Senzor(null, null), "23:00", "06:00"); + public UserData userData3 = new UserData("Alex", new Senzor(null, null), "20:00", "06:00"); + @Test + void stepsForCurrentDay() { + userData1.afisajTotal(); + userData2.afisajTotal(); + userData3.afisajTotal(); + + } +} diff --git a/manuela/src/test/java/com/imalittletester/OperatorsTest.java b/manuela/src/test/java/com/imalittletester/OperatorsTest.java new file mode 100644 index 0000000..0891e02 --- /dev/null +++ b/manuela/src/test/java/com/imalittletester/OperatorsTest.java @@ -0,0 +1,168 @@ +package com.imalittletester; + +import org.junit.jupiter.api.Test; + +import java.util.*; + +public class OperatorsTest { + + @Test + void firstTest() { + //variabila + int int1 = 0; + int int2 = 55; + + double double1 = 0.0, double2 = 125.5; //operator unar -125.5 + + boolean boo1 = true, bool2 = false; + String string1 = "", string2 = "This is the second string"; + + System.out.println("int1 = " + int1); + int1 = 100; + System.out.println("int1 = " + int1); + int2 = int1; + System.out.println("int2 = " + int2); + int1 = int1 + 5; + System.out.println("int1 = " + int1); + int1 = int2 + 10; + System.out.println("int1 = " + int1); + + double1 = 10.5 - 2.3; + System.out.println("double1 = " + double1); + double1 = double2 - 1; + System.out.println("double1 = " + double1); + double1 = double1 - double2; + System.out.println("double1 = " + double1); + System.out.println(1 + 2); + System.out.println("1 " + "2");//concatenare de string + System.out.println(1 + "2"); + System.out.println(!boo1); // asta device false + System.out.println(!bool2); //asta devine true + + boolean e = !"eee".contains("e"); //are nega si ar aduce false in loc de true + + System.out.println("String equals: " + string1.equals(string2)); + + } + + @Test + void secondTest(){ + int int1 = 1; + //la fel ca si int1 = int1+1; + int cuiAsignamValoarea = 0; + //int 1 e 1 + cuiAsignamValoarea = int1++; //nu tine cont de ++ cand asignezi o variabila altei variable, asignez valoarea veche, apoi updatez valoarea lui int1 + System.out.println("cuiAsignamValoarea = " + cuiAsignamValoarea); + //int1 e 2 deja + cuiAsignamValoarea = ++int1; //tine cont de ++ cand asignezi o variable altei variable, intai updatez valoarea lui int1, apoi o asignez + //int1 e 3 + System.out.println("cuiAsignamValoarea = " + cuiAsignamValoarea); + ++int1; + //int1 e 4 + System.out.println("int1 = " + int1); + int1++; + //int1 e 5 + System.out.println("int1 = " + int1); + + boolean int1MaiMareSauNu = int1 > cuiAsignamValoarea; + System.out.println("Int1 mai mare ca celalalt? " + int1MaiMareSauNu); + System.out.println("Int1 mai mic ca celalalt? " + (int1MaiMareSauNu)); + + } + + @Test + void thirdTest(){ + int int1 = 1; + int1 += 10; //la fel ca int1 = int1 + 10; + System.out.println("int1 = " + int1); //avem valoarea 11 + int1 -= 10; //la fel ca int1 = int1 - 10; + System.out.println("int1 = " + int1);//avem valoare 1 + int1 += -100000; // int1 = int1 + -100000; + System.out.println("int1 = " + int1); + System.out.println(1 == 2); + System.out.println(1 != 2); + } + @Test + void listTest(){ + //stocam mai multe, se poate adauga si in if, for, while + List lista1 = new ArrayList<>(); + System.out.println(lista1.isEmpty()); + lista1.add("Cluj"); + lista1.add("Oradea"); + lista1.get(1); + //rezultate [] reprezinta lista + System.out.println("lista1 = " + lista1); + + List lista2 = Arrays.asList("peach", "apple", "melon"); + System.out.println("lista2 = " + lista2); + System.out.println("Lista 2 contains apple: " + lista2.contains("apple")); + + List lista3 = List.of(1,2,3,4,5,6,7,8,9,10, 11); + System.out.println("lista3 = " + lista3); + System.out.println(lista3.get(5)); + System.out.println(lista3.size()); + + List listaDeNumere = List.of(5,13, 25, 8,14, 7, 9); + System.out.println(listaDeNumere.size()); + int numberOfNumbers = 0; + int number2 = 0; + List positionInList = new ArrayList<>(); + + for(int i = 0; i < listaDeNumere.size(); i++){ + if (listaDeNumere.get(i) % 7 == 0) { + numberOfNumbers++; + positionInList.add(i); + } + + } + System.out.println("Number of numbers...." + numberOfNumbers); + System.out.println("Elements on the positions: " +positionInList); + + //nu te intereseaza cate nr sunt in lista, inhence for + for (Integer numarInLista : listaDeNumere){ + if(numarInLista % 7 == 0){ + number2++; + } + } + System.out.println("Number 2...: " + number2); + + List listOf52 = new ArrayList<>(); + for (int i = 0; i<52; i++){ + listOf52.add(i+1); + } + System.out.println("listof52 " +listOf52); + + } + @Test + void mapTest(){ + Map simpleMap = new HashMap<>(); + simpleMap.put("firstKey", 1); + // System.out.println(simpleMap.containsKey("firstKey")); + // System.out.println("simpleMap = " + simpleMap); + + Map anotherMap = Map.of("firstKey", 1, "secondKey",2, "thirdKey", 3); + // System.out.println("anotherMap = " + anotherMap); + //System.out.println("Is key present: " + anotherMap.containsKey("secondKey")); + // System.out.println("Is value present: " + anotherMap.containsValue(5)); + System.out.println("The value of 'secondKey' is: " +anotherMap.get("secondKey")); + System.out.println("The map size is: " + anotherMap.size()); + System.out.println("Is the map empty: " + anotherMap.isEmpty()); + + for(Map.Entry entry : anotherMap.entrySet()){ + System.out.println("Key: " + entry.getKey() + " - value: " + entry.getValue()); + } + for(String key : anotherMap.keySet()){ + System.out.println(key); + } + for (int value : anotherMap.values()){ + System.out.println(value); + } + } + + @Test + void setTest (){ + Set firstSet = new HashSet<>(); + firstSet.add("fruit"); + System.out.println(firstSet); + } +} diff --git a/manuela/src/test/java/com/imalittletester/cookie/CookieTest.java b/manuela/src/test/java/com/imalittletester/cookie/CookieTest.java new file mode 100644 index 0000000..544573c --- /dev/null +++ b/manuela/src/test/java/com/imalittletester/cookie/CookieTest.java @@ -0,0 +1,16 @@ +package com.imalittletester.cookie; + +import com.imalittletester.jam.AppricotJam; +import org.junit.jupiter.api.Test; + +public class CookieTest { + public Cookie cookie2 = new Cookie("en.garmin.com"); + + @Test + void TestCookie() { + + cookie2.isProvidedParamSubDomainOfDomain("en"); + System.out.println(cookie2.isProvidedParamSubDomainOfDomain("en")); + System.out.println(cookie2.isProvidedParamSubDomainOfDomain("ro")); + } +} diff --git a/manuela/src/test/java/com/imalittletester/jam/AppricotJamTest.java b/manuela/src/test/java/com/imalittletester/jam/AppricotJamTest.java new file mode 100644 index 0000000..249bc77 --- /dev/null +++ b/manuela/src/test/java/com/imalittletester/jam/AppricotJamTest.java @@ -0,0 +1,189 @@ +package com.imalittletester.jam; + +import com.imalittletester.utils.UnitOfMeasureConverter; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +//import java.io.File; +import java.sql.SQLOutput; +import java.util.*; + +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) //set order on run tests +public class AppricotJamTest { + public int aPositiveInt = -10; + public long aPositiveLong = -100000000; + public float aFloat = 500; + public double aDouble = -221211.556765746464564564564564645645632342435465564; + public boolean aBoolean; + public String aSweetener = "sugar cane"; + public Date new_Date; + + //stocam un nou appricotJam + public AppricotJam appricotJam = new AppricotJam(); + public AppricotJam appricotJam2 = new AppricotJam("white sugar"); + public AppricotJam appricotJam3 = new AppricotJam("sugar cane", 1.5f, "kg", new ArrayList<>(), new Jar(30, 500)); + public AppricotJam appricotJamStevia = new AppricotJam("stevia", 1.5f, "kg", new ArrayList<>(), new Jar(30, 500)); + public AppricotJam appricotJamSucralose = new AppricotJam("sucralose", 1.5f, "kg", new ArrayList<>(), new Jar(30, 500)); + //initialized a new object of melonJam + public MelonJam melonJam = new MelonJam("plain sugar", 10, "kg", new ArrayList<>(), new Bottle(20, 100)); + + //homework with MAP + List fruits = List.of(); +public AppricotJam appricotJamTest = new AppricotJam ("sugar cane", 1.5f, "kg", List.of(new Fruits("appricot", 10, "kg")), new Jar(30, 500)); + //("sugar cane", 1.5f, "kg", List fruits, new Jar(30, 500)); + + @Order(1) //sa fie rulate in ordine + @Test + void thirdTest() { +// appricotJam3.makeJam(); +// System.out.println(appricotJam3.getSweetener()); +// appricotJam3.setSweetener(aSweetener); +// System.out.println(appricotJam3.getSweetener()); +// System.out.println("-------------------------"); +// melonJam.makeJam(); + System.out.println(appricotJam3.howManyFullJars(2300)); + System.out.println(appricotJam3.remainderJam(2300)); + System.out.println(appricotJam3.equals(appricotJam2)); + } + + //@Order(2) +// @Test +// void secondTest() { +// appricotJam3.makeJam(); +// System.out.println(appricotJam3.sweetener); +// +// appricotJam3.sweetener.contains("sugar"); +// +// melonJam.makeJam(); +// +// } + + @Order(3) + @Test + void firstTest() { + //sout+tab for print + System.out.println(aPositiveInt); +// System.out.println(aPositiveLong); +// System.out.println(aFloat); +// System.out.println(aDouble); +// System.out.println(aBoolean); + System.out.println(" --> " + aSweetener); + // asertEquals (api.login("username1","passwoard1") + getResponse "Success"); + } + + @Order(4) + @Test + void fourthTest(){ + //tratarea unei exceptii +// try { +// System.out.println(9 / 0); +// } +// catch (Exception e) { +// // e.printStackTrace(); +// throw new RuntimeException(( "Nu am putut imparti 9 la 0")); +// } + appricotJam3.makeJam(); + System.out.println("----------------------------------"); + appricotJamStevia.makeJam(); + System.out.println("----------------------------------"); + appricotJamSucralose.makeJam(); + } + + @Test + void fiveTest() { + //apelezi clasa UnitOfMeasureConverter + // UnitOfMeasureConverter unitOfMeasureConverter = new UnitOfMeasureConverter(); + // System.out.println(unitOfMeasureConverter.qtyInGramsUsingIf2(appricotJam3.sweetenerUom, appricotJam3.sweetenerQty)); + + System.out.println(appricotJam3.qtyInGramsUsingIf("kg", 2.5f)); + System.out.println(appricotJam3.qtyInGramsUsingIf("micrograms", 1000)); + double appricotJam3SweetenerQtyInGrams = appricotJam3.qtyInGramsUsingIf(appricotJam3.sweetenerUom, appricotJam3.sweetenerQty); + System.out.println(appricotJam3SweetenerQtyInGrams); + System.out.println((appricotJam3.qtyInGramsUsingIf("grams", 125))); + + int position = 789; + if (position > 0) { + System.out.println("Element found on position: " + position); + } else { + System.out.println("There is no element!!!"); + } + + //using simplified if + System.out.println(position > 0 ? "Element found on position: " + position : "THERE IS NO ELEMENT!"); // e la fel ca if de sus + String theMessage = position > 0 ? "Element found on position: " + position : "THERE IS NO ELEMENT!"; + System.out.println(theMessage); + //last simplified if is equivalent to: + String theMessage2 = ""; + if (position > 0) { + theMessage2 = "Element found on position: " + position; + } else theMessage2 = "THERE IS NO ELEMENT!"; + System.out.println(theMessage2); + + System.out.println("--------------------------"); + System.out.println(appricotJam3.qtyInGramsUsingIfSimple("micrograms", 2500)); + System.out.println(appricotJam3.qtyInGramsUsingIfSimple(appricotJam3.sweetenerUom, appricotJam3.sweetenerQty)); + System.out.println(appricotJam3.qtyInGramsUsingIfSimple("grams", 78)); + System.out.println(appricotJam3.qtyInGramsUsingSwitchSimple("gfgdfgfg", 12)); + System.out.println(appricotJam3.qtyInGramsUsingSwitch("grams", 23)); + System.out.println("--------------------------"); + } + + @Test + void sixTest() { +// for(int i = 0; i < 1; i++){ +// System.out.println(i); +// } + + //numere divizibile cu 3 intre 0 si 21 (exclusiv) + for (int i = 1; i < 21; i++) { + if (i % 3 == 0) { + System.out.println(i); + } + } + System.out.println("-----------------"); + //pt for in for e nevoie ca contorul (variabila) sa fie diferita de cea din primul for + for (int i = 21; i > 0; i--) { + if (i % 3 == 0) { + System.out.println(i); + } + } + System.out.println("--------------------------"); + for (int i = 3; i < 20; i += 3) { + System.out.println(i); + } + + System.out.println("-----------------------"); + + int i = 7; + while (i < 21) { + if (i % 3 == 0) { + System.out.println(i); + break; //te scoate din while + } + i++; + } + + System.out.println(("---------------------------")); + int j = 1; + do { + if (j % 3 == 0) { + System.out.println(j); + } + j++; + } + while (j < 21); + + } + + @Test + void mapOfFruit() { + //Nu am stiut cum sa adaug in initializarea unui obiect o lista ca sa pot testa "Create a new ApricotJam and calculate in the test class the cost of the fruit used for the jam" + Map fruitPricePerKg = Map.of("appricot", 5.0, "peach", 3.5, "melon", 7.0); + // List fruits = new ArrayList<>(); + //fruits.add(new Fruits("appricot", 25, "kg")); + System.out.println(appricotJamTest.fruits.get(0).fruitsQty * fruitPricePerKg.get("appricot")); + System.out.println(appricotJam3.qtyInGramsUsingIfSimple("grams", 1000)); + //System.out.println(appricotJam3.qtyInGramsUsingIfSimple("gramz", 1000)); + } +} diff --git a/manuela/src/test/java/com/imalittletester/utils/UnitOfMeasureConverterTest.java b/manuela/src/test/java/com/imalittletester/utils/UnitOfMeasureConverterTest.java new file mode 100644 index 0000000..2c7e969 --- /dev/null +++ b/manuela/src/test/java/com/imalittletester/utils/UnitOfMeasureConverterTest.java @@ -0,0 +1,22 @@ +package com.imalittletester.utils; + +import com.imalittletester.jam.AppricotJam; +import org.junit.jupiter.api.Test; + +public class UnitOfMeasureConverterTest { + + public UnitOfMeasureConverter lastDayOfMonth = new UnitOfMeasureConverter(1); + @Test + public void firstTest(){ + + System.out.println(lastDayOfMonth.lastDayOfProvidedMonth("Noiembrie", 31, 2022)); + System.out.println("-------------------------"); + System.out.println(lastDayOfMonth.lastDayOfProvidedMonth("Noiembrie", 30, 2022)); + System.out.println(lastDayOfMonth.lastDayOfProvidedMonth("Februarie", 28, 2022)); + System.out.println("-------------------------"); + System.out.println("-------------------------"); + System.out.println(lastDayOfMonth.divideBySeven(21)); + System.out.println(lastDayOfMonth.divideBySeven(14)); + } + +} diff --git a/pom.xml b/pom.xml index 63fe07f..023353c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,11 @@ com.imalittletester tutorial-java + pom 1.0-SNAPSHOT + + manuela + tutorial-java