So I'm trying to get a return in the format "month number, number" ex. February 11, 2012. In the beginning I enter all in numbers. I'm stumped on where to begin. Should I create an string array ?
public class DaysBetween { public static void main(String[] args) { Scanner conIn = new Scanner(System.in); int day, month, year; boolean cont = true; String input; do // Added do while loop, so user gets asked if he wants to repeat operation. { System.out.println("Enter two 'modern' dates: month day year"); System.out.println("For example, January 12, 1954, would be: 1 12 1954"); System.out.println(); System.out.println("Modern dates occur after " + Date.MINYEAR + "."); System.out.println(); System.out.println("Enter the first date:"); if(conIn.hasNextInt()) { month = conIn.nextInt(); day = conIn.nextInt(); year = conIn.nextInt(); Date date1 = new Date(month, day, year); } else { conIn.next(); System.out.print("Illegal input was entered. "); return; } System.out.println("Enter the second date:"); month = conIn.nextInt(); day = conIn.nextInt(); year = conIn.nextInt(); Date date2 = new Date(month, day, year); if ((date1.getYear() <= Date.MINYEAR) /////Cannot find symbol || (date2.getYear() <= Date.MINYEAR)) System.out.println("You entered a 'pre-modern' date."); else { System.out.println("The number of days between"); System.out.print(date1); /////Cannot find symbol System.out.print(" and "); System.out.print(date2); System.out.print(" is "); System.out.println(Math.abs(date1.lilian() - date2.lilian()));///Cannot find symbol System.out.print("and it has been "); System.out.print(Math.abs(date2.mjd())); // Added to print days between now and Nov 17, 1858. System.out.println(" days since November 17, 1858"); System.out.print("and it has been "); System.out.print(Math.abs(date2.djd())); // Added to print days between now and Jan 1, 1900. System.out.println(" days since January 1, 1900"); System.out.print("Do you want to continue? (Y/N): "); // Added to ask user if they want to continue. } } while ("Y".equalsIgnoreCase(conIn.next().trim())); //Added so if user enters "yes" program will start over. } }
Edit: I have figured out the problem with my toString method, but have encountered another problem. I am supposed to verify that the input are integers and if not, I'm supposed to tell user "wrong input" and close. I thought I can put a if-else statment, but when I build I get an error "Cannot find symbol" refering to date1 in the 2nd "if" statement. Any clue on what I'm doing wrong?