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

Reputation: 2134 Grandmaster
Group:
Mentors
Active Posts:
4,463 (1.67 per day)
Joined:
11-December 07
Profile Views:
63,844
Last Active:
User is online 7 minutes ago
Currently:
Viewing Board Index

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: Restricted access to methods

    Posted 30 Mar 2015

    It sounds like a poor design to me, but maybe also a problem set by the teacher. One solution is to extract a superclass from your parent that has only the methods all the children should see. The method available to two of the children stays in your current parent. Your inheritance hierarchy will look like this:

    Superclass
    |
    |--Parent
    |  |
    |  |--Child A
    |  |
    |  `--Child B
    |
    `--Child C
    
  2. In Topic: How often do you have to look stuff up?

    Posted 25 Mar 2015

    On the other hand, Wikipedia is a marvellous tool for serendipitously following threads of interest. If you follow the rabbit hole deep enough you'll come out at all sorts of interesting places.

    For research at work, one or two levels deep is the sweet spot. I usually land on a general page which gives me a nice overview and then follow a link to the specific part I really need.
  3. In Topic: Why Is Your Job Fulfilling?

    Posted 24 Mar 2015

    Quote

    But it was the notes from Zed Shaw that are stuck in my brain while thinking about this. He says in his Learn Python the Hard Way book that he had amassed so much knowledge that programming had become boring for him (paraphrasing).


    I remember reading this and wondering if it was a glimpse into my future. There is no way to know. If I can provide for my future self and keep my present self entertained then that's about as much as I can do.
  4. In Topic: Deck of cards program (Which is more efficient)

    Posted 23 Mar 2015

    Also, hearts and diamonds are always red. Spades and clubs are always black. It can also be confusing to reuse variables so it's best to just create new ones. How about this:

    import java.util.Random;
    
    
    public class Main {
    	
    	public static void main(String args[]){
    		Random rand = new Random();
    		
    		String[] cardNumber = {"Ace", "1", "2", "3", "4", "5", "6", "7", 
    				"8", "9", "10", "King", "Queen", "Jack"};
    		String[] cardType = {"Spades", "Hearts", "Diamonds", "Clubs"};
    		String[] cardColor = {"Black", "Red", "Red", "Black"};
    		
    		int counter = 0;
    				
    		do{
    			int numberLength = cardNumber.length;
    			int numberIndex = rand.nextInt(numberLength);
    			String number = cardNumber[numberIndex];
    			System.out.print(number + " of ");
    		
    			int typeLength = cardType.length;
    			int typeIndex = rand.nextInt(typeLength);
    			String type = cardType[typeIndex];
    			System.out.print(type + " ");
    		
    			String typeColor = cardColor[typeIndex];
    			System.out.print(typeColor);
    			
    			counter++;
    			System.out.println();
    		} while(counter < 4);
    	}
    }
    
    
    


    You can clean it up further by removing some of the variables, combining the print and using a for loop.

    import java.util.Random;
    
    public class Main {
    
    	public static void main(String args[]){
    		Random rand = new Random();
    
    		String[] cardNumber = {"Ace", "1", "2", "3", "4", "5", "6", "7", 
    				"8", "9", "10", "King", "Queen", "Jack"};
    		String[] cardType = {"Spades", "Hearts", "Diamonds", "Clubs"};
    		String[] cardColor = {"Black", "Red", "Red", "Black"};
    
    		for(int i = 0; i < 4; i++) {
    			int numberIndex = rand.nextInt(cardNumber.length);
    			int typeIndex = rand.nextInt(cardType.length);
    			String number = cardNumber[numberIndex];
    			String type = cardType[typeIndex];
    			String typeColor = cardColor[typeIndex];
    			System.out.println(number + " of " + type + " " + typeColor);
    		}
    	}
    }
    
    
    


    This still doesn't change the fact that you can choose the same card twice. Can you think how to solve that?
  5. In Topic: Does the position of my [ ] in main() effect anything?

    Posted 22 Mar 2015

    Another possibility:

    public static void main(String... args) {}
    

My Information

Member Title:
Cabbage
Age:
32 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