Lisa Austin

Ranch Hand
+ Follow
since Jun 04, 2015
Cows and Likes
Cows
Total received
5
In last 30 days
1
Total given
0
Likes
Total received
6
Received in last 30 days
0
Total given
68
Given in last 30 days
1
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Lisa Austin

Thank you Carey Brown and Dave Tolls.
I thought I responded to this post earlier but I've been kicked out frequently by this website so I guess my response was lost.
4 days ago
Hi there,

I struggled on trying to finish this exercise and now I'm studying the suggested solution.  The suggested solution uses TreeMap & TreeSet which was never brought up in any previous assignments so I didn't think of it myself.  However when I changed TreeMap to HashMap ( just to study and understand ), then the TreeSet to HashSet it didn't change the outcome.

Googling TreeSet vs. HashSet says HashSet is preferred because it's faster.
https://stackoverflow.com/questions/1463284/hashset-vs-treeset

But between HashMap and TreeMap , the TreeMap guarantees that the order of the keys is sorted.  So Maybe that's why it's being used?  However the Person class implements Comparable so doesn't that take care of the sort issue?

Thank You for any feedback and discussion.

Screen shot of the assignment
https://imgur.com/a/aTp8pVq


















1 week ago

Junilu Lacar wrote:Comments are not the solution to a structural/organization problem. That's like putting a sticky note on your refrigerator saying "Make sure to set the thermostat to 75 to make the microwave oven work."

In fact, comments like those you are suggesting would be considered a "code smell."



Got it.  And , honestly I figured as much.  

Thank You for your time.
2 weeks ago

Junilu Lacar wrote:

Junilu Lacar wrote:More problematic is the fact that if I decided to change the menu option to "Q to quit", then I'd have to go to UserInterface to do that. However, I'd also need to go to PersonMaintenance and change the condition to check for "Q" instead of "x".


And in fact, in the other thread,

you wrote:The program is supposed to have 8 commands .  1 - 7 does different things, 8 is to quit.



Correct.  Originally I had both the printMenuOptions() method and the enterMenuOption() method on the UserInterface class.  The assignment wants the user to enter the value X to quit.  I apologize, I can see saying "8 is to quit" implies something different.  
I think I'm just going to keep the UserInterface the way it was prior to making the changes I was trying to do here .  I understand what you mean by Code should be cohesive and Thank You.

Would some of the issues you pointed out , where the printMenuOptions() method being on UserInterface and enterMenuOption() being on PersonMaintenance , been resolved by comments?   If I had added a comment on the UserInterface that the requirement is to use "X" and that the printMenuOption() method was on PersonMaintenance?

If I completely missed your point, please let me know.  

Thank You
2 weeks ago

Junilu Lacar wrote:

Lisa Austin wrote:
NOW
But with the suggestion to have PersonMaintenance drive , how can I get UserInterface to call a method on PersonMaintenance without creating a new PersonMaintenance object ?  Is there a way I can pass the current PersonMaintenance object over to UserInterface?


There is a way but I doubt that's a good idea. If PersonMaintenance knows about UserInterface, then it's not a good idea to have UserInterface know about PersonMaintenance. Rethink your idea about UserInterface accessing anything that has to do with PersonMaintenance. If you do that, you create a two-way dependency: PersonMaintenance is dependent on UserInterface and UserInterface is dependent on PersonMaintenance. That kind of design, one where you have circular dependencies, tends to create problems.



Gotcha .  Okay.  From what Knute Snortum said, it does sound like the UserInterface was only supposed to be for things like response (i.e "address unknown" , "not found" ,"phone number not found" )   but the way the assignment has it's requirements , the response "phone number not found" is the only response that repeats so I am not sure it makes sense to just use it for responses.  

I'll keep thinking.  Thanks!
2 weeks ago
I've been stuck on an assignment for a while and decided to try and just tackle a suggestion made by Knute Snortum.  https://coderanch.com/t/711072/java/Suggestion-handling-expected-results-code on this post.

PersonMaintenance would be the class driving the process.  That is, it would have the start() method and that would call the printMenuoptions() from UserInterface (you will need an instance of the class unless you make the method static).  PersonMaintenance would have the enterMenuOption() method in it and so on.  So PersonMaintenance would have all the logic to "maintain" a Person (add a Person, search, etc.)  Then printing "not found" or "phone not found" would be calls to UserInterface.



I made the changes I think but currently my UserInterface has the method performCommand() which calls the PersonMaintenance to perform searches,  adds information and removes information.  

Previously
The way I had PRIOR to changing everything was UserInterface had the start() method , and that was called by the Main method.   I created a PersonMaintenance object in the UserInterface.  PersonMaintenance would create the Person object. .  From UserInterface I used the PersonMaintenance object to call the methods within PersonMaintenance.  I hope that makes sense.

Just to try and draw an explanation as to what I mean :  

UserInterface  {

      PersonMaintenance {
                                       Person {  }
                                   }
                      }



NOW

But with the suggestion to have PersonMaintenance drive , how can I get UserInterface to call a method on PersonMaintenance without creating a new PersonMaintenance object ?  Is there a way I can pass the current PersonMaintenance object over to UserInterface?










2 weeks ago

Knute Snortum wrote:That looks better.  You have the UI isolated in a class.  But I was thinking that PersonMaintenance would be the class driving the process.  That is, it would have the start() method and that would call the printMenuoptions() from UserInterface (you will need an instance of the class unless you make the method static).  PersonMaintenance would have the enterMenuOption() method in it and so on.  So PersonMaintenance would have all the logic to "maintain" a Person (add a Person, search, etc.)  Then printing "not found" or "phone not found" would be calls to UserInterface.



Hi Knute Snortum  sorry so late responding.  I'll get that PersonMaintenance class updated.  I've been struggling with the last requirement of my project and I think I may need to redo everything.  The command #7 wants if the user doesn't enter a keyword then all information ( phone and address ) will print to screen , in order of how it was entered.  I have been struggling to figure out IF there is a way I can do this with how I have things structured.   With separate Person, Phone and Address classes but I've hit a wall so I'm thinking about re-working / refactoring .

Thank You however for all your help with this and understanding my issue.
2 weeks ago
Hey Knute Snortum I hope you see this.      
Can you please tell me if I have the right idea?  Also again my address part isn't finished as of yet still.


Knute Snortum wrote:One of the things I noticed is that you have UI in your Person class.  addPhone() shouldn't prompt for or input a phone number, it should just be:




Okay so I took out ALL user input from my Person class.


Knute Snortum wrote:

Also, I think UserInterface is doing more than it should be.  The actual logic of putting data into Persons and search should be a its own class.  Let's call it PersonMaintenance.  This class would call UserInterface to print the menu and to prompt and get data.  It would contain the logic for searching Persons.  The Search class would go away in this model.  Whether you call UserInterface to print "not found" or "phone not found" would be in PersonMaintenance.  Anything with a System.out.println() or a scanner would be in UserInterface and only there.

Does this structure make sense to you?



I did the following:
  • Removed the Search class
  • I created the PersonMaintenance class


  • On the PersonMaintenance class
  • All of the logic of putting data and searching for data


  • On the UserInterface class
  • Has all print statements ( Anything with System.out.println() )
  • Prints the menu , and prompts for UI



  • Knute Snortum wrote:

    Whether you call UserInterface to print "not found" or "phone not found" would be in PersonMaintenance.



    But yet I don't know how to make this happen .    Right now I have the UserInterface calls methods on PersonMaintenance if the method returns a null value it prints that the phone number wasn't found but I think you are suggesting the opposite?  If the phone number isn't found, the method doing the phone number search calls a methods on the UserInterface to prints the statements?  


    Here are my changes














    1 month ago

    Knute Snortum wrote:One of the things I noticed is that you have UI in your Person class.  addPhone() shouldn't prompt for or input a phone number, it should just be:

    Also, I think UserInterface is doing more than it should be.  The actual logic of putting data into Persons and search should be a its own class.  Let's call it PersonMaintenance.  This class would call UserInterface to print the menu and to prompt and get data.  It would contain the logic for searching Persons.  The Search class would go away in this model.  Whether you call UserInterface to print "not found" or "phone not found" would be in PersonMaintenance.  Anything with a System.out.println() or a scanner would be in UserInterface and only there.

    Does this structure make sense to you?



    Thank You.  I THINK it makes sense to me.  After writing this post I was skimming over class about design and I believe I saw something like what you are talking about.   I'll try and put what you suggest in practice.  Thank You

    1 month ago

    Swastik Dey wrote:

    The searchPhoneNumberByName(Person person, String name ) doesn't return anything.  It only calls a search method on the Person class and prints the result.




    The return type of the method is void.  What are you trying to return from this method?



    This is the method called when the user enters command #2 and currently it prints "  not found" when person.getPhone returns a null or empty.      If the user enters command #5 the method searchForAllInformation(Person person) is called.  In the method it calls searchPhoneNumberByName(Person person, String name) because the assignment requires a person's phone number to be printed as part of command #5 but if person.getPhone returns a null or empty the assignment expects "  phone number not found" to be printed.

    My question is.     Is there a good option for both commands to use the method searchPhoneNumberByName(Person person, String name) and still print the two different messages for the same scenario ( if person.getPhone returns a null or empty the assignment expects " )?    

    I'm not asking a How To question .  Like I'm not asking how to get searchPhoneNumberByName(Person person, String name) to return anything.  I know it's a void right now and I can change it to a string and return those messages rather than have them print out.   That maybe what I need to do.  Have it return the Null and based on whether the user had entered "2" or "5" , it prints the appropriate response.

    I guess I was hoping someone would see how I have things organized / done and could help me see other options than what I see.


    I'm stuck here
    I can't think about what to do past the following options and none seem correct.

    A.  Repeat the phone number search I used for #2 rather than have #5's method, searchForAllInformation call searchPhoneNumberByName.   But that goes against the whole DRY concept doesn't it?
    B.  change searchPhoneNumberByName to return a String and handle printing out the results on  the UserInterface class?  It seems like I should just get rid of the Search class then.
    C.  change searchPhoneNumberByName to call another method on the Search class to handle the null and empty?





    1 month ago
    Introduction
    I'm working through an online course, MOOC Java part 2 https://materiaalit.github.io/2013-oo-programming/part2/week-9/.   Week 9, section 26.  It's the last assignment for this section and we are supposed to design the solution on our own.   That being said, I'm struggling with trying to keep from repeating code within methods.  Also object oriented.  The below program isn't a finished program.  It needs the Address part , and add error handling.

    I hope I can explain this well enough.  The issue really is with two commands at the moment and what to do with responses expected when the information isn't found.  It's not the entire program.  

    The assignment:

    The assignment is a phone and address search.   Right now I'm working through the phone part and the problem I'm struggling with is the  assignment wants slightly different expected results between #2 and #5 when the phone number isn't found.
    The program is supposed to have 8 commands .  1 - 7 does different things, 8 is to quit.

    Commands 1, 2 and 5:
  • 1. adds a (phone) number
  • 2. search(es) for a (phone) number
  • 5. search(es) for personal information ( i.e. phone number and address )


  • Example:



    The Issue:

    Both #2 and #5 searches for a phone number using the person's name.   But if the phone number isn't found, the expected result for #2 is "not found" where #5 it's "phone number not found".

    In the Search class.
    For command #2 I have a method name searchPhoneNumberByName(Person person, String name ).  
    For #5 I have method name searchForAllInformation(Person person) and inside that method it calls the searchPhoneNumberByName(Person person, String name ) method.  

    The searchPhoneNumberByName(Person person, String name ) doesn't return anything.  It only calls a search method on the Person class and prints the result.




    I'm stuck here
    I can't think about what to do past the following options and none seem correct.

    A.  Repeat the phone number search I used for #2 rather than have #5's method, searchForAllInformation call searchPhoneNumberByName.   But that goes against the whole DRY concept doesn't it?
    B.  change searchPhoneNumberByName to return a String and handle printing out the results on  the UserInterface class?  It seems like I should just get rid of the Search class then.
    C.  change searchPhoneNumberByName to call another method on the Search class to handle the null and empty?  


    Help Please

    I'm stuck.   I think I may just need to re-organize everything but I'm not sure what is the best way.    Should I get rid of the Search class altogether and instead do the searching in my UserInterface class ?  This would eliminate one layer at least.  I could have a method to call Person's getPhone method and another method to handle the null responses on UserInterface rather than on Search.




    Program is organized as

    I have 6 class files.
  • Main - just to start the program
  • UserInterface - gives instructions, takes user's commands.
  • Search - performs the various searches
  • Person - stores the phone and address information.  
  • Phone - "helper" class ( I think that's what it's called ).  Just stores the Phone info
  • Address - Same as Phone but for addresses











  • UserInterface class




    Search class




    Person






    Phone



    Address











    Main







    1 month ago

    Campbell Ritchie wrote:

    Lisa Austin wrote:. . . Got it.  . . . .

    Yes, you have



    Sweet!  Thanks again!  I appreciate all of time you take teaching me to do the right things.  
    1 month ago

    Campbell Ritchie wrote:

    Yesterday, I wrote: . . . the Winston Gutkowski school of computing. . . .

    Winston recommends making everything in sight final and private. The tighter encapsulation makes for more reliable code. If you have any problems, you can always change the modifiers. You can change private→public, but you can't change public→private without risking breaking dependent code.



    Got it.  I think I understand this.  Because if a method is public and something is using it then changing it from public -> private would break things.   But private methods wouldn't have another outside class calling it so making it public wouldn't break anything.
    1 month ago

    Campbell Ritchie wrote:

    Lisa Austin wrote:. . . Is this what is called "bubbling up" which Knute Snortum mentioned?

    No, I don't think it is.

    . . . What does the word "token" in the javadoc exactly mean?

    It is whatever is separated by the delimiter. Since the default delimiter for a Scanner is whitespace, it means any visible bit of text separated from the rest of the text by whitespace. Remember line end sequences count as whitespace. If you write multiple words separated by spaces, then each word is a token, as defined before. The Scanner#tokens() method does something different, but each Stream element is a token. Scroll that link to the top of the page; it gives some examples (mostly drawn from Dr Seuss) about what a token looks like.

    . . . post about beginners needing to be familiar with Streams . . .

    Well, that is my opinion, but I am completely correct

    Some suggestions about how you might handle exceptions here, as threatened last night.



    Thanks Campbell Ritchie for all your help.  I'm a self-learner so all the extra information is good.  I'll put into practice better exception handling with my java practice and go through all the info you gave.
    1 month ago

    Knute Snortum wrote:

    So I'm not familiar with what "bubble up" to the top means.  I did some Googling and is this a good example of what that means?
    https://teamtreehouse.com/community/whats-meant-by-bubbling


    That's what I meant.  It probably isn't that greatest term for what I'm describing since "bubble up" is often used about the same action with events, but I can't think of a better term.  "Propagate"?  Would that have been clearer?



    It's me not you.  Since I've been trying to learn Java , there are many things which surround Java and programming in general which I often get lost on.  
    Thank you for your patience however .
    1 month ago