r/learnjava • u/[deleted] • Nov 27 '15
Today I finished writing my first program. I'd love some feedback and critique!
https://github.com/jayremyhyoos/medtrack3
Nov 27 '15
About a week ago, two things came to me:
I need a practical project to practice the java that I've been teaching myself.
I'm awful at remembering to take my medicine.
Therefore, I wrote a simple medicine tracker! I intend to put it in a batch file that will open it when my computer is turned on. As it opens, it prompts you to either confirm that you've taken your medicine or to view the log.
Any feedback or critique is appreciated. I'm super proud of my work, even if it is simple.
0
Nov 28 '15
[deleted]
2
Nov 28 '15
Thank you! This is the first program that I've ever thought of, planned out, and wrote by myself! I've dabbled in python and c++, but never did anything "major" in programming until I started working with Java. I'm teaching myself, using online tutorials and a book that I bought!
0
Nov 28 '15
[deleted]
2
Nov 28 '15
Thank you so much! I'll write these things down and work on them in order. I'll have to teach myself how to do the second one, but it's something that makes a lot of sense. Thanks again for the critique and ideas!
4
u/Mitsuwa Nov 28 '15 edited Nov 28 '15
Cool program, Here are some thoughts
Print out the stacktrace from exception e if you are going to catch it.
You should move this stuff
Date today = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
String date = dateFormat.format(today);
Into the if userChoice == 1 - as you are declaring variables that are not used unless they choose 1
You should indent things in try {}
You might want to look into the finally statement to utilize with your try catches finally and put the BufferedReader or PrintWriter .close() in there. So that if it throws an exception anywhere you are always going to close that
Your error messages could be improved. From doing what I said in 1. as well as
File Not Foundisn't necessarily going to be your actual reason for erroring all the time. What if it fails anywhere other than createdfrthen that error isnt really true.You should have a default case. What if they enter something that isnt 1 or 2? You should print out something that says, you must enter a 1 or a 2 or something like that. Or print your help text again.
Just my 2 cents, cool program, keep at it!
2
Nov 28 '15
Wow, thanks a bunch for this. I hadn't considered a lot of that. Number 2 makes a lot of sense. I don't know why I didn't catch number 3, but your totally right. And I'll look into the rest. I appreciate your thoughts a lot!
1
u/Jorrd93 Nov 28 '15 edited Nov 28 '15
Had a go at making some changes myself. Love this as a first project.
I have made a pull request on Git (new to Git so I don't know if I should have branched instead).
2
Nov 28 '15
I approved it! Thanks so much! I'll be working on it periodically throughout the day, so if you continue to work with it, just message me whenever you have a pull request or whatever. (I'm new to git too, I'm still trying to get the vocab down. :P)
3
u/rodomvp Nov 28 '15
two things:
You should always include a readme in your public git projects, learn to use markdown it's great
This could be really cool if you used a cron job to run the program whenever you're supposed to take your medicine - that way you would never forget (as long as you're on your computer!)
1
Nov 30 '15
Nice. You should implement error handling. Ie, if you don't enter an integer when asked for input, it currently returns an error:
Exception in thread "main" java.util.InputMismatchException
5
u/Sokonit Nov 28 '15
IDK if you know this or thought it would look better for the purpose of printing, but you can use an +"\n"+ to make a new line, \t for tab and so on, just in case.
Also, you could look into using "cases", just for the purpose of knowing how to use them.