Results 1 to 6 of 6
Thread: Need help quick, 15 errors
- 02-07-2013, 03:47 AM #1
Member
- Join Date
- Oct 2012
- Posts
- 46
- Rep Power
- 0
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; } }Errors:Java Code:public class TimeFormatException extends Exception { //attributes public TimeFormatException(String message) { super(message); } public TimeFormatException(String message, String msg1) { super(message + "\n" + msg1); } }
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.
- 02-07-2013, 04:07 AM #2
Member
- Join Date
- Oct 2012
- Posts
- 46
- Rep Power
- 0
Re: Need help quick, 15 errors
I have made changes am I am down to 10 errors:
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; } }
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
- 02-07-2013, 04:44 AM #3
Re: Need help quick, 15 errors
Please go through the Forum Rules, particularly the third paragraph.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-07-2013, 04:55 AM #4
Member
- Join Date
- Oct 2012
- Posts
- 46
- Rep Power
- 0
Re: Need help quick, 15 errors
sorry, i tried to change title
- 02-07-2013, 05:00 AM #5
Re: Need help quick, 15 errors
Click 'Edit' then 'Go Advanced'
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-07-2013, 09:42 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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.Please do not ask for code as refusal often offends.
Similar Threads
-
Should be a quick fix :)
By Alienz in forum New To JavaReplies: 5Last Post: 04-08-2011, 01:23 AM -
First Java Program-Compile Errors (errors are posted)-simple GUI
By cc11rocks in forum AWT / SwingReplies: 4Last Post: 01-04-2011, 12:36 AM -
Quick help
By locazor in forum New To JavaReplies: 15Last Post: 10-17-2010, 07:07 PM -
What is the difference between Semantic Errors and Logical Errors?
By tlau3128 in forum New To JavaReplies: 3Last Post: 03-08-2009, 01:51 AM -
Need help quick!
By Manikyr in forum New To JavaReplies: 11Last Post: 01-28-2009, 04:08 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks