diff --git a/.idea/misc.xml b/.idea/misc.xml index 639900d..e9710cf 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index ef8a6f4..c5c52f7 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,6 +3,7 @@ + diff --git a/src/enums/enums.iml b/src/enums/enums.iml new file mode 100644 index 0000000..9092d60 --- /dev/null +++ b/src/enums/enums.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/enums/src/Main.java b/src/enums/src/Main.java new file mode 100644 index 0000000..01e0b25 --- /dev/null +++ b/src/enums/src/Main.java @@ -0,0 +1,4 @@ +public class Main { + public static void main(String[] args) { + } +} \ No newline at end of file diff --git a/src/enums/src/Month.java b/src/enums/src/Month.java new file mode 100644 index 0000000..d2a8778 --- /dev/null +++ b/src/enums/src/Month.java @@ -0,0 +1,51 @@ +public enum Month { + + JANUARY(31), + FEBRUARY(28), + MARCH(31), + APRIL(30), + MAY(31), + JUNE(30), + JULY(31), + AUGUST(31), + SEPTEMBER(30), + OCTOBER(31), + NOVEMBER(30), + DECEMBER(31); + + private int daysInMonth; + + private Month(int daysInMonth) { + this.daysInMonth = daysInMonth; + } + + public int getDaysInMonth() { + return daysInMonth; + } + + + public int getMonthNum() { + return ordinal() + 1; + } + + public static int howManyDaysBefore(Month month, int dayInMonth) { + int daysBefore = 0; + Month[] arr = Month.values(); + for (int i = 0; i < month.ordinal(); i++) { + daysBefore += arr[i].getDaysInMonth(); + } + return daysBefore+dayInMonth-1; + } + + public static Month whichMonth(int currentDay) { + Month[] arr = Month.values(); + int totalDays = 0; + int count = 0; + while(totalDays < currentDay) { + totalDays += arr[count].getDaysInMonth(); + count++; + } + return arr[count-1]; + } + +} diff --git a/src/enums/src/Supermarket.java b/src/enums/src/Supermarket.java new file mode 100644 index 0000000..97bb019 --- /dev/null +++ b/src/enums/src/Supermarket.java @@ -0,0 +1,24 @@ +public enum Supermarket { + + CHEESE("cheese", 5), + WATER_BOTTLE("water bottle" , 3), + OIL_BOTTLE( "oil bottle", 10), + SUGAR("sugar",7); + + private int productsPrice; + private String name; + + private Supermarket (String name, int productsPrice) { + this.productsPrice = this.productsPrice; + this.name = name; + } + + public static int sumPrice(Supermarket[] arr, int [] sizes) { + int priceOfAll = 0; + for (int i = 0; i < arr.length ; i++) { + priceOfAll += arr[i].productsPrice*sizes[i]; + } + return priceOfAll; + } + +}