Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Part 2: Fruit and Numbers This second part of the project checks that you know how to use command line arguments and write basic Java
Part 2: Fruit and Numbers This second part of the project checks that you know how to use command line arguments and write basic Java code (including exception handling), and it gives you more practice writing JavaDocs and using checkstyle. You'll also be able to see and use JUnit tests (such as the ones we use when grading). Specification: Write a program (AppleOrange, that lives in AppleOrange. java). This program should print the numbers from 1 to X (inclusive), space separated, but for multiples of 3 print "apple" instead of the number, for multiples of 7 print "orange" instead of the number, and for the multiples of both 3 and 7 print "appleorange" (no space) instead of the number. X is a command line argument to the program. Don't forget to document as you go. Example program run (coloring added for readability): > java AppleOrange 10 12 apple 45 apple orange 8 apple 10 > java AppleOrange 25 12 apple 45 apple orange 8 apple 1011 apple 13 orange apple 1617 apple 1920 appleorange 2223 apple 25 > java AppleOrange 50 12 apple 45 apple orange 8 apple 1011 apple 13 orange apple 1617 apple 1920 appleorange 2223 apple 2526 apple orange 29 apple 3132 apple 34 orange apple 37 38 apple 4041 appleorange 4344 apple 4647 apple orange 50 Checking for Invalid Input Your program should print the following (exactly) if the command line argument is missing, if the argument is not a positive number, or if too many arguments are given. This message should be sent to system. err not system. out. After printing the error message, your program should terminate immediately. NOTE: do NOT use system. exit () to terminate since it will interfere with JUnit testing. See below (page 6) for more details. Example commands which generate this error: > java AppleOrange > java AppleOrange 11 > java AppleOrange 0 > java AppleOrange apple > java AppleOrange 10 Error message: One positive number required as a command line argument
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started