Harsha Smith wrote:Assuming all the validation is done and user enter the course in the format given in the example
I believe the Scanner class is now the usual way to read user input.kyky ky wrote:but how if "ABC 12345 Spanish Studies" type by the users (use printer)
Joanne
Joanne Neal wrote:
I believe the Scanner class is now the usual way to read user input.kyky ky wrote:but how if "ABC 12345 Spanish Studies" type by the users (use printer)
jack parker wrote:if i use scanner, is that the correct answer differ from the above one? thanks alot
Joanne
John Jai wrote:How far you are comfortable with the substring() and indexOf() methods?
A small example:
Can you try with the two methods to achieve your goal?
Harsha Smith wrote:Hope this helps!
jack parker wrote:but if i use the scanner method to grab user input instead of store the course there are errors
Harsha Smith wrote:put this inside main method and see if it works as desired.
John Jai wrote:
jack parker wrote:but if i use the scanner method to grab user input instead of store the course there are errors
Please TellTheDetails
The more you get working code, you tend to put aside the code you have tried and fail to address the Exceptions / Errors you experience.
You could have showed the Scanner code you tried and the errors you received. Please try to resolve the errors one by one and learn from it .
John Jai wrote:Check the API for substring() method in String class - substring(int,int)
See when a IndexOutOfBoundsException is thrown by the method.
My guess is that you have entered a String that does not contain a blank character (' ') and hence the endIndex is -1.
Print the end index and check like below.
Well you have other errors (or invalid logic) following this one... First correct this error.
jack parker wrote:A college course can be described using three components: <Division title><Code><Course
description>, where represents an empty space. Write a Java program that
obtains a course string, and then splits and prints the THREE components of the course.
for example ~
ABC 12345 Spanish Studies
the users can type what classes they want.
how can i seperate them to :
Enter course string: ABC 12345 Spanish Studies
Division: ABC
Course Code: 12345
Course Description: Spanish Studies
thank you so much.