This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.

tangara goh

Ranch Hand
+ Follow
since Dec 27, 2009
I am a beginner in Java and hope to pick up the trade secrets so that I can move on to Android development
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
46
Given in last 30 days
6
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by tangara goh

Carey Brown wrote:Note that you are incrementing "i" twice.



Thanks Carey.

I feel so alone struggling with my code.  Forums are the only place where I can ask for help.

I wonder if other people are also doing the same like me or they can just google and understand how to do things immediately?

2 days ago

Knute Snortum wrote:I'm going to assume that your question is, How do I retrieve an enum values from a String value?  If that is correct, then try this:



Thank you so much.

You made it so easy where as I have been struggling this for SO L....O ....N....G ......Think I am not cut out to do coding....sigh....hope i can just finish this project will do.

Now, I am on to the next problem....


Thank you once again.....I am so thankful for your help.
2 days ago

Carey Brown wrote:It would really help us to help you. One way would be to provide properly formatted code. If you show effort then we are more likely to contribute. It would also help if you provided a stand-alone, subset of your project that we can compile and run (this would probably benefit you as well).

Here's an example, though it doesn't entirely compile. There are some missing pieces that I can't guess at.

Notice you have "i++" twice.







I hope you could let me know how to get the int value out.

Tks.
2 days ago

Knute Snortum wrote:You can get the value of the enum by using something like the below.  Will this help you?



Hi Knute,

Tks for your example.

However, I have problem in adding the value which in my case is an int into a List<Integer>

Here's how I used your code to apply here :



Hope that you can tell me where have I gone wrong in the above code.

Million thanks.
3 days ago
Hi expert,

I have tried to attempt the codility test but even the first one already stumped me   Very demoralising.....


Write a function:

    class Solution { public int solution(int[] A); }

that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A.

For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5.

Given A = [1, 2, 3], the function should return 4. // why this is 4 ?

Given A = [−1, −3], the function should return 1.

Write an efficient algorithm for the following assumptions:

        N is an integer within the range [1..100,000];
        each element of array A is an integer within the range [−1,000,000..1,000,000].




I would like to know



Why the answer is 4 for the above.

Tks.
2 weeks ago
OK. I got it.  Tks for pointing out.  Tks alot.

This is where I had gone wrong.

List<Subject> array = new ArrayList<Subject>();
// for(Subject s : array){
//array.add(new Subject(s.name));
array.add(new Subject("LPrichinese"));

array.add(new Subject("LPriMaths"));
array.add(new Subject("C"));
for(Subject s : array){
List<String> strList = array.stream()
.map(Subject:: toString).peek(System.out::println)
.collect(Collectors.toList());
2 weeks ago

Carey Brown wrote:If you had put in braces for your "for" loop you might have noticed your problem.



Pardon my stupidity but I still can't figure where is wrong or what step I have missed out.

Yes, the array is empty at that point you have pointed out.

So, then the Subject.name is then added in to the array to create the List<Subject> objects so where is the mistake I have made such that it won't print out the LPrichinese ?
2 weeks ago
Hi expert,

I am not sure how to get the first element to be printed.

Here's the snippet of code :



On adding the System.out.println, all I get is the LPriMaths and C but not LPrichinese....

Hope someone can tell me what is missing in my code so that I can get to see LPrichinese print out as well.

Tks.
2 weeks ago

Carey Brown wrote:You haven't posted the code for Subject yet. I assume it has one or more Blah's. If it has a List<Blah> then are you looking to see if the Subject contains any Blah, a particular Blah, or a matching list of Blah's?



Here is my Subject class :

2 weeks ago

Carey Brown wrote:

tangara goh wrote:


"array" is a List<Subject>, what does it mean for the list to "contain" a Blah.code? A Blah.code is not a Subject. The only thing that works with the "contains()" method is to search the list for an instance of another Subject.



Hi Carey,

Thanks for your reply.

This is the part that I am facing problem.

Now I am not sure where to place the Comparable interface in my code ?  Should I put it in Subject or ?

I have to revise all these topics but I hope you can give me some tips how to go about doing the comparison - the elements in the array against the Enum Blah to give me the values if the two matches.

Tks.
3 weeks ago

Joseph Mokenela wrote:Have a look at the following thread



Hi Joseph,

I have tried out as per the thread you have suggested.

However, I am not very clear how to do the Constructor of the class Subject if I have to make use of the Enum Keys Values instead of String.



Please let me know how do do the constructor for this part.





Tks.

3 weeks ago
Hi expert,

I am facing problem in understanding how to retrieve the value from Enum.

With reference to below URL,

https://stackoverflow.com/questions/604424/lookup-java-enum-by-string-value (However, this may not also be the one that address my problem.

For example, in this Enum here :



My problem is that I need to compare a List<Object> against the Enum Key as shown above.

If the List<Object> contains the Enum Key, then it will give me the corresponding values.

To be more specific :



I have tried and search for a solution but seems like nobody is comparing the arrays or list of another class with Enum to get the values.

Really hope some can guide me in this area.

Tks.

3 weeks ago

Carey Brown wrote:perhaps this TUTORIAL will help



But this is just one entity.
I am using 2 entities now - tutor and subject.

cos if I use JPA, they will normally use dependencies and used tutor to insert the subject and not using subject to insert by itself.

That's the area I am stumped.  I wonder should I use DAO pattern for my case.

Any advice is appreciated.

1 month ago

Piet Souris wrote:

tangara goh wrote:(...)
So the List<Subject> must have a list of SubjectNames and a list of matching SubjectIDs.

But, I am not sure how to do it. 


Well, you could have this Subject enum:

with this use:

but I agree with Junilu: a Subject class like in your opening post, and oerhaps with a field: MOESubjectIDs moes, wasn't bad at all, and much more flexible.



Hi Piet,

Thanks for showing me the above.

I need to highlight that I am using DAO pattern where I have a SubjectDAOImpl class that use Subject class to insert the subject which make us of a SQL insert query.  The Manager class is one which hide the logic and Controller calling the Managerial and insert the method insdie.

Actually, at this point, I am abit confused as in should I use TutorDAOImpl to insert the Subject class List<Subject> or still use SubjectDAOImpl and with the Subject now change to Enum altogether, how should I piece everything together ?

Hope to hear some advice how best to move things forward.

Tks again.
1 month ago

Carey Brown wrote:



Thanks for the clarification.

However, I need the return to be in a List cos I am using List<Subject> as an insertion into the database,

So the List<Subject> must have a list of SubjectNames and a list of matching SubjectIDs.

But, I am not sure how to do it. 

1 month ago