Programming

So, as some of you know, I’m studying Computer Science at Purdue University Calumet, in Indiana currently. I’m enrolled in a beginning Java course which has been relatively easy thus far, minus the occasional road bump of new concepts. Just wanted to see who all here is also interested in computers, programming, and the like.

Here’s an assignment I just finished, so you may feast your eyes upon the simplicity and beginner-level stuffs.

import java.util.Scanner;


public class Hw3
  
{
  public static void main( String[] args)
    
  {
    
    System.out.println("Please enter a date in the mm/dd/yyyy format.");
    
    Scanner keyboard = new Scanner (System.in);
    keyboard.useDelimiter("/");
    
    String userString = keyboard.nextLine();
    int firstSlash = userString.indexOf("/");
    int lastSlash = userString.lastIndexOf("/");
    int length = userString.length();
    
    
    String monthString = userString.substring (0, firstSlash);
    if ( 2 != monthString.length())
    {
      System.out.println("Error with " + userString + ": The month must only be two digits.");
      System.exit(0);
    }
    int month = Integer.parseInt ( monthString );
    
    if (( month < 1 ) || ( month > 12))
    {
      System.out.println("Error with " + userString + ": The month must be between 1 and 12.");
      System.exit(0);
    }
    
    
    String dayString = userString.substring ((firstSlash + 1), lastSlash);
    if ( 2 != dayString.length())
    {
      System.out.println("Error with " + userString + ": The day must only be two digits.");
      System.exit(0);
    }
    int day = Integer.parseInt ( dayString );
    
    if ( day < 1)
    {
      System.out.println("Error with " + userString + ": The day cannot go lower than 1.");
      System.exit(0);
    }
    
    String yearString = userString.substring((lastSlash + 1), length);
    if ( 4 != yearString.length())
    {
      System.out.println("Error with " + userString + ": The year must only be four characters.");
      System.exit(0);
    }
    int year = Integer.parseInt( yearString );
    
    if (year < 1 )
    {
      System.out.println("Error with " + userString + ": Year cannot be less than 1.");
      System.exit(0);
    }
    
    Boolean leapYear = true;
    if ( 0 == (year % 4))
    {
      if ( 0 == (year % 100) &&  0 == (year % 400))
      {
        leapYear = true;
      }
      else if ( 0 == (year % 100) && 0 != (year % 400))
      {
        leapYear = false;
      }
    }
    else if ( 0 != (year % 4))
    {
      leapYear = false;
    }
          
    
    if ((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12))
    {
      if ( day > 31)
      {
        System.out.println("Error with " + userString + ": This month only has 31 days.");
        System.exit(0);
      }
    }
    else if ((month == 4) || (month == 6) || (month == 9) || (month == 11))
    {
      if (day > 30)
      {
        System.out.println("Error with " + userString + ": This month only has 30 days.");
        System.exit(0);
      }
    }
    
    if (month == 2)
    {
      if (leapYear == true)
      {
          if (day > 29)
        {
          System.out.println("Error with " + userString + ": February only has 29 days this year.");
          System.exit(0);
        }
      }
      else if (leapYear == false)
      {
          if (day > 28)
        {
          System.out.println("Error with " + userString + ": February only has 28 days this year.");
          System.exit(0);
        }
      }
    }
    System.out.println("The date " + userString + " is a correct date.");
    System.exit(0);
  }
}

This essentially receives a input through the keyboard in mm/dd/yyyy format for a date, runs it through a few checks, and then identifies whether it is a valid date, due to leap years or other logical aspects that make no sense for a date. Had issues with the leap year concept,but then decided on using a Boolean value for it and making it work. If it is invalid, it gives a reason why that’s so.

Good luck with Uni Zak!

I have a Cert 4 in IT (General) and am currently completing a Diploma in Networking (Equivalent to about 2 years at uni).

I have avoided programming at all costs because I find the languages in use (like ASP and Java) very archaic. I do know HTML5 and CSS3 though (self taught), which I much prefer to use (plus they read more easily to non-code speakers xD).

I also know some PHP from my course at TAFE (tertiary and further education).

I guess I would benefit from learning Java but I honestly CBF.

Hope it all goes well for you though :slight_smile:

I’m currently taking AP CompSci in high school right now, so I should be able to transition into a CompSci 2xx course in college with no sweat, and maybe even go straight into a CompSci 3xx. I’m a junior in high school, so next year I’ll be exploring some Python.

Outside of structured learning, I do alot of teensy tiny programming for random crap that I need. Explore this beautiful shell script that I wrote to parse the targets of a makefile:

targets () {
        make -rpn | gsed -n -e '/^$/ { n ; /^[^ ]*:/p }' | sort | egrep --color '^[^ ]*:' | sed 's/W$//' | tr -s ":" | awk -F: '!($1 in a){b[++n]=$1} {a[$1]=a[$1] $2} END{for (i=1; i<=n; i++) print b FS a[b]}' | awk '{print NF,$0}' | sort -nr | cut -d' ' -f 2- | ~/.env/treedumper.py
}

and the contents of treedumper.py (referenced above):

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

text = ""
for line in sys.stdin:
    text += line

branch = '├'
pipe = '│'
end = '└'
dash = '─'


class Tree(object):
    def __init__(self, tag):
        self.tag = tag


class Node(Tree):
    def __init__(self, tag, *nodes):
        super(Node, self).__init__(tag)
        self.nodes = list(nodes)


class Leaf(Tree):
    pass


def _draw_tree(tree, level, last=False, sup=[]):
    def update(left, i):
        if i < len(left):
            left = '   '
        return left

    print ''.join(reduce(update, sup, ['{}  '.format(pipe)] * level)) \
          + (end if last else branch) + '{} '.format(dash) \
          + str(tree.tag)
    if isinstance(tree, Node):
        level += 1
        for node in tree.nodes[:-1]:
            _draw_tree(node, level, sup=sup)
        _draw_tree(tree.nodes[-1], level, True, [level] + sup)


def draw_tree(trees):
    for tree in trees[:-1]:
        _draw_tree(tree, 0)
    _draw_tree(trees[-1], 0, True, [0])

class Track(object):
    def __init__(self, parent, idx):
        self.parent, self.idx = parent, idx


def parser(text):
    trees = []
    tracks = {}
    for line in text.splitlines():
        line = line.strip()
        key, value = map(lambda s: s.strip(), line.split(':', 1))
        nodes = value.split()
        if len(nodes):
            parent = Node(key)
            for i, node in enumerate(nodes):
                tracks[node] = Track(parent, i)
                parent.nodes.append(Leaf(node))
            curnode = parent
            if curnode.tag in tracks:
                t = tracks[curnode.tag]
                t.parent.nodes[t.idx] = curnode
            else:
                trees.append(curnode)
        else:
            curnode = Leaf(key)
            if curnode.tag in tracks:
                # well, how you want to handle it?
                pass # ignore
            else:
                trees.append(curnode)
    return trees

draw_tree(parser(text))

Stack Overflow is a great resource for random learning and questions, whether about syntax, implementation, best practices, or theory. I suggest if anyone runs into any problems to look for answers there, and if it hasn’t been answered yet, to ask the question. I have found my own butt saved many times on that site.

If anyone wants to see my less kludgy work, I am alebcay on GitHub.

Nice! Im going into Computer Software Engineering soon early next year :slight_smile:

EDIT: RN im taking UNM Computer Science Dual Credit course witch involves NetLogo and Java :); I also know my ways in photoshop as well!

I take Computer Design at my school. We’ve worked with programs such as

Blender
Rhinoceros
Adobe Photoshop / Illustrator

and we’ve gotten into a bit of Java as well. I love it!

Computer Forensics…

I get to play with Ddosping, the Enigma Machine, Kali, you name it.

I’m currently doing the second half of GCSE CS. From that point I’m going to do A-level in CS, and then get a BSc then MEng in CS (all in one 4-year course).

At GCSE CS we do python and appinventor, but tbh I knew most of the stuff about python before I started the course. I semi-learn a bunch of languages just to try them out (Rust, go, java, ruby), but my two main programming languages are python, PHP and server-side JS (node.js for the knowledgeable, which I absolutely hate, but is a necessary evil).

I would post some code, but my most recent project is pretty huge, based on the Laravel web application framework.

Another project I’ve worked on is rarestpep.es, again using the Laravel framework.

Come have a look at all the half-done stuff on my github

I now have to start learning my namesake

http://learnrubythehardway.org/book/
Tah-dah!

The USMA CS department has us learn Python, Scala, VHDL, and now a bit of Java and C.

I’m taking a computers 1010 course that is heavily Java as well. And I must say your annotations are very lacking. On another note it’s good to see that we have so many literate computer users among us. I will say that I immensely prefer lua, or any other procedural based language, over Java.

Fun fact: George Boole was a professor in the University I’m currently attending.

Same as above, plus mySQL and Assembly. Although I don’t remember much about assembly or VHDL. Those were from the mandatory electrical engineering courses that Meta and I had to take Junior year. EE = "Blergh…
[move]Major in CS. Come to the dark side. We have Cookies and free coffee.[/move]

Im doing a semester a my school for Beginner’s Java myself. I hate to say this word in any association about me…but I am very Noobish at Java, already 3 labs behind oops

Wow I’m so noobish by comparison. Currently studying for CS GCSE (although @mattheux1 aka VirBinarus will testify that nothing gets done in those lessons), planning to do the A-Level too, but I’m probably going to go for accounting or something else commerce-related at uni with a CS minor. I’m relatively competent in javascript, visual basic, HTML and CSS.

My experiments with EE came to an end when I connected a USB controller hub with the incorrect polarity and it started smoking.

Also, this.

That was hilarious.

Since it was brought up, I annotated a bit better, and cleaned it up a bit, a bit happier with it now!

[code]import java.util.Scanner;

public class Hw3

{
public static void main( String[] args)

{

System.out.println("Please enter a date in the mm/dd/yyyy format.");

Scanner keyboard = new Scanner (System.in);

//This will pick up user input through the keyboard

String userString = keyboard.nextLine();
int firstSlash = userString.indexOf("/");
int lastSlash = userString.lastIndexOf("/");
int length = userString.length();
//This will create the integers and string used to check how a string is entered or if it is valid.

String monthString = userString.substring (0, firstSlash);
if ( 2 != monthString.length())
{
  System.out.println("Error with " + userString + ": The month must only be two digits.");
  System.exit(0);
}
int month = Integer.parseInt ( monthString );

if (( month < 1 ) || ( month > 12))
{
  System.out.println("Error with " + userString + ": The month must be between 1 and 12.");
  System.exit(0);
}
//This checks if the month entered is of the right length, written in a valid format, or makes logical sense.

String dayString = userString.substring ((firstSlash + 1), lastSlash);
if ( 2 != dayString.length())
{
  System.out.println("Error with " + userString + ": The day must only be two digits.");
  System.exit(0);
}
int day = Integer.parseInt ( dayString );

if ( day < 1)
{
  System.out.println("Error with " + userString + ": The day cannot go lower than 1.");
  System.exit(0);
}
//This checks if the day entered is of the right length, written in a valid format, or makes logical sense.

String yearString = userString.substring((lastSlash + 1), length);
if ( 4 != yearString.length())
{
  System.out.println("Error with " + userString + ": The year must only be four characters.");
  System.exit(0);
}
int year = Integer.parseInt( yearString );

if (year < 1 )
{
  System.out.println("Error with " + userString + ": Year cannot be less than 1.");
  System.exit(0);
}
//This checks if the year entered is of the right length, written in a valid format, or makes logical sense.

Boolean leapYear = true;
if ( 0 == (year % 4))
{
  if ( 0 == (year % 100) &&  0 == (year % 400))
  {
    leapYear = true;
  }
  else if ( 0 == (year % 100) && 0 != (year % 400))
  {
    leapYear = false;
  }
}
else if ( 0 != (year % 4))
{
  leapYear = false;
}
//This creates the factor that determines whether or not a year is a leap year.

if ((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12))
{
  if ( day > 31)
  {
    System.out.println("Error with " + userString + ": This month only has 31 days.");
    System.exit(0);
  }
}
else if ((month == 4) || (month == 6) || (month == 9) || (month == 11))
{
  if (day > 30)
  {
    System.out.println("Error with " + userString + ": This month only has 30 days.");
    System.exit(0);
  }
}
//This determmines if the month entered has 31 days (Jan/Mar/May/July/Aug/Oct/Dec).
//Or if a month has 30 days (Apr/June/Sept/Nov) 

if (month == 2)
{
  if (leapYear == true)
  {
      if (day > 29)
    {
      System.out.println("Error with " + userString + ": February only has 29 days this year.");
      System.exit(0);
    }
  }
  else if (leapYear == false)
  {
      if (day > 28)
    {
      System.out.println("Error with " + userString + ": February only has 28 days this year.");
      System.exit(0);
    }
    //This checks if the month is February, and if it is a leap year/how many days there should be.
  }
}

System.out.println("The date " + userString + " is a correct date.");
System.exit(0);
//This tells the user that the date is valid.

}

}[/code]

Wellp, that just validated every reason I’ve ever had for not wanting to touch EE ever again.

Well, I’m slightly different.

I started programming in Visual Basic (Microsoft) in 2008.
Then moved on to HTML, CSS, JS, jquery.

Now I program in C# - with some Windows Programs my latest project is based here: https://jia0020.github.io/IntFix-Enterprise - it’s currently not publicly avaiable and I do some programming in Unity.

I do programming for fun.