www.webdeveloper.com
Results 1 to 7 of 7

Thread: for my friend a little piece of codness

  1. #1
    Join Date
    Nov 2003
    Posts
    128

    for my friend a little piece of codness

    PHP Code:

    import java
    .util.*;
    import java.lang.*;
    public class 
    poker extends Object {

        public 
    poker() {
        }
        
        static 
    java.util.Random r=new java.util.Random();
        
        public static 
    int pickcard(){
            return 
    r.nextInt(13)+1
        }
        
        public static 
    int picksuit(){
            return 
    r.nextInt(4)+1;
        }
        
        public static 
    String cardname(int cardint suit){
            
    String cardname="";
            if (
    card>1&&card<11){System.out.print(card);}
            if (
    card==1){cardname="Ace";}
            if (
    card==11){cardname="Jack";}
            if (
    card==12){cardname="Queen";}
            if (
    card==13){cardname="King";}
            if (
    suit==1){cardname=cardname " of diamonds. ";}
            if (
    suit==2){cardname=cardname " of hearts. ";}
            if (
    suit==3){cardname=cardname " of spades. ";}
            if (
    suit==4){cardname=cardname " of clubs. ";}
            return 
    cardname;
        }
        
        public static 
    void main (String args[]) {
            
    int card,suit,card1=0,suit1=0,card2=0,suit2=0,card3=0,suit3=0,card4=0,suit4=0,card5=0,suit5=0;
            
    int ran=0;
            while (
    ran<5)
            {
            
    card pickcard();
            
    suit picksuit();
            if (
    ran!=0){
             while ((
    card==card1 && suit==suit1)||(card==card2 && suit==suit2)|| (card==card3 && suit==suit3)|| (card==card4 && suit==suit4)) 
             {
             
    card pickcard();
             
    suit picksuit();
             }
            }
            
            if (
    ran==0){
                
    card1=card;
                
    suit1=suit;}
            if (
    ran==1){
                
    card2=card;
                
    suit2=suit;}
            if (
    ran==2){
                
    card3=card;
                
    suit3=suit;}
            if (
    ran==3){
                
    card4=card;
                
    suit4=suit;}
            if (
    ran==4){
                
    card5=card;
                
    suit5=suit;}
            
    String cardname=cardname(cardsuit);
            
    System.out.print(cardname);

            
    ran++;
            }
            
    card=card3;
            
    suit=suit3;
            
    String cardname=cardname(cardsuit);
            
    System.out.print(cardname);
        }


    Last edited by davey; 11-29-2004 at 02:35 PM.

  2. #2
    Join Date
    Jul 2004
    Location
    West Coast, Canada
    Posts
    665
    What's your question? lol.

    I would suggest you run a program called, "Checkstyle", that will check for semantic errors in your code.

    Such semantic errors, like,

    Code:
    public class foo {
    
    }
    Should be

    PHP Code:
    public class foo
    {


    and

    Code:
    public static void main (String args[]) { 
    }
    Should be

    PHP Code:
    public static void main (final String args[])



    I'm just suggesting it because it's industry standards to have a standardized semantic method of coding.

  3. #3
    Join Date
    Nov 2003
    Posts
    128
    thanks for the tip but we are just in a basic high school class so i dont think we need to worry about that just yet

  4. #4
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    Bueza, I wouldnt really call these errors. I have worked in industry and its purely the developers decision whether he/she uses block openers on new lines.

    Whitespace wont effect the syntax.

  5. #5
    Join Date
    Jul 2004
    Location
    West Coast, Canada
    Posts
    665
    Originally posted by buntine
    Bueza, I wouldnt really call these errors. I have worked in industry and its purely the developers decision whether he/she uses block openers on new lines.

    Whitespace wont effect the syntax.
    Hmm, my lab instructor (who has worked for Symantec) said there was an standard of coding for each company, and for Symantec, they have a style-checker program that's something close to the restrictions of Checkstyle off of Sourceforge.

    That's why when we code in Java in University right now, we lose marks for not conforming to the style guidelines. :P

    But, yeah, it totally depends on the developers. In this case, for Symantec, there are a lot of developers, so they need to follow a specific style guide.

  6. #6
    Join Date
    Nov 2003
    Location
    Jerryville, Tejas
    Posts
    11,715
    Originally posted by davey
    thanks for the tip but we are just in a basic high school class so i dont think we need to worry about that just yet
    One thing you DO need to worry about though is this.
    Code:
    public class poker extends Object {
    
        public poker() {
        }
    The OO naming rule is that class names (and constructors) are capitalized and objects are not. So that should be:
    Code:
    public class Poker extends Object {
    
        public Poker() {
        }
    Of course in this you're not "making" a Poker but if you did it might look like

    Poker texasHoldem = new Poker();

  7. #7
    Join Date
    Nov 2003
    Location
    Jerryville, Tejas
    Posts
    11,715
    Symantec has been a good SE company with good practices. In a rigorous shop there'll be coding standards that are inforced by tools like Checkstyle or Jalopy and part of the process of checking code into the CMS will be to first run the company's configuration of a pretty printer on the source. There are two big benefits there. First, the code all looks the same so it's easier for teams to work on it and understand it. Second, the diffs between versions of a piece of code will really be functional changes, not just formatting changes. There are a lot of pretty printers out there but there aren't a lot of really good ones.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles