Last active
December 14, 2019 10:28
-
-
Save liketaurus/5599c5063829c8b60150622dad7c8ee4 to your computer and use it in GitHub Desktop.
Пример рассчета биоритмов и их отображения на Java. Описание можно найти, к примеру, здесь: http://informatika.edusite.ru/modelir4.htm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package biorytms; | |
import java.util.Date; | |
public class biorhythm { | |
private final Date birthDate; | |
public biorhythm(Date myBirthDate) { | |
birthDate=myBirthDate; | |
} | |
private long daysBetweenDates(Date calcDate){ | |
long difference = calcDate.getTime() - birthDate.getTime(); | |
return (int)(difference / (24 * 60 * 60 * 1000)); | |
} | |
public long getDaysOfMyLife() | |
{ | |
return daysBetweenDates(new Date()); | |
} | |
public int getPhys() | |
{ | |
return getPhys(new Date()); | |
} | |
public int getPhys(Date calcDate) | |
{ | |
return (int)(100*Math.sin(2*Math.PI*daysBetweenDates(calcDate)/23)); | |
} | |
public int getEmo() | |
{ | |
return getEmo(new Date()); | |
} | |
public int getEmo(Date calcDate) | |
{ | |
return (int)(100*Math.sin(2*Math.PI*daysBetweenDates(calcDate)/28)); | |
} | |
public int getIntellect() | |
{ | |
return getIntellect(new Date()); | |
} | |
public int getIntellect(Date calcDate) | |
{ | |
return (int)(100*Math.sin(2*Math.PI*daysBetweenDates(calcDate)/33)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package biorytms; | |
import java.util.Date; | |
import java.util.GregorianCalendar; | |
public class Biorhythms { | |
private static Date createDate(int year, int month, int day) { | |
return new GregorianCalendar(year, month, day).getTime(); | |
} | |
private static String formatDate(Date date) { | |
String result = date.toLocaleString(); | |
if (date.getDate()<10) | |
result=" "+result; | |
return result.substring(0, 13); //только число, месяц и год | |
} | |
private static String shift(int value) { | |
String result = "" + value; | |
if (value == 0) { | |
result = " " + result; | |
} | |
if (value > 0) { | |
result = " " + result; | |
} | |
return result; | |
} | |
private static char trend(int value) { | |
if (value == 0) { | |
return '\u29BF'; | |
} | |
if (value > 0) { | |
return '\u2191'; | |
} else { | |
return '\u2193'; | |
} | |
} | |
private static enum circles { | |
phys, emo, intel | |
}; | |
public static String getBadDaysForMonth(circles circle, Date birthDate) { | |
biorhythm myBio = new biorhythm(birthDate); | |
Date tempDate = new Date(); | |
String result=""; | |
tempDate.setDate(tempDate.getDate() + 1); | |
int value = 0; | |
for (int i = 0; i < 30; i++) { | |
switch (circle) { | |
case phys: | |
value=myBio.getPhys(tempDate); | |
break; | |
case emo: | |
value = myBio.getEmo(tempDate); | |
break; | |
case intel: | |
value = myBio.getIntellect(tempDate); | |
break; | |
} | |
if (value == 0) { | |
result=result+formatDate(tempDate)+"\n"; | |
} | |
tempDate.setDate(tempDate.getDate() + 1); | |
} | |
if (result=="") | |
result="нет неблагоприятных дней!"; | |
return result; | |
} | |
public static void main(String[] args) { | |
Date myBirthDate = createDate(2002, 5, 3);//месяцы нумеруются с 0 | |
System.out.print("Вы родились " + formatDate(myBirthDate)); | |
biorhythm myBio = new biorhythm(myBirthDate); | |
int phys = myBio.getPhys(); | |
int emo = myBio.getEmo(); | |
int intel = myBio.getIntellect(); | |
System.out.println(" и это " + myBio.getDaysOfMyLife() + " дней!\n"); | |
System.out.println("На сегодня - " + formatDate(new Date()) + ": "); | |
System.out.println("--------------------------------------------"); | |
System.out.println("Физическая форма: \t\t" + shift(phys) + " из 100 " + trend(phys)); | |
System.out.println("Эмоциональное состояние: \t" + shift(emo) + " из 100 " + trend(emo)); | |
System.out.println("Интеллектуальные возможности: \t" + shift(intel) + " из 100 " + trend(intel)); | |
System.out.println("\nнеблагоприятные дни на месяц вперед:"); | |
System.out.println("--------------------------------------------"); | |
System.out.println("Физический ритм:\n"+getBadDaysForMonth(Biorhythms.circles.phys, myBirthDate)); | |
System.out.println("Эмоциональный ритм:\n"+getBadDaysForMonth(Biorhythms.circles.emo, myBirthDate)); | |
System.out.println("Интеллектуальный ритм:\n"+getBadDaysForMonth(Biorhythms.circles.intel, myBirthDate)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Вы родились 3 черв. 2002 и это 6403 дней! | |
На сегодня - 14 груд. 2019: | |
-------------------------------------------- | |
Физическая форма: 63 из 100 ↑ | |
Эмоциональное состояние: -90 из 100 ↓ | |
Интеллектуальные возможности: 18 из 100 ↑ | |
неблагоприятные дни на месяц вперед: | |
-------------------------------------------- | |
Физический ритм: | |
28 груд. 2019 | |
Эмоциональный ритм: | |
23 груд. 2019 | |
6 січ. 2020 | |
Интеллектуальный ритм: | |
нет неблагоприятных дней! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment