Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Exception Thrown

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Exception Thrown

    I am not sure whats wrong here. This is a simple event handling program we are trying to make for a group assignment, but it throws an exception if the name entered is more than one word.

    /* Team C Prototype EventTrack
     * Wednesday, October 19, 2011
     * Get Event Name
     * Get Start Time
     *
     
    */
     
    import java.util.Scanner;
    import java.util.Calendar;
    import java.util.Date;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
     
    public class EventTrack2
    {
        public static void main (String[] args)
        {
    		Boolean bErrorCode = true;
    		//**if error in EventTrack will return and give user another chance
    		while (bErrorCode == true) {
    		       bErrorCode = EventInput();
    		}
        }
     
        public static Boolean EventInput()
        {
    		Boolean bEventInput = false;
    		int iComplete;
    		int iTimeInput;
    		int iYear;
    		int iMonth;
    		int iDay;
    		int iHour;
    		int iMinute;
    		String sEventName;
    		String sDateInput="";
    		String sStartDate="";
    		String sStartTime="";
    		String sEndDate="";
    		String sEndTime="";
    		int iLength=0;
    		DateFormat dateFormat;
            Date dInput;
            long lMillisecondsStart;
            long lMillisecondsEnd;
            long lDiff;
            long lDiffMinutes;
            long lDiffHours;
     
    		Calendar startDate = Calendar.getInstance(); //**Calendar  instance start
    		Calendar endDate = Calendar.getInstance(); //**Calendar  instance end
    		Scanner sc = new Scanner(System.in);
    		System.out.println("*****************");
    		System.out.print("Enter Event Name: ");
    		sEventName = sc.next(); //**Put Event Name in string
    		iLength = sEventName.length();
    		if ( iLength < 1){
    			System.out.println("*****************");
    			System.out.print("Event Name can not be null, Enter Event Name: ");
    			sEventName = sc.nextLine();
            }
            try {
    		  System.out.println("*****************");
    		  System.out.print("Enter Start Date MM/DD/YYYY: ");
    		  sDateInput = sc.next(); //**Put Start Date in string
    		  dateFormat = new SimpleDateFormat("MM/dd/yyyy");
    		  dInput = (Date)dateFormat.parse(sDateInput);
              startDate.setTime(dInput);
            }
    		catch (Exception ex) {
    		    System.out.println("Exception in getting Start Date occurred");
    		    bEventInput = true;
            }
            try {
    			System.out.println("*****************");
    			System.out.print("Enter Start Hour 1 to 24:");
    			iTimeInput = sc.nextInt(); //**Put Start Hour
    			if (iTimeInput >= 0 || iTimeInput <= 24) {
    				  startDate.set(Calendar.HOUR_OF_DAY, iTimeInput);
    			}
    			else {
    				  System.out.println("*****************");
    				  System.out.print("Enter Start Hour 1 to 24:");
    				  iTimeInput = sc.nextInt(); //**Put Start Hour
    				  if (iTimeInput >= 0 || iTimeInput <= 24) {
    					  startDate.set(Calendar.HOUR_OF_DAY, iTimeInput);
    				  }
    				  else {
    					  startDate.set(Calendar.HOUR_OF_DAY, 12);
    				  }
    			}
    			System.out.println("*****************");
    			System.out.print("Enter Start Minute 0 to 60:");
    			iTimeInput = sc.nextInt(); //**Put Start Minute
    			if (iTimeInput >= 0 || iTimeInput <= 60) {
    				   startDate.set(Calendar.MINUTE, iTimeInput);
    			}
    			else {
    				   System.out.println("*****************");
    				   System.out.print("Enter Start Minute 0 to 60:");
    				   iTimeInput = sc.nextInt(); //**Put Start Hour
    				   if (iTimeInput >= 0 || iTimeInput <= 24) {
    					   startDate.set(Calendar.MINUTE, iTimeInput);
    				   }
    				   else {
    					   startDate.set(Calendar.MINUTE, 0);
    				   }
                }
    		}
    		catch (Exception ex) {
    		    System.out.println("Exception in getting Start Time occurred");
    		    bEventInput = true;
            }
     
            try {
    			  System.out.println("*****************");
    			  System.out.print("Enter End Date MM/DD/YYYY: ");
    			  sDateInput = sc.next(); //**Put End Date in string
    			  dateFormat = new SimpleDateFormat("MM/dd/yyyy");
    			  dInput = (Date)dateFormat.parse(sDateInput);
    			  endDate.setTime(dInput);
    			}
    			catch (Exception ex) {
    				System.out.println("Exception in getting Start Date occurred");
    				bEventInput = true;
    			}
    			try {
    				System.out.println("*****************");
    				System.out.print("Enter End Hour 1 to 24:");
    				iTimeInput = sc.nextInt(); //**Put End Hour
    				if (iTimeInput >= 0 || iTimeInput <= 24) {
    					  endDate.set(Calendar.HOUR_OF_DAY, iTimeInput);
    				}
    				else {
    					  System.out.println("*****************");
    					  System.out.print("Enter End Hour 1 to 24:");
    					  iTimeInput = sc.nextInt(); //**Put End Hour
    					  if (iTimeInput >= 0 || iTimeInput <= 24) {
    						  endDate.set(Calendar.HOUR_OF_DAY, iTimeInput);
    					  }
    					  else {
    						  endDate.set(Calendar.HOUR_OF_DAY, 12);
    					  }
    				}
    				System.out.println("*****************");
    				System.out.print("Enter End Minute 0 to 60:");
    				iTimeInput = sc.nextInt(); //**Put End Minute
    				if (iTimeInput >= 0 || iTimeInput <= 60) {
    					   endDate.set(Calendar.MINUTE, iTimeInput);
    				}
    				else {
    					   System.out.println("*****************");
    					   System.out.print("Enter End Minute 0 to 60:");
    					   iTimeInput = sc.nextInt(); //**Put End Minute
    					   if (iTimeInput >= 0 || iTimeInput <= 24) {
    						   endDate.set(Calendar.MINUTE, iTimeInput);
    					   }
    					   else {
    						   endDate.set(Calendar.MINUTE, 0);
    					   }
    				}
    			}
    			catch (Exception ex) {
    				System.out.println("Exception in getting End Time occurred");
    				bEventInput = true;
            }
     
    		lMillisecondsStart = startDate.getTimeInMillis();
    		lMillisecondsEnd = endDate.getTimeInMillis();
    		lDiff = lMillisecondsEnd - lMillisecondsStart;
    		lDiffMinutes = lDiff / (60 * 1000);
    		lDiffHours = lDiff / (60 * 60 * 1000);
     
            dateFormat = new SimpleDateFormat("MM/dd/yyyy");
    		sStartDate = dateFormat.format(startDate.getTime());
    		sEndDate = dateFormat.format(endDate.getTime());
    		System.out.println("*****************");
    		System.out.println("Don't Forget about " + sEventName + "!");
    		System.out.println("*****************");
    		System.out.println("Begins on:" + sStartDate);
    		System.out.println("Ends on:" + sEndDate);
    		System.out.println("Runs for:" + lDiffMinutes + " minutes");
    		System.out.println("*****************");
    		System.out.println(" ");
    		sStartTime = startDate.get(Calendar.HOUR) + ":" + startDate.get(Calendar.MINUTE) + ":" + startDate.get(Calendar.SECOND);
    		System.out.println("Be there at: " + sStartTime);
    		sEndTime = endDate.get(Calendar.HOUR) + ":" + endDate.get(Calendar.MINUTE) + ":" + endDate.get(Calendar.SECOND);
    		System.out.println("Leave at: " + sEndTime);
    		System.out.println("This will be " + lDiffHours + " hours of fun! Hope to see your there!");
    		System.out.println(" ");
    		return bEventInput = false;
    	}
     
    }
    Last edited by helloworld922; October 30th, 2011 at 12:37 AM.


  2. #2
    Member
    Join Date
    Mar 2011
    Posts
    84
    My Mood
    Daring
    Thanks
    17
    Thanked 1 Time in 1 Post

    Default Re: Exception Thrown

    please read this
    Last edited by arvindbis; October 29th, 2011 at 11:17 PM.

Similar Threads

  1. Replies: 5
    Last Post: September 5th, 2011, 10:31 AM
  2. [SOLVED] Should I use an exception here?
    By whity in forum Java Theory & Questions
    Replies: 3
    Last Post: May 4th, 2011, 06:52 AM
  3. Replies: 6
    Last Post: March 25th, 2011, 03:42 PM
  4. caught or declare might be thrown error
    By IDK12 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 28th, 2011, 01:55 PM
  5. DAO exception
    By nrao in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 13th, 2010, 12:22 PM