Adult Content Warning

This community may contain adult content that is not suitable for minors. By closing this dialog box or continuing to navigate this site, you certify that you are 18 years of age and consent to view adult content.

Programming -- shell / java / c# / python / ada / lisp

Discussion in 'Technical Board' started by Nettdata, Dec 1, 2009.

  1. rei

    rei
    Expand Collapse
    Emotionally Jaded

    Reputation:
    16
    Joined:
    Oct 19, 2009
    Messages:
    1,273
    Location:
    Guelph, ON
    in that case, start here
     
  2. Arms Akimbo

    Arms Akimbo
    Expand Collapse
    Emotionally Jaded

    Reputation:
    2
    Joined:
    Oct 21, 2009
    Messages:
    717
    You could also check out
    http://ocw.mit.edu/courses/electric...o-computer-science-and-programming-fall-2008/

    It's free online course materials for MIT's intro to computer programming course, in which they focus on Python. Readings, lecture notes, assignments, lots of handy stuff. Even video lectures.

    You can also see what other comp sci courses they have at
    http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/
    which includes: C, C++, Java and more Python courses.
     
  3. AbsentMindedProf

    AbsentMindedProf
    Expand Collapse
    Emotionally Jaded

    Reputation:
    42
    Joined:
    Oct 20, 2009
    Messages:
    502
    Please forgive the simpleness of this question, but I'm trying to teach myself Java, and haven't done much programming at all. I'm using the Head First Java book that Nett recommended, and I'm having a problem with the first real program it has you create. I think it's more of a syntax issue then anything, but I can't really figure it out.

    Code:
    public static void main(String[] args){
     int numOfGuesses = 0;
     GameHelper helper = new GameHelper();
     
     SimpleDotCom theDotCom = new SimpleDotCom();
     int randomNum = (int) (Math.random() *5);
     
     int[] locations = {randomNum, randomNum+1, randomNum+2);
     thDotCom.setLocationsCells(locations);
     boolean isAlive = true;
     while(isAlive == true){
      String guess = helper.getUserInput("enter a number");
      String result = theDotCom.checkYourself(guess);
      numOfGuesses++;
      if(result.equals("kill"))
       isAlive = false;
       System.out.println(You took "+ numofGuesses + " guesses");
      }//close if
     }// close while
    }// close main
    I'm getting 13 errors that are all "class, interface, or enum expected" the first one occurs in the first line at "void"

    I understand how the loop is working, but I would really like to understand all the errors that I get so that I learn to use the language better. Thanks for the help.
     
  4. Celos

    Celos
    Expand Collapse
    Disturbed

    Reputation:
    0
    Joined:
    Oct 19, 2009
    Messages:
    292
    Location:
    Estonia
    Java is a strictly object oriented language. Among other things it means that everything must be contained in an object. What you pasted here is a function. It needs to be wrapped inside a class.

    edit: Sorry, I wasn't paying that much attention once I saw the error message and your code tags. The locations array is not correctly defined (mismatched brackets), the if statement is missing a starting bracket and the println output is missing a quotation mark.
     
  5. AbsentMindedProf

    AbsentMindedProf
    Expand Collapse
    Emotionally Jaded

    Reputation:
    42
    Joined:
    Oct 20, 2009
    Messages:
    502
    I appreciate the help. I made those changes, but I'm still getting the same errors. I think it has to be something at the beginning of the code that is messing a bunch of other stuff up. I'm going to keep messing with it, but anymore ideas about it would be welcome.
     
  6. Nettdata

    Nettdata
    Expand Collapse
    Mr. Toast

    Reputation:
    2,870
    Joined:
    Feb 14, 2006
    Messages:
    25,796
    When asking for help, paste the errors in, preferably within CODE tags.

    The output has a lot of very useful information, and usually includes the line/position that it's bitching about.
     
  7. AbsentMindedProf

    AbsentMindedProf
    Expand Collapse
    Emotionally Jaded

    Reputation:
    42
    Joined:
    Oct 20, 2009
    Messages:
    502
    Okay, here's the code again, and the complete error read out.

    Code:
    public static void main(String[] args){
     int numOfGuesses = 0;
     GameHelper helper = new GameHelper();
     
     SimpleDotCom theDotCom = new SimpleDotCom();
     int randomNum = (int) (Math.random() *5);
     
     int[] locations = {randomNum, randomNum+1, randomNum+2};
     thDotCom.setLocationsCells(locations);
     boolean isAlive = true;
     while(isAlive == true){
      String guess = helper.getUserInput("enter a number");
      String result = theDotCom.checkYourself(guess);
      numOfGuesses++;
      if (result.equals("kill"))
       isAlive = false;
       System.out.println("You took "+ numofGuesses + " guesses");
      }//close if
     }// close while
    }// close main
    Code:
    SimpleDotComGame.java:1: class, interface, or enum expected
    public static void main(String[] args){
                     ^
    SimpleDotComGame.java:3: class, interface, or enum expected
     GameHelper helper = new GameHelper();
     ^
    SimpleDotComGame.java:5: class, interface, or enum expected
     SimpleDotCom theDotCom = new SimpleDotCom();
     ^
    SimpleDotComGame.java:6: class, interface, or enum expected
     int randomNum = (int) (Math.random() *5);
     ^
    SimpleDotComGame.java:8: class, interface, or enum expected
     int[] locations = {randomNum, randomNum+1, randomNum+2};
     ^
    SimpleDotComGame.java:9: class, interface, or enum expected
     thDotCom.setLocationsCells(locations);
     ^
    SimpleDotComGame.java:10: class, interface, or enum expected
     boolean isAlive = true;
     ^
    SimpleDotComGame.java:11: class, interface, or enum expected
     while(isAlive == true){
     ^
    SimpleDotComGame.java:13: class, interface, or enum expected
      String result = theDotCom.checkYourself(guess);
      ^
    SimpleDotComGame.java:14: class, interface, or enum expected
      numOfGuesses++;
      ^
    SimpleDotComGame.java:15: class, interface, or enum expected
      if (result.equals("kill"))
      ^
    SimpleDotComGame.java:17: class, interface, or enum expected
       System.out.println("You took "+ numofGuesses + " guesses");
       ^
    SimpleDotComGame.java:18: class, interface, or enum expected
      }//close if
      ^
    13 errors
    
    Also, I'm running the code through the command prompt. As a beginner should I be using one of the editors? I thought doing it this way would get me used to some of the coding syntax stuff, but it's been more frustrating than I expected.

    I really appreciate the help guys.
     
  8. prexus

    prexus
    Expand Collapse
    Should still be lurking

    Reputation:
    0
    Joined:
    Oct 24, 2009
    Messages:
    7
    As celos mentioned before, Java is object-oriented, which means that every piece of code you write must be encapsulated in a class. Check, for example, this "hello world" program:

    Code:
    public class HelloWorld {
    
        // method main(): ALWAYS the APPLICATION entry point
        public static void main (String[] args) {
    	System.out.println ("Hello World!");
        }
    }
    Java's parser goes line after line in your code, looking for a class deceleration (or an interface or an enum, but leave those for later). Wrap the main method you have there with a "public class MyClass {" before and a "}" afterwards, and try again. You should also ave the file as "MyClass.java".

    As for an editor, it's very much a matter of opinion. I think you should use one - learning to program without one is akin to learning to write essays in notepad, in my opinion. I'm a big fan of Eclipse (<a class="postlink" href="http://www.eclipse.org/" onclick="window.open(this.href);return false;">http://www.eclipse.org/</a>), but there are several other solid ones out there.
     
  9. AbsentMindedProf

    AbsentMindedProf
    Expand Collapse
    Emotionally Jaded

    Reputation:
    42
    Joined:
    Oct 20, 2009
    Messages:
    502
    Thank you. I got it working, and I guess I had to learn the hard way that everything needs a class in java.
     
  10. Nettdata

    Nettdata
    Expand Collapse
    Mr. Toast

    Reputation:
    2,870
    Joined:
    Feb 14, 2006
    Messages:
    25,796
    <a class="postlink" href="http://www.mindview.net/Books/TIJ/" onclick="window.open(this.href);return false;">http://www.mindview.net/Books/TIJ/</a>

    Thinking in Java is a "must read", or at least a "must flip through", in my opinion.

    Free, eBook, full of awesomeness.
     
  11. captainjackass

    captainjackass
    Expand Collapse
    Experienced Idiot

    Reputation:
    0
    Joined:
    Oct 30, 2009
    Messages:
    102
    Hello ladies and gents...

    This is sort of a programming related question.

    Basically, I have some light experience in programming. I am not a programmer by trade or education, at all. I have experience in Python, html/css/javascript/php, and mostly VBA (which a lot of people laugh at but it's at least the most readily useful and less abstract).

    Anyway, I recently acquired a job a few months ago (not programming related), but I've used VBA in past jobs and have been using it more extensively for various purposes in my current job (that uses quite a bit of Excel and Outlook).

    Anyway I showed my boss and team some micro-applications I've created; by which I mean user-forms that are created based on certain data, and have an array of options/ buttons with a clean interface, and then analyze and format said data.

    Ironically, although the forms required a LOT of coding and work on my end - I think people were mostly impressed with the graphic of the company logo I put in the userform background that took all of 2 seconds.


    Anyway, since then, I have actually had some people in my department (including my boss) -- computer savvy, but completely green to programming -- ask me to attempt to teach them a little something in terms of learning and using VBA.

    Personally, I learned the absolute basics of programming via online, tooling around, trial-and-error.

    But my question is this: If you were in my position, how would you go about trying to teach 3-4 people how to get started and off the ground with VBA programming? Anyone here good at teaching methods?

    My first instinct is to first teach how the language can do simple math functions, the kinds of variables and how to store data in them and call them, maybe how VBA is comprised of objects, methods, and properties.

    But I'm not sure if this is the best way to go about doing it. Anyone have any ideas or experience with this?
     
  12. Celos

    Celos
    Expand Collapse
    Disturbed

    Reputation:
    0
    Joined:
    Oct 19, 2009
    Messages:
    292
    Location:
    Estonia
    I can't help with specific VBA resources, but my first reaction to a question worded like that is this: don't try to teach them. First off, you're saying that you're a novice yourself. It's likely that there are things/methods you don't know or aren't able to adequately teach. This will result in (or be at least partly responsible for) them doing stupid shit to achieve something simple and in the process wasting their time.
    Secondly, it's a fucking pain in the ass. You'll probably sink way too much time into trying to teach them and correcting them later (speaking from experience).

    Instead I'd suggest looking for some on-site training possibilities to get you started and then getting some good exercises and reading material from the trainers.

    Unless it really is just 3-4 people dicking around, wanting to put company logos on shit.
     
  13. captainjackass

    captainjackass
    Expand Collapse
    Experienced Idiot

    Reputation:
    0
    Joined:
    Oct 30, 2009
    Messages:
    102
    You're absolutely right, and it is mostly 3-4 people dicking around.

    I don't think there are any company resources/ training available for this, but maybe that's something to look into. However I don't know if some advanced tech team in this company has the time or inclination to teach 4 people from our floor the fundamentals of computer science/ VBA. Maybe something can be set up though, that's an idea. Personally I'd love formal instruction myself.

    However, I'm really not that green to VBA. I've been using it pretty intensely for close to 8 months. It's the most in-depth I've studied a language (others being javacript [also fairly user-friendly] and Python [syntax-friendly]).

    I'm a fairly intelligent person, very good at math as well, so I learn quickly and have been able to throw together some fairly complex and thoughtful work-- yes, I'm sure a lot of my code is spaghetti code, but I've been stumbling through for months and have learned more efficient practices. That, and most professional developers probably laugh at VBA, so my knowledge of the VBA in excel -- the dozens of obscure objects that comprise a chart, for instance (fuck Microsoft lol) -- might not be that shallow.


    But you're right --- teaching anything of use would be a time sink. I wouldn't mind committing an hour every two weeks to sort of attempt teach some things I know, and they can dick around on their own if they want, but let's be honest --- developing something of use takes a lot of time, especially for a beginner - and it might not be worth it for them.

    Look, the job I'm at right now is sort of an interim job for me --- I'm planning on going to grad school next year (though still thinking about it) and barring that I'll probably seek out a better job that's more in line with what I want to do. So I'm not really doing any of this shit to pad my resume, nor trying to get in good with the boss, but I wouldn't mind helping the team and building some respect for this little department I'm in.

    Eh, it was originally two of my smarter co-workers who asked me to teach them a few things, but the boss caught wind of it and wanted to join so that's when I thought I had to sort of prepare something more substantive.

    Anyway, most of the tools we would be creating would be just to make our own lives (and other department workers' jobs) easier. We aren't exactly building company products here.

    I mean, I've read a lot about programming, and there's a lot to learn - but what exactly are a lot of these best practices anyway? I mean I know documentation and comments and code readability are best practices, but does one really need to be an expert in data structures or algorithms to create efficient scripts in fuckin VBA in Excel? For our purposes, I don't think so.

    This company is one the biggest in the U.S. - and I'm in one of the shit departments - but let me tell you that the amount of inefficiency and horrid practices here is staggering. Hell, I wouldn't be surprised if you told me their accounting department was using an abacus last year. Again, I'm not here for the long haul, but hell, I've already created a few useful things - no matter how potentially laughable from a CS major's viewpoint - so fuck it lol. Better than just counting the minutes until August.
     
  14. Binary

    Binary
    Expand Collapse
    Emotionally Jaded

    Reputation:
    388
    Joined:
    Oct 21, 2009
    Messages:
    4,080
    If you really want to help, I'd go down to the nearest book store and spend a few minutes with each of the VBA books in there. Use your experience to figure out which one looks the most useful for a new user.

    Go back to the office, recommend the book, and say that you will be a resource for questions and help as they teach themselves about programming.

    This could easily become a MASSIVE time sink for you if you commit to actually teaching them. You've never taught before, from what it sounds like, and that is an entire set of skills by itself - a pretty complicated and unique one, in fact. Effective teaching is not that easy and usually has a lot of planning time involved.
     
  15. captainjackass

    captainjackass
    Expand Collapse
    Experienced Idiot

    Reputation:
    0
    Joined:
    Oct 30, 2009
    Messages:
    102
    Eh, you're right.

    Well, the boss doesn't seem like the programming type - he probably won't do anything anyway.

    The other two people are pretty intelligent and ambitious though.

    Again, this isn't really a formal thing. I wasn't going to try to teach some sort of all-inclusive course of everything I know.

    I was just going to get them started and then probably show them how to teach themselves - you know, different web boards, websites, googling VBA examples (most people have often encountered similar problems to you), using the record button and viewing the code.

    I was probably just going to do an informal one hour introduction, heavily simplified, reiterating that I'm by no means a veteran programmer, covering -

    1. How VBA is an object oriented programming language - how Excel is comprised of objects, hierarchically arranged.

    2. How essentially VBA programming is basically running methods and properties of those objects.

    3. How VBA can do arithmetic and the usefulness of variables.

    4. A few conditional and loop statements - particularly how to automate or repeat tasks which is probably going to be the most useful for our purposes and something I'm very efficient at (compared to the barf examples I've seen online several times).

    Maybe a few words about debugging, then tell them to look up the rest online/ tinker around themselves.

    Not sure if this would be a futile effort or not. Hell I can even just lookup a basic VBA introduction online and mirror that for the 'lesson.' I don't know.

    I'm obviously not terribly busy at work (work gets slow some days), and these people seem genuinely interested, so what am I to do? Tell them to fuck off and learn it themselves? I thought I'd toss them a bone.
     
  16. whathasbeenseen

    whathasbeenseen
    Expand Collapse
    Emotionally Jaded

    Reputation:
    27
    Joined:
    Dec 30, 2009
    Messages:
    604
    I think I have a project in mind. I know next to nothing about programming but I'm eager to learn to get myself out of server/deskside/phone support. I'm beginning to hate it with a passion. Anyway. A lot of my job is phone support. We use VOIP softphones to answer calls. One of the things that we have the most problems with is engineers not writing tickets for every call they take. My idea is to create a program that would capture the number calling in, compare it to a database of phone numbers, extract the company calling, populate some sort of form with that information, bring that window in to focus once the call is complete and then prompt the engineer to input various data into the form regarding the call. After the form is closed I'd want it to inject all of the entered data into our ticketing system. What do I use to make this happen? Thanks in advance guys.
     
  17. whathasbeenseen

    whathasbeenseen
    Expand Collapse
    Emotionally Jaded

    Reputation:
    27
    Joined:
    Dec 30, 2009
    Messages:
    604
  18. Ton80

    Ton80
    Expand Collapse
    Experienced Idiot

    Reputation:
    0
    Joined:
    Oct 22, 2009
    Messages:
    201
    I posted this in the Can Someone Help Me This thread, but this is clearly the better forum for it.

    My wife works for a hospital, and is trying to accomplish a specific task using vba within Access. I'm cutting and pasting from her email below, and I know that this has been driving her crazy, so we would both appreciate any help you guys might be able to provide:

    Here’s what I need to know how to do, because I can find most of the code online but I don’t know how to actually make it do it. I am using an Access Database and I have a query I created called “Flu Tracking” with a field name “LeadershipLast”.
    I want to export the query results in an excel workbook but I want to create separate worksheets by the field “LeadershipLast”.
     
  19. Euphonious

    Euphonious
    Expand Collapse
    Village Idiot

    Reputation:
    5
    Joined:
    Oct 20, 2009
    Messages:
    27
    Location:
    Austin, TX, Austin, United States
    I moved away from the web design world of HTML/CSS/PHP/Javascript/XML and all the other fancy abbreviations. Im currently a Linux SysAdmin noob learning the ways of Bash, Grep, Awk, Sed and all that fun stuff. Ive been writing some bash scripts, learning Perl/Python for server side scripting stuffs. I deal with Apache, MySQL and cPanel/WHM on a daily basis. Ive successfully setup LAMP on virtual enviroments plenty of times so I know my way around.

    I know this thread is pretty much dead but if there any other SysAdmins out there, YOU ARE NOT ALONE!
     
  20. whathasbeenseen

    whathasbeenseen
    Expand Collapse
    Emotionally Jaded

    Reputation:
    27
    Joined:
    Dec 30, 2009
    Messages:
    604
    Why did you move away from HTML/CSS/PHP/Javascript/XML? I am currently trying to jump in there after a hiatus from learning to code being sidetracked with building an ITIL helpdesk.