reset password
Author Message
mferras2
Posts: 7
Posted 23:52 Oct 02, 2018 |

Two part question about the Fill in the blank class.

I’m slightly confused on the bullet points where you are asking us to take the question and parse our the answer in the constructor. Then ask us to write a method that should do the exact same. What would be the exact difference between those two statements.

Also, the constructor should only take in the question in the given format of having two underscores. What I have so far is using a string method to see if the string passed only has one underscore. How would it be possible to check for more than 1 character in a string?

rgallegos
Posts: 29
Posted 00:04 Oct 03, 2018 |

There's many different ways to do so. What does the string method return? If it's an index you can check the string class for a method that allows you to search for something starting at some index.

There's no need to have a method in the constructor and a method outside of it. With object oriented programming if you have the same code twice you might want to consider making it into a method and calling the method where needed.

chern227
Posts: 7
Posted 00:05 Oct 03, 2018 |

to check the string @  1st "_" use the indexOf() method and to check last "_" use the lastIndexOf() method. yes

rgallegos
Posts: 29
Posted 00:26 Oct 03, 2018 |
chern227 wrote:

to check the string @  1st "_" use the indexOf() method and to check last "_" use the lastIndexOf() method. yes

That might cause some errors if it only finds one of them or the sentence does not have any underscores at all but checking for those errors is simple enough.

chern227
Posts: 7
Posted 00:29 Oct 03, 2018 |
rgallegos wrote:
chern227 wrote:

to check the string @  1st "_" use the indexOf() method and to check last "_" use the lastIndexOf() method. yes

That might cause some errors if it only finds one of them or the sentence does not have any underscores at all but checking for those errors is simple enough.

but then it would work since you could do "if (!nameholder.equals("_")) {.....}" to print out the error which is needed

rgallegos
Posts: 29
Posted 00:34 Oct 03, 2018 |
chern227 wrote:
rgallegos wrote:
chern227 wrote:

to check the string @  1st "_" use the indexOf() method and to check last "_" use the lastIndexOf() method. yes

That might cause some errors if it only finds one of them or the sentence does not have any underscores at all but checking for those errors is simple enough.

but then it would work since you could do "if (!nameholder.equals("_")) {.....}" to print out the error which is needed

Interesting. That's a cool approach to it.

mferras2
Posts: 7
Posted 02:25 Oct 03, 2018 |

Thanks guys for the help