Q:

Java Code Logic Error

When I input "today" in the code below, if(date_holder.contains("/")) executes. How do I fix this?
Sorry for the sloppiness of my code. Any help is appreciated.

import java.util.*;
import java.io.*;
import java.text.*;
/**
 * Write a description of class Driver here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class Driver
{
    //extra credit
    //do you want to enter a date or use todays date can use api to get it
    public static void main(String[] args) 
    {
       Scanner keyboard = new Scanner(System.in);
       int day = 0;
       int month = 0;
       int year = 0;
       char choice;
       String date_holder;
       StringTokenizer stok;
       int count = 0; // use this variable to create all of the sub menus
       //for example 0 is the first sub menu 1 s the next sub menu
       
       while(count == 0)
       {
           System.out.println("Enter a date or type 'today' for todays date \nor enter 'quit' to quit: ");
           date_holder = keyboard.next();
           date_holder.trim();//trim any white space
           System.out.println("!@# " + date_holder);
           if(date_holder.contains("/"))
           {
               stok = new StringTokenizer(date_holder,"/");
               month = Integer.parseInt(stok.nextToken());
               day = Integer.parseInt(stok.nextToken());
               year = Integer.parseInt(stok.nextToken());
               Date date = new Date(day, month, year);
               count = 1;
               while(count == 1)
               {
                   do
                   {
                       //zz
                       System.out.println("Current Date: " + month + "/" + day + "/" + year +
                       "\nEnter 'a' if you want to add days to the date \n" +
                       "or enter a 's' if you want to subtract the date \n" +
                       "or enter a 'd' get the days between the current date and another date \n " +
                       "or enter a 'f' if you want to format the date.\n");
                       choice = keyboard.next().charAt(0);
                   }while(choice != 'a' && choice != 's' && choice != 'd' && choice != 'f');
                   String number; //to store the user's number input
                   String answer;
                   if(choice == 'a')//too add the date
                   {
                       System.out.println("Enter a number to add:");
                       number = keyboard.next();
                       date.add(Integer.parseInt(number));
                       answer = date.toString();
                       System.out.println("answer: " + answer);
                       count = 0;
                   }
                   else if(choice == 's')//too subtract the date
                   {
                       System.out.println("Enter a number of days to subtract:");
                       number = keyboard.next();
                       date.subtract(Integer.parseInt(number));
                       answer = date.toString();
                       System.out.println("answer: " + answer);
                       count = 0;
                   }
                   else if(choice == 'd')//too get the days between
                   {
                       int inMonth, inDay, inYear = 0;
                       System.out.println("Enter a date to use with " + month + "/" + day +
                       "/" + year + ":");
                       number = keyboard.next();
                       if(number.contains("/"))
                       {
                           stok = new StringTokenizer(number,"/");
                           inMonth = Integer.parseInt(stok.nextToken());
                           inDay = Integer.parseInt(stok.nextToken());
                           inYear = Integer.parseInt(stok.nextToken());
                           Date inDate = new Date(inDay, inMonth, inYear);
                           Date outDate = new Date(day, month, year);
                           if(year < inYear)
                           {
                               System.out.println("The days between " + date.toString() + 
                               "and" + inDate.toString() + " is " + inDate.daysBetween(outDate) + " days.");
                           }
                           else
                           {
                               System.out.println("The days between " + date.toString() + 
                               "and" + inDate.toString() + " is " + outDate.daysBetween(inDate) + "days.");
                           }
                           count = 0;
                       }
                   }
                   else if(choice == 'f')//too change the format and (extra credit)
                   {
                       do
                       {
                           //zz
                           System.out.println("Current Date: " + month + "/" + day + "/" + year +
                           "\nEnter 's' if you want the format day//month//year \n" +
                           "or enter a 'l' if you want the format day of month, year \n" +
                           "or enter a 'j' to get the Julian date \n" +
                           "or enter a 'h' if you want to get the horoscope Zodiac of the date.\n" +
                           "or enter a 'c' if you want to get the Chinese Zodiac of the date.\n"+
                           "or enter a 'e' if you want to get the Easter date of the year.\n");
                           choice = keyboard.next().charAt(0);
                       }while(choice != 's' && choice != 'l' && choice != 'j' && choice != 'h' && choice != 'c' && choice != 'e');
                       //I don't need any if statments to verify the choices because
                       //it is all handled in the getDate() method
                       System.out.println(date.getDate(choice));
                       count = 0;//end the submenu loop
                   }
               }
           }
           else if(date_holder.equals("today"))
           {
               DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
               Calendar cal = Calendar.getInstance();
               System.out.println(dateFormat.format(cal));
           }
           else if(date_holder.equals("quit"))
           {
               count = -1;
           }
       }
       System.out.println("goodbye!");

   }
}

A:

Your Code works fine when I give today it prints the today's date with the format you mentioned but change your code to below.
else if(date_holder.equals("today"))
           {
               DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
               Calendar cal = Calendar.getInstance();
               System.out.println(dateFormat.format(cal.getTime()));
           }

You cannot format the calendar object you have to use getTime method to get the Date object.
Your code looks quite clumsy please study more about the Date api here 

