cfoley's Profile User Rating: -----

Reputation: 1508 Grandmaster
Group:
Mentors
Active Posts:
3,219 (1.62 per day)
Joined:
11-December 07
Profile Views:
43,691
Last Active:
User is offline May 24 2013 09:15 AM
Currently:
Offline

Previous Fields

Country:
GB
OS Preference:
Who Cares
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
225
Expert In:
Java

Latest Visitors

Icon   cfoley has not set their status

Posts I've Made

  1. In Topic: Card Game Task Using Classes

    Posted 24 May 2013

    You don't need the getters in the equals() method. Private means accessible only from that class. The catch is that separate instances are still the same class. This compiles, for example:

    public class Card {
    
    	private int value;
    	private int suit;
    
    	public Card(int value, int suit) {
    		this.value = value;
    		this.suit = suit;
    	}
    
    	public boolean equals(Card other) {
    		return (value == other.value) && (suit == other.suit);
    	}
    
    }
    
    
  2. In Topic: I've burned out

    Posted 24 May 2013

    That just isn't true. You can play the guitar no matter how rich or poor you are (as long as you have one to start with). Listening to music is also cheap and a lot of people do it in their homes, on their commute and at their work.

    The gym can be expensive but it is something that is affordable as long as you are in gainful employment or are a student (since most universities have very cheap gyms).

    Classes and travelling are more of a time issue than a money issue for most. However, I bet even the busiest people could find one evening a week, and everybody gets holidays, right?
  3. In Topic: Setting Windows Registry Values

    Posted 24 May 2013

    Before you do that, be aware it will only work on Windows and if you mess it up, there is a good chance of messing up your users' computers. Java Web Start is designed to add similar functionality to Java programs. I would at least look into it before playing with the registry.
  4. In Topic: Finding duplicate in arraylist except for zero

    Posted 22 May 2013

    Why not use Java's collections to your advantage? A good answer might be that this is for class.

    As an aside, checkArray() is a bad method name. It doesn't tell you what you are checking for and it's lying about working with arrays. hasNonZeroDuplicates() is better and I'm sure there are better still.

    import java.util.*;
    
    public class Duplicates {
    
    	public static void main(String[] args) {
    		reportResult(1, 2, 3, 4, 5);
    		reportResult(0, 1, 2, 3, 4, 5, 0);
    		reportResult(0, 1, 2, 3, 4, 1, 2, 5, 0);
    		reportResult(1, 2, 3, 4, 1, 2, 5);
    	}
    
    	public static void reportResult(Integer... list) {
    		System.out.print(Arrays.toString(list));
    		String indicator = hasNonZeroDuplicates(Arrays.asList(list)) ? "has" : "does not have";
    		System.out.println(" This list " + indicator + " non-zero duplicates.");
    	}
    
    	public static boolean hasNonZeroDuplicates(List<Integer> list) {
    		return hasDuplicates(removeAllInstances(list, 0));
    	}
    
    	public static <T> List<T> removeAllInstances(List<T> list, T item) {
    		List<T> copy = new ArrayList<>(list);
    		while (copy.remove(item)) {
    			// Keep going until remove() returns false.
    		}
    		return copy;
    	}
    
    	public static <T> boolean hasDuplicates(List<T> list) {
    		Set<T> set = new HashSet<>(list);
    		return list.size() != set.size();
    	}
    
    }
    
    
  5. In Topic: The 14 Characters You Meet as a Coder

    Posted 21 May 2013

    Quote

    when asked to write a program to output text from a regular text file, in his native language of course, he couldn't do it.


    I think I'd run into issues with that too. My native language is English. :P

My Information

Member Title:
Cabbage
Age:
31 years old
Birthday:
April 7, 1982
Gender:
Location:
Glasgow
Forum Leader:
Java
Years Programming:
20

Contact Information

E-mail:
Click here to e-mail me
Website URL:
Website URL  http://

Comments

Page 1 of 1
  1. Photo

    burakaltr Icon

    06 Mar 2013 - 18:18
    Thanks for Your Precious Input. I Found the character counting thing very bedazzling. I have the code to it that I wrote Myself, but it took me Long to find a subtle Algorithm :)
  2. Photo

    cfoley Icon

    18 Oct 2011 - 03:29
    Cheers! The next one is in progress, but I'm having to learn and write some programs first. It's going to take a little time...
  3. Photo

    Dogstopper Icon

    18 Oct 2011 - 03:24
    Nice blog. Can't wait to see more
  4. Photo

    ayaz 786123 Icon

    25 Feb 2011 - 06:49
    have a nice day sir
  5. Photo

    cfoley Icon

    16 Feb 2011 - 17:26
    Oooh thanks! Your comment is the first I heard!
  6. Photo

    m-e-g-a-z Icon

    16 Feb 2011 - 15:34
    Congrats on becoming a Forum Leader! :)
  7. Photo

    Dogstopper Icon

    08 Jan 2011 - 23:49
    "Cabbage" is much better! :D
  8. Photo

    cfoley Icon

    06 Jan 2011 - 16:19
    Cheers dude!
  9. Photo

    Dogstopper Icon

    06 Jan 2011 - 14:36
    "Purple DIC-headed Warrior" doesn't quite apply now that you got the promotion. Well done!
  10. Photo

    DaneAU Icon

    08 Sep 2010 - 09:19
    "cfoley has no profile comments yet. Why not say hello?"
    I don't have many comments either, so i am only doing what the thingy below said to do, hello cfoley and thanks for the thanks :)
Page 1 of 1