Java programming

Discussion in 'Computer Science & Culture' started by draqon, Jan 20, 2009.

Thread Status:
Not open for further replies.
  1. river-wind Valued Senior Member

    Messages:
    2,671
    I just started a course in java as well. The instructor is avoiding any IDE, sadly, so it's DOS prompts only. sigh

    We had to write a class with "two methods, two instance variables, and a custom constructor" for this week's homework. Figured I'd have fun with it.

    Please Register or Log in to view the hidden image!


    Code:
    import java.util.*;
    
    public class Character
    {
      private String name;
      private int cID;
      private int charType;
      private static int numOfType;
      private int[] attri = new int[6]; //str,def,agi,int,wis,car
      private String[] attriName = {"str","def","agi","int","wis","car"};
      
      Character(int charTypeIn,String nameIn)
      {
        Scanner scanner = new Scanner (System.in);
        name = nameIn;
        charType = charTypeIn;
        numOfType = numOfType + 1; 
        int tempSum = 0;
        int rollNum = 0;
        String reroll="";
        int[] diceRoll = new int[4];
        int[] tempAttri = new int[7]; //str,def,agi,int,wis,car
    
        do{
          rollNum=rollNum+1;
          reroll="N";
          for (int d=0;d<=6;d++){
            System.out.println("Dice roll set "+(d+1)+":");
            tempSum = 0;
            for (int x=0;x<=3;x++){
              Dice die = new Dice();
              diceRoll[x]=die.rollDie(6);
              if (x<=2)
                System.out.print(diceRoll[x]+", ");
              else
                System.out.print(diceRoll[x]); 
            }
    	
            //total top three contents of array
            Arrays.sort(diceRoll);
            System.out.print("; dropping lowest value("+diceRoll[0]+"), ");
            for (int x=1;x<=3;x++){
              tempSum=tempSum+diceRoll[x];
            }
            System.out.println(" Dice Roll "+(d+1)+" Total: "+tempSum);
            tempAttri[d]=tempSum;
          }
    
          System.out.println("Available Values to be Assigned:");
          for (int x=0;x<=5;x++){
            System.out.println(tempAttri[x]);
          }
          if (rollNum==1) {
            System.out.println("Reroll this set? (Y/N)  WARNING: You cann only reroll ONE time.  You will have to accept the next roll.)");
            reroll= scanner.nextLine();
            if (reroll.equals("Y")){}else
              reroll="N";
          }
        }while (reroll.equals("Y"));
    
        //Allow user to assign values here.
      }
    
      public void getCharacter()
      {
        System.out.println(name+": ");
        for (int x=0;x<=5;x++){
    	System.out.println("   "+attriName[x]+": "+attri[x]);
        }
      }
    
    }
    
     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. Rick Valued Senior Member

    Messages:
    3,336
    Rubik,

    IntelliJ is good for refactoring, has some things worth exploring, although professionally I have been using Rational Application Developer for years now (before that WSAD), that I find it natural to work with Eclipse more. Plus the fact that I am involved with some open source development, makes eclipse a more natural choice for us.

    Rick
     
  4. Google AdSense Guest Advertisement



    to hide all adverts.
  5. river-wind Valued Senior Member

    Messages:
    2,671
    I just learned that java Strings are not changeable! In my code, the JVM would create the String object 'reroll' with an empty value, then it apparently creates a second String instance with the value 'N' and changes the reroll variable to point to the new String instance; dereferencing the original empty string in the process. Then it does this again when changing the value to 'Y', dereferencing the 'N' instance.

    Apparently StringBuffers aren't so 'unusual' *cough*dumb*cough*


    How's your work going, draqon?
     
  6. Google AdSense Guest Advertisement



    to hide all adverts.
  7. Dr Mabuse Percipient Thaumaturgist Registered Senior Member

    Messages:
    714
    Here's some Java Programming for you.

    Please Register or Log in to view the hidden image!



    Please Register or Log in to view the hidden image!

     
  8. firdroirich A friend of The Friends Registered Senior Member

    Messages:
    565
    It's great that your teacher is making you avoid an IDE. Java is best learnt that way. I used jedit or VIM in the beginning. VIM is my fav. Use netbeans at the moment, ver 6.5 has the javaFX sdk bundled.
     
  9. Rick Valued Senior Member

    Messages:
    3,336
    firdoirich and others,

    While it might be good to get down with some basics, I would still advice "AGAINST" such an action going forward. The reason why I am saying this is obviously professional; In professional world you "ALWAYS" work with an IDE in programming; be it Java, .NET or Ruby on Rails or even Haskell for that matter.

    There's just too much stuff to be done in a commercial application that you just cant get away with simple editor. My question would be that do you want to learn a language and be productive in creating end "product" or are you just interested in learning the language? If you are interested in "using" the language to create some application (commercial / open source / System) or whatever, you would be better off in using an IDE; Why unnecessarily waste time when you can get certain things done faster and plus you can move to doing more important and cool stuff ...

    But that's just me speaking from experience off course, my experience might be limited (I have worked with JEE, Java, C++,VB mostly); and so from experience for home projects on Ruby, Scala, Haskell I usually do use an IDE (Eclipse mostly as they have plugins for most languages).


    Rick
     
  10. Xelios We're setting you adrift idiot Registered Senior Member

    Messages:
    2,447
    God I hate that colored square...
     
  11. Crunchy Cat F-in' *meow* baby!!! Valued Senior Member

    Messages:
    8,423
    What he said. Your programming and debugging experience will be awesome.
     
Thread Status:
Not open for further replies.

Share This Page