WeekdaysFunctions | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

WeekdaysFunctions

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

21st Oct 2019, 6:39 PM
Micelito
Micelito - avatar
9 Answers
+ 5
One question from my side: Are you supposed to program everything from scratch or are Java utilities like DateTimeFormatter or the DateTime api allowed?
21st Oct 2019, 7:19 PM
Tashi N
Tashi N - avatar
+ 5
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.
21st Oct 2019, 7:42 PM
Tashi N
Tashi N - avatar
+ 2
You should use regular expressions
21st Oct 2019, 11:07 PM
Marina Vasilyova
Marina Vasilyova - avatar
+ 1
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;
21st Oct 2019, 7:39 PM
zemiak
+ 1
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
22nd Oct 2019, 9:52 AM
Micelito
Micelito - avatar
0
how are you
23rd Oct 2019, 12:59 PM
Daniel
0
Your program works. What's your problem? correction: it works with my Birthday 😁
23rd Oct 2019, 1:54 PM
Kiuziu 💘 Berlin
Kiuziu 💘 Berlin - avatar
23rd Oct 2019, 3:42 PM
zemiak
0
have a nice day
23rd Oct 2019, 5:31 PM
Daniel