Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA homework. Thank you Background: The notes for Lecture 6 suggest having a ca

ID: 3871227 • Letter: J

Question

JAVA homework. Thank you

Background: The notes for Lecture 6 suggest having a call to Errors.fatal() if there are extra arguments, but the code doesn't tell the user about the extra arguments it found. In contrast, the call to Errors.fatal() given for a file that can't be opened gives useful feedback.

a) Suggest simple code for the error message for extra arguments that shows the first extra argument. (0.4 points)

b) Briefly explain why part a above only asked for the first extra argument. (You might try working out the code you'd have to write if you wanted the message to show all the extra arguments, but do not turn in this code, just explain what about that code made it unappealing in this context.)

Background: The notes for Lecture 6 suggest having a call to Errors. fatal0 if there are extra arguments, but the code doesn't tell the user about the extra arguments it found. In contrast, the call to Errors. fatalo given for a file that can't be opened gives useful feedback. a) Suggest simple code for the error message for extra arguments that shows the first extra argument. (0.4 points) b) Briefly explain why part a above only asked for the first extra argument. (You might try working out the code you'd have to write if you wanted the message to show all the extra arguments, but do not turn in this code, just explain what about that code made it unappealing in this context.) (0.4 points)

Explanation / Answer

Hi,
This goes back to the basic java interpretation, main method is the intitial point of a java program and the parameters passed to it is a string array[] whih contains command line arguements. so if we write like
java filename.java -arg1 -arg2.
args[] will have two values with 1st value as arg1 and 2nd value as arg2
Now, in the code given below, we only want to allow one arguement, thats why if the args length is more than 1 we are throwing an error, to display the extra arguement we can use the args array.