I am a programming enthusiast currently studying for App Development. We have started programming with Java for one months..Can someone help me fix this code? Requirements • The user enters the date in the YYYYMMDD format • Any impossible date is rejected: – dates before Oct. 15th 1582 or after Dec, 31st, 2199 – impossible month (<1 or >12) – impossible days (e.g. any day>31, a day>30 for some months, a day>28 in February of a non-leap year, etc) Code: https://code.sololearn.com/cib6hTe86w64/#java
10/21/2019 6:39:40 PMMicelito
9 AnswersNew Answer
One question from my side: Are you supposed to program everything from scratch or are Java utilities like DateTimeFormatter or the DateTime api allowed?
1st advice: Take the date input as a string. With formatter and api: Date date=new SimpleDateFormat("yyyyMMdd").parse(input); Without formatter and api you can use String's substring method to parse an input string, for the year it would be: input.substring(0,4); Then for month: input.substring(4,6); And so on.
You should use regular expressions
import java.util.Scanner; ... Scanner sc = new Scanner(System.in); int date = sc.nextInt(); - you have two isLeap() method at line 24 and 56 - package is not supported by Sololearn //package WeekdaysFunctions;
update: https://code.sololearn.com/cib6hTe86w64/#java I need to complete the tests in IntelliJ-Project. Date (yyyymmdd) 19991232 - correct 21010101 - correct 20030229 - correct 19800201 - correct 19190303 - correct 15821015 - correct 15821016 - test failed 21001231 - test failed 19291025 (black Friday) - test failed
how are you
Your program works. What's your problem? correction: it works with my Birthday 😁
15821016 returns Saturday, but it is Tuesday https://www.timeanddate.com/date/weekday.html?year=1582&month=10&day=16
have a nice day