Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/enums/enums.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-24" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
4 changes: 4 additions & 0 deletions src/enums/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public class Main {
public static void main(String[] args) {
}
}
51 changes: 51 additions & 0 deletions src/enums/src/Month.java
Original file line number Diff line number Diff line change
@@ -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];
}

}
24 changes: 24 additions & 0 deletions src/enums/src/Supermarket.java
Original file line number Diff line number Diff line change
@@ -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;
}

}