Wesleigh Pieters

Ranch Hand
+ Follow
since Sep 04, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
9
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Wesleigh Pieters

thanks Winston, I would always like to learn better ways, I am fairly new to programming and Java.
11 years ago

james aggeles wrote:Thanks for the API link, but I don't see anything about intializing the ArrayList. I googled it but didn't see anyone creating an arraylist and then putting an array into it directly. do i have to create a for loop to do this with the .add command?



there are a few ways you could do this but easiest i think



then you can just check if it contains and remove.



just out of my head so you may need to fix syntax etc and test
11 years ago
null is different.

like I said your solution over looks the placement of those elements when it tries to build the second array. easiest would be an ArrayList and then using it's remove method. or if you don't want duplicates a Set etc.

http://docs.oracle.com/javase/7/docs/api/

edit (your new array should be the length of your old array - count ) but an ArrayList would still be better imo
11 years ago
can you not stop it from reading that in and adding it to the original array in the first place?

you are getting array out of bounds error?

also your for (int i = 0; i < count; I++) { - loop that will possibly not iterate over the entire array as count will be set by the number of instances where the element is not equal to "", but what if said elements are near the beginning of the array and it will then miss out valid entries near the end.
11 years ago

Winston Gutkowski wrote:

Darryl Burke wrote:but if I understood your post correctly you might find a SortedMap<String, SortedSet<Integer>> suitable.


And another class you might find useful is LineNumberReader.

Winston



very cool that nice
11 years ago


you will still get a NullPointerException if you try to compare one object with another that hasn't been initialised.

however if you check if the object is null itself then you will get what you are looking for



edit I am also pretty sure that you could compare and check with ignoring case in one loop.
11 years ago
I really struggle to follow what you are trying to say, please review what you are asking in a more coherent simplistic way.

From what I do gather though I would use a Map implementation and then sort it.
11 years ago
jens there are a few problems with your code, just for example match up your braces "{}" and see after the while();{{ // why is there 2 opening braces for example? and why a semi colon?

also % - that does not mean divide - that is modulos it means to return the remainder of, go read up on operators in java. so when i gave you the condition if (num%2 == 0) what this really means is return the remainder of my number of 2 and if that is equal to 0 then the number is even (i.e it is divisible by 2 with no remainder, get it?)

I have helped you a bit here but you really need to try understand what I have done



say you are stuck in the loop and it is not doing what you want, you can put in System.out.prinltn(""); statements at each point to print the value of a variable and then it will be easier for you to see where it is going wrong.
11 years ago
Please use code tags

if I compile this I get a frame with an test field, a password filed and a login button? what problems are you having exactly?
11 years ago
Scanner how so?

I would say one of the top pitfalls I have noticed is not sticking to the naming conventions
11 years ago
It is because in the first code you never actually call the method, you did write out the method but it is never called. Also it is good practise to call a static method by using the class name, ie Classname.staticMethodName(); for example when you call the Math methods it is Math.random(); etc.

so in your code you need to call the method and pass in the argument you have now created.



you see how confusing the repetition of naming is above?

edit - I see you solved it, well done
11 years ago

jens jarl wrote:I figured it might be psuedo code, but my lack of experience caused me to be unsure, thanks for clearing that up.
Im trying to do it in the way you suggested, but for some reason I just can't seem to get this line of code to work, do you know whats wrong?
Ive never done this with a scanner before, just typing strenght(14); is easy and it works but when I try doing the same with the scanner I just get a variable error.



You never declared the variable properly, what is strenght (btw isn't it strength?) isnt it an int? i.e



also there are a few general issues you should look at fixing, don't name your variables and methods the same, read up on the general conventions, I would have used something like public static void printStrength(){ }

so it is a noun verb pair that is descriptive with the second word starting with a capital.

Likewise with your class name, the words should all be capitilised, i.e OppGaveOne or ThisIsMyClassName etc
11 years ago
wrapping the code in an if statement and changing the boolean it depends on with the listener on the start button?

11 years ago

shivam singhal wrote:yeah.. 2 digit int...
in question its mentioning like that" CONSUMED UNITS in electricity bill"

n yeah they are related to country class.. as both the country provide electricity at different cost per unit..



ok so then you can still use my way just convert the input to an int



then use that n an if statement to check for country.

still even though it is checking based on an int I fail to see the need for an array, do you need to store multiple inputs for later use in the program?
11 years ago

shivam singhal wrote:hello Wesleigh..

my aim is not just entering the country name ,, but user must have to enter a 2-digit electric unit used ..
thats why i think to use array..



so they will enter a 2 digit int? (sorry what do you mean by electric unit used?) and then the 2 digit int must relate to a country(class)?
11 years ago