Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Tolls

Thread: Need help quick, 15 errors

  1. #1
    ndsmith20 is offline Member
    Join Date
    Oct 2012
    Posts
    55
    Rep Power
    0

    Default Need help quick, parse and try catch block errors

    I need help with this Java program please. It supposed to convert military time format to 12 hr time format without using built in java time conversions and catch all errors, this is what i have so far:
    Java Code:
    /**
     * 218-102 HW 7
     * TimeConvert.java
     *
     * @author     
     *
     */
    
    public class TimeConvert
    {
    	//attributes
    	public String time;
    	public String timeConvert;
    	public int hour = 0;
    	public int min = 0;
    	public String msg = "Minutes must be less than 60 and greater than 0";
    	public String msg1 = "Hours must be less than 24 and greater than 0";
    	public String msg2 = "Format must be hh:mm format";
    	public String amPM = "AM";
    	
    	public String doConversion(String _time)
    	{
    		
    		try
    		{
    			hour = Integer.parseInt(_time.substring(0,1));
    			min = Integer.parseInt(_time.substring(3,4));
    			if(min =< 0 || min >= 60)
    			{
    				throw new TimeFormatException(msg);
    			}
    			else if (hour < 0 || hour > 24)
    			{
    				throw new TimeFormatException(msg1);
    			}
    			else if (_time.length() < 5)
    			{
    				throw new TimeFormatException(msg2);
    			}
    			else
    			{
    					  if (hour == 12)
    	  {
    	  	amPM = "PM";
    	  }
    	  else if (hour == 13)
    	  	{
    			hour = 1;
    			amPM = "PM";
    		}
    		else if (hour == 14)
    		{
    			hour = 2;
    			amPM = "PM";
    		}
    		else if (hour == 15)
    		{
    			hour = 3;
    			amPM = "PM";
    		}
    		else if (hour == 16)
    		{
    			hour = 4;
    			amPM = "PM";
    		}
    		else if (hour == 17)
    		{
    			hour = 5;
    			amPM = "PM";
    		}
    		else if (hour == 18)
    		{
    			hour = 6;
    			amPM = "PM";
    		}
    		else if (hour == 19)
    		{
    			hour = 7;
    			amPM = "PM";
    		}
    		else if (hour == 20)
    		{
    			hour = 8;
    			amPM = "PM";
    		}
    		else if (hour == 21)
    		{
    			hour = 9;
    			amPM = "PM";
    		}
    		else if (hour == 22)
    		{
    			hour = 10;
    			amPM = "PM";
    		}
    		else if (hour == 23)
    		{
    		hour = 11;
    		amPM = "PM";
    		}
    		else if (hour == 24)
    		{
    		hour = 12;
    		}
    			}
    		}
    		catch(TimeFormatException e)
    		{
    			 
    		}
    		catch(NumberFormatException e)
    	  {
    	  	System.out.println("Use integer values for hour and minute specifications");
    		System.exit(0);
    	  }
    
    		timeConvert = "That is the same as "+hour+":"+min+" "+amPM;
    		return timeConvert;
    	}
    }
    Java Code:
    public class TimeFormatException extends Exception 
    {
    	//attributes
       
       public TimeFormatException(String message) 
       {
          super(message);
       }
    	
    	public TimeFormatException(String message, String msg1)
    	{
    		super(message + "\n" + msg1);
    	}
    }
    Errors:
    TimeConvert.java:28: error: illegal start of type
    if(min =< 0 || min >= 60)
    ^
    TimeConvert.java:28: error: illegal start of expression
    if(min =< 0 || min >= 60)
    ^
    TimeConvert.java:28: error: ')' expected
    if(min =< 0 || min >= 60)
    ^
    TimeConvert.java:28: error: illegal start of expression
    if(min =< 0 || min >= 60)
    ^
    TimeConvert.java:28: error: ';' expected
    if(min =< 0 || min >= 60)
    ^
    TimeConvert.java:28: error: illegal start of expression
    if(min =< 0 || min >= 60)
    ^
    TimeConvert.java:28: error: ';' expected
    if(min =< 0 || min >= 60)
    ^
    TimeConvert.java:24: error: 'try' without 'catch', 'finally' or resource declarations
    try
    ^
    TimeConvert.java:32: error: 'else' without 'if'
    else if (hour < 0 || hour > 24)
    ^
    TimeConvert.java:107: error: illegal start of type
    catch(TimeFormatException e)
    ^
    TimeConvert.java:111: error: illegal start of type
    catch(NumberFormatException e)
    ^
    TimeConvert.java:117: error: <identifier> expected
    timeConvert = "That is the same as "+hour+":"+min+" "+amPM;
    ^
    TimeConvert.java:118: error: illegal start of type
    return timeConvert;
    ^
    TimeConvert.java:118: error: ';' expected
    return timeConvert;
    ^
    TimeConvert.java:120: error: class, interface, or enum expected
    }
    ^
    15 errors

    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP:
    Last edited by ndsmith20; 02-07-2013 at 04:54 AM.

  2. #2
    ndsmith20 is offline Member
    Join Date
    Oct 2012
    Posts
    55
    Rep Power
    0

    Default Re: Need help quick, 15 errors

    I have made changes am I am down to 10 errors:
    Java Code:
    public class TimeConvert
    {
    	//attributes
    	public String time;
    	public String timeConvert;
    	public int hour = 0;
    	public int min = 0;
    	public String hour1;
    	public String min1;
    	public String msg = "Minutes must be less than 60 and greater than 0";
    	public String msg1 = "Hours must be less than 24 and greater than 0";
    	public String msg2 = "Format must be hh:mm format";
    	public String amPM = "AM";
    	
    	public String doConversion(String _time)
    	{
    		
    		try
    		{	//create hour and min from _time String
    			min1 = _time.substring(0,1);
    			hour1 = _time.substring(3,4);
    			hour = Integer.parseInt(hour);
    			min = Integer.parseInt(min);
    			if((min =< 0 )|| (min >= 60))
    			{
    				throw new TimeFormatException(msg);
    			}
    			else if (hour < 0 || hour > 24)
    			{
    				throw new TimeFormatException(msg1);
    			}
    			else if (_time.length() < 5)
    			{
    				throw new TimeFormatException(msg2);
    			}
    			//converts 24 hour format to 12 hour format
    			else
    			{
    				if (hour == 12)
    	  				{
    	  					amPM = "PM";
    	 				}
    	  			else if (hour == 13)
    	  				{
    						hour = 1;
    						amPM = "PM";
    					}
    				else if (hour == 14)
    					{
    						hour = 2;
    						amPM = "PM";
    					}
    				else if (hour == 15)
    					{
    						hour = 3;
    						amPM = "PM";
    					}
    				else if (hour == 16)
    					{
    						hour = 4;
    						amPM = "PM";
    					}
    				else if (hour == 17)
    					{
    						hour = 5;
    						amPM = "PM";
    					}
    				else if (hour == 18)
    					{
    						hour = 6;
    						amPM = "PM";
    					}
    				else if (hour == 19)
    					{
    						hour = 7;
    						amPM = "PM";
    					}
    				else if (hour == 20)
    					{
    						hour = 8;
    						amPM = "PM";
    					}
    				else if (hour == 21)
    					{
    						hour = 9;
    						amPM = "PM";
    					}
    				else if (hour == 22)
    					{
    						hour = 10;
    						amPM = "PM";
    					}
    				else if (hour == 23)
    					{
    						hour = 11;
    						amPM = "PM";
    					}
    				else if (hour == 24)
    					{
    						hour = 12;
    					}
    				}
    			}
    		}
    		catch(TimeFormatException e)
    			{
    			 
    			}
    		catch(NumberFormatException e)
    	  		{
    	  			System.out.println("Use integer values for hour and minute specifications");
    				System.exit(0);
    	  		}
    
    		timeConvert = "That is the same as "+hour+":"+min+" "+amPM;
    		return timeConvert;
    	}
    }
    errors:
    TimeConvert.java:32: error: illegal start of type
    if((min =< 0 )|| (min >= 60))
    ^
    TimeConvert.java:32: error: illegal start of expression
    if((min =< 0 )|| (min >= 60))
    ^
    TimeConvert.java:32: error: ')' expected
    if((min =< 0 )|| (min >= 60))
    ^
    TimeConvert.java:26: error: 'try' without 'catch', 'finally' or resource declarations
    try
    ^
    TimeConvert.java:112: error: illegal start of type
    catch(TimeFormatException e)
    ^
    TimeConvert.java:116: error: illegal start of type
    catch(NumberFormatException e)
    ^
    TimeConvert.java:122: error: <identifier> expected
    timeConvert = "That is the same as "+hour+":"+min+" "+amPM;
    ^
    TimeConvert.java:123: error: illegal start of type
    return timeConvert;
    ^
    TimeConvert.java:123: error: ';' expected
    return timeConvert;
    ^
    TimeConvert.java:125: error: class, interface, or enum expected
    }
    ^
    10 errors

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: Need help quick, 15 errors

    Please go through the Forum Rules, particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    ndsmith20 is offline Member
    Join Date
    Oct 2012
    Posts
    55
    Rep Power
    0

    Default Re: Need help quick, 15 errors

    sorry, i tried to change title

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: Need help quick, 15 errors

    Click 'Edit' then 'Go Advanced'

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,861
    Rep Power
    19

    Default Re: Need help quick, 15 errors

    Java operators.
    I don't think you'll find '=<'.

    For the remainder, check your brackets.
    That "'try' without 'catch'" one implies you've mucked them up somewhere.
    lenois likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Should be a quick fix :)
    By Alienz in forum New To Java
    Replies: 5
    Last Post: 04-08-2011, 01:23 AM
  2. Replies: 4
    Last Post: 01-04-2011, 12:36 AM
  3. Quick help
    By locazor in forum New To Java
    Replies: 15
    Last Post: 10-17-2010, 07:07 PM
  4. Replies: 3
    Last Post: 03-08-2009, 01:51 AM
  5. Need help quick!
    By Manikyr in forum New To Java
    Replies: 11
    Last Post: 01-28-2009, 04:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •