Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!

Kyle Prouty

Greenhorn
+ Follow
since Jan 31, 2019
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
4
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kyle Prouty

I misread your post.

You should be walking through the string in the while loop and checking that its equal to the character. No need to substring anything since you are already checking that they only gave you a char.

Just split the string into a list of chars, walk the list in the loop and compare it to the single second input char. Sound like you also should keep a count of how many times you find the char in the string and return or print that number.
1 year ago
I think that you are saying that you type in text into the box, click the send button, and the text is still in the boxes?

If you are storing the inputs in an object and the dialog box is just displaying the current value of that object, then you may need to clear the value from that object.

a = "hello"
After I click send, a still had hello stored in it.
1 year ago
It looks like you may want to substring your first input string and check if it is equal to the single character second entry.

Right now you are saying while a == apple, thats false so it just exits and wont print anything
1 year ago
This error has to do with you using TreeSet.

Look at the java doc
https://docs.oracle.com/javase/7/docs/api/java/util/TreeSet.html

It says, "The elements are ordered using their natural ordering, or by a Comparator provided at set creation time, depending on which constructor is used."

Since you are storing your object in a TreeSet, your object will need to implement a comparable so that it knows how to order the objects.
Maybe just use a HashSet if you dont care about ordering or implement a comparable.

1 year ago

Here is a fun Java 8 way to do it.

1 year ago

I would take a step back and think about what the exercise is trying to achieve.

Here are some questions they are asking...

  • We are given a static class that has a main, we know that this class will start the execution of our program. Do I know how to compile and run a java class?
  • We are told to create a class. Do I know how to create a class?
  • We are told to add 4 static methods to that class. We are given the complete function definition, nice! Do I know what methods of a class are?
  • Do I know what public and static mean? Do I know what the double following public static means? Do I know what sum(double[] x) means?
  • We keep seeing static. What does that mean when my class is static. How does that change how methods are called?
  • Do I know how to iterate through an array?
  • Do I know how to return a value from a method?

  • 1 year ago
    Go learn how to build a Hello World React App. (Client Side)
    Go learn how to create a MySql local database. Learn how to create a schema, insert records, learn how to select records efficiently. (Database)
    Go learn Node.js and create a Hello World server-side application. Learn how to talk to your local database. Learn how the client and server side apps work together. (Server side)
    Go learn how to use bootstrap-react to make your app pretty on any device. (HCI)
    Lastly, go learn AWS so you can deploy your app to the cloud. (Deployment)
    1 year ago

    Kyle Prouty wrote:

    Carey Brown wrote:
    Absolutely NOT !!
    A Scanner object created from System.in SHOULD NEVER BE CLOSED, no matter what the IDE warnings say. Doing so closes down one of the system I/O streams so it can never be accessed again.



    Could you clarify this?
    It seems I would still disagree .



    Oh, I see. You were specifically saying this about System.in.
    I was not taking that into account.
    1 year ago

    Carey Brown wrote:
    Absolutely NOT !!
    A Scanner object created from System.in SHOULD NEVER BE CLOSED, no matter what the IDE warnings say. Doing so closes down one of the system I/O streams so it can never be accessed again.



    Could you clarify this?
    It seems I would still disagree .
    1 year ago

    I would recommend using a Try with resources so that you won't need to worry about closing your scanner.
    Also, using a switch statement can be cleaner.

    1 year ago

    Just to help you learn.

    Here is another way to do this.
    I removed static methods and encapsulated them into an object. I added in a Map and a loop using Java 8 lambda.

    1 year ago