Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up Try the site in https mode Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: Java programmers look inside  (Read 7837 times)

0 Members and 1 Guest are viewing this topic.

shmokes

  • Just think of all the suffering in this world that could have been avoided had I just been a little better informed. :)
  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 10397
  • Last login:September 24, 2016, 06:50:42 pm
  • Don't tread on me.
    • Jake Moses
Java programmers look inside
« on: September 21, 2005, 11:10:19 am »
I'm in an introduction to programming class, and I just made a program that draws a beautiful picture of a truck out of a bunch of circles, triangles and squares.  You'll have to take my word for it that those shape classes are all made up, but now that I've got it drawn I want to make the vehicle drive away off the screen.  I tried to make a method that would move all the objects, but it moves them one at a time, so the headlight scrolls off the screen and when it's done a wheel goes, then the windshield, etc.

I think what I need to do is some kind of loop, so each object moves only one pixel before the next object goes and then it all starts over again and over again until every object has moved as far as I want it it.  But I don't know how to do that.  Can someone help?  here's my code:



/**
 * This class was heavily modified for Assignment number 1 in CSIS 1400 -
 * section 1 by Jake Moses.  It originaly displayed a simple house with
 * a setting sun. Now it displays a complex truck on a stary night during
 * a lunar eclipse. The original author's comments are below:
 *
 * This class represents a simple picture. You can draw the picture using
 * the draw method. But wait, there's more: being an electronic picture, it
 * can be changed. You can set it to black-and-white display and back to
 * colors (only after it's been drawn, of course).
 *
 * This class was written as an early example for teaching Java with BlueJ.
 *
 * @author  Michael Kolling and David J. Barnes
 * @version 1.1  (24 May 2001)
 */
public class Picture
{
    private Square sky;
    private Square grass;
    private Square bumper_1;
    private Square bumper_2;
    private Square hood_1;
    private Square hood_2;
    private Square bed_1;
    private Square bed_2;
    private Square bed_3;
    private Square window;
    private Square cab;
    private Triangle windshield;
    private Triangle hoodslant;
    private Triangle doorline_1;
    private Triangle doorline_2;
    private Triangle handle;
    private Circle wheel_1;
    private Circle wheel_2;
    private Circle headlamp;
    private Circle moon;
    private Circle eclipse;
    private Circle star_1;
    private Circle star_2;
    private Circle star_3;
    private Circle star_4;
    private Circle star_5;
    private Circle star_6;
    private Circle star_7;
   
    /**
     * Constructor for objects of class Picture
     */
    public Picture()
    {
        // nothing to do... instance variables are automatically set to null
    }

    /**
     * Draw this picture.
     * Code changed by Jake Moses on Sept. 20, 2005 for assignment.
     * I made all new fields and changed the constructor and methods
     * to create and manipulate a much more complicated picture than
     * the house with the sunset.
     */
    public void draw()
    {
       
        sky = new Square();
        sky.changeColor("blue");
        sky.moveVertical(-100);
        sky.moveHorizontal(-100);
        sky.changeSize(1000);
        sky.makeVisible();
               
        grass = new Square();
        grass.changeColor("green");
        grass.moveVertical(190);
        grass.moveHorizontal(-100);
        grass.changeSize(1000);
        grass.makeVisible();
       
        moon = new Circle();
        moon.changeColor("yellow");
        moon.moveHorizontal(24);
        moon.moveVertical(-48);
        moon.changeSize(40);
        moon.makeVisible();
       
        eclipse = new Circle();
        eclipse.changeColor("blue");
        eclipse.moveHorizontal(68);
        eclipse.moveVertical(-48);
        eclipse.changeSize(40);
        eclipse.makeVisible();
       
        star_1 = new Circle();
        star_1.changeColor("yellow");
        star_1.moveHorizontal(75);
        star_1.moveVertical(-10);
        star_1.changeSize(3);
        star_1.makeVisible();
       
        star_2 = new Circle();
        star_2.changeColor("yellow");
        star_2.moveHorizontal(245);
        star_2.moveVertical(0);
        star_2.changeSize(3);
        star_2.makeVisible();
       
        star_3 = new Circle();
        star_3.changeColor("yellow");
        star_3.moveHorizontal(255);
        star_3.moveVertical(-15);
        star_3.changeSize(3);
        star_3.makeVisible();
       
        star_4 = new Circle();
        star_4.changeColor("yellow");
        star_4.moveHorizontal(145);
        star_4.moveVertical(-45);
        star_4.changeSize(3);
        star_4.makeVisible();
       
        star_5 = new Circle();
        star_5.changeColor("yellow");
        star_5.moveHorizontal(103);
        star_5.moveVertical(18);
        star_5.changeSize(3);
        star_5.makeVisible();
       
        star_6 = new Circle();
        star_6.changeColor("yellow");
        star_6.moveHorizontal(-15);
        star_6.moveVertical(-3);
        star_6.changeSize(3);
        star_6.makeVisible();
       
        star_7 = new Circle();
        star_7.changeColor("yellow");
        star_7.moveHorizontal(193);
        star_7.moveVertical(-5);
        star_7.changeSize(3);
        star_7.makeVisible();
       
        windshield = new Triangle();
        windshield.changeColor("white");
        windshield.changeSize(45, 40);
        windshield.moveHorizontal(80);
        windshield.moveVertical(135);
        windshield.makeVisible();
       
        cab = new Square();
        cab.changeColor("red");
        cab.moveVertical(90);
        cab.moveHorizontal(70);
        cab.changeSize(40);
        cab.makeVisible();
       
        window = new Square();
        window.changeColor("white");
        window.moveHorizontal(74);
        window.moveVertical(97);
        window.changeSize(33);
        window.makeVisible();
       
        headlamp = new Circle();
        headlamp.changeColor("white");
        headlamp.moveHorizontal(35);
        headlamp.moveVertical(130);
        headlamp.changeSize(15);
        headlamp.makeVisible();
       
        hood_1 = new Square();
        hood_1.changeColor("red");
        hood_1.moveVertical(130);
        hood_1.changeSize(50);
        hood_1.makeVisible();
       
        hoodslant = new Triangle();
        hoodslant.changeColor("blue");
        hoodslant.changeSize(-11, 120);
        hoodslant.moveHorizontal(8);
        hoodslant.moveVertical(174);
        hoodslant.makeVisible();
       
        hood_2 = new Square();
        hood_2.changeColor("red");
        hood_2.moveVertical(130);
        hood_2.moveHorizontal(50);
        hood_2.changeSize(50);
        hood_2.makeVisible();
       
        bed_1 = new Square();
        bed_1.changeColor("red");
        bed_1.moveVertical(130);
        bed_1.moveHorizontal(100);
        bed_1.changeSize(50);
        bed_1.makeVisible();
       
        bed_2 = new Square();
        bed_2.changeColor("red");
        bed_2.moveVertical(130);
        bed_2.moveHorizontal(115);
        bed_2.changeSize(50);
        bed_2.makeVisible();
       
        bed_3 = new Square();
        bed_3.changeColor("red");
        bed_3.moveVertical(130);
        bed_3.moveHorizontal(130);
        bed_3.changeSize(50);
        bed_3.makeVisible();
       
        doorline_1 = new Triangle();
        doorline_1.changeColor("black");
        doorline_1.changeSize(70, 2);
        doorline_1.moveHorizontal(82);
        doorline_1.moveVertical(146);
        doorline_1.makeVisible();
       
        doorline_2 = new Triangle();
        doorline_2.changeColor("black");
        doorline_2.changeSize(70, 2);
        doorline_2.moveHorizontal(120);
        doorline_2.moveVertical(146);
        doorline_2.makeVisible();
       
        handle = new Triangle();
        handle.changeColor("black");
        handle.changeSize(3, 15);
        handle.moveHorizontal(110);
        handle.moveVertical(170);
        handle.makeVisible();
       
        bumper_1 = new Square();
        bumper_1.changeColor("black");
        bumper_1.moveVertical(164);
        bumper_1.moveHorizontal(-8);
        bumper_1.changeSize(16);
        bumper_1.makeVisible();
       
        bumper_2 = new Square();
        bumper_2.changeColor("black");
        bumper_2.moveVertical(164);
        bumper_2.moveHorizontal(172);
        bumper_2.changeSize(16);
        bumper_2.makeVisible();
       
        wheel_1 = new Circle();
        wheel_1.changeColor("black");
        wheel_1.moveHorizontal(65);
        wheel_1.moveVertical(150);
        wheel_1.changeSize(35);
        wheel_1.makeVisible();
       
        wheel_2 = new Circle();
        wheel_2.changeColor("black");
        wheel_2.moveHorizontal(160);
        wheel_2.moveVertical(146);
        wheel_2.changeSize(40);
        wheel_2.makeVisible();

    }

    /**
     * Make car drive off the screen.  Unfortunately it goes
     * one piece at a time.  Code added Sept. 20, 2005 by Jake Moses.
     * Too bad it's broken :(
     */
   
public void drive()
    {
       if(hood_1 != null)   // only if it's painted already...
        {
            hood_1.slowMoveHorizontal(-500);
            hood_2.slowMoveHorizontal(-500);
            hoodslant.slowMoveHorizontal(-500);
            bed_1.slowMoveHorizontal(-500);
            bed_2.slowMoveHorizontal(-500);
            bed_3.slowMoveHorizontal(-500);
            windshield.slowMoveHorizontal(-500);
            cab.slowMoveHorizontal(-500);
            window.slowMoveHorizontal(-500);
            headlamp.slowMoveHorizontal(-500);
            bumper_1.slowMoveHorizontal(-500);
            bumper_2.slowMoveHorizontal(-500);
            doorline_1.slowMoveHorizontal(-500);
            doorline_2.slowMoveHorizontal(-500);
            handle.slowMoveHorizontal(-500);
            wheel_1.slowMoveHorizontal(-500);   
            wheel_2.slowMoveHorizontal(-500);
        }   
    }
   
    /**
     * Initiate a lunar eclipse.
     * Code added Sept 20, 2005 to add a cool method.
     */
   
public void eclipse()
    {
       if(hood_1 != null)   // only if it's painted already...
        {
            eclipse.slowMoveHorizontal(-100);
        }   
    }
   
    /**
     * Change this picture to black/white display
     * Changed Sept. 20, 2005 by Jake Moses to reflect changes in fields
     */
   
public void setBlackAndWhite()
    {
        if(hood_1 != null)   // only if it's painted already...
        {
           
            sky.changeColor("white");
            grass.changeColor("black");
            moon.changeColor("black");
            eclipse.changeColor("white");
            star_1.changeColor("black");
            star_2.changeColor("black");
            star_3.changeColor("black");
            star_4.changeColor("black");
            star_5.changeColor("black");
            star_6.changeColor("black");
            star_7.changeColor("black");
            hood_1.changeColor("black");
            hood_2.changeColor("black");
            bed_1.changeColor("black");
            bed_2.changeColor("black");
            bed_3.changeColor("black");
            windshield.changeColor("white");
            cab.changeColor("black");
            bumper_1.changeColor("black");
            bumper_2.changeColor("black");
            window.changeColor("white");
            wheel_1.changeColor("white");
            wheel_2.changeColor("white");
            doorline_1.changeColor("white");
            doorline_2.changeColor("white");
            handle.changeColor("white");
            hoodslant.changeColor("white");
           
        }
    }

    /**
     * Change this picture to use color display
     * Changed Sept. 20, 2005 by Jake Moses to reflect changes in fields
     */
    public void setColor()
    {
        if(hood_1 != null)   // only if it's painted already...
        {
            sky.changeColor("blue");
            grass.changeColor("green");
            moon.changeColor("yellow");
            star_1.changeColor("yellow");
            star_2.changeColor("yellow");
            star_3.changeColor("yellow");
            star_4.changeColor("yellow");
            star_5.changeColor("yellow");
            star_6.changeColor("yellow");
            star_7.changeColor("yellow");
            eclipse.changeColor("blue");
            hood_1.changeColor("red");
            hood_2.changeColor("red");
            bed_1.changeColor("red");
            bed_2.changeColor("red");
            bed_3.changeColor("red");
            windshield.changeColor("black");
            cab.changeColor("red");
            bumper_1.changeColor("black");
            bumper_2.changeColor("black");
            window.changeColor("black");
            wheel_1.changeColor("black");
            wheel_2.changeColor("black");
            doorline_1.changeColor("black");
            doorline_2.changeColor("black");
            handle.changeColor("black");
            hoodslant.changeColor("blue");
        }
    }


}
Check out my website for in-depth reviews of children's books, games, and educational apps for the iPad:

Best Kid iPad Apps

ChadTower

  • Chief Kicker - Nobody's perfect, including me. Fantastic body.
  • Trade Count: (+12)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 38212
  • Last login:June 22, 2025, 04:57:38 pm
Re: Java programmers look inside
« Reply #1 on: September 21, 2005, 11:18:31 am »

Write a method that moves each piece one pixel.  Then call it repeatedly until the car is offscreen.

lokki

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 647
  • Last login:May 05, 2025, 06:18:51 pm
Re: Java programmers look inside
« Reply #2 on: September 21, 2005, 11:22:21 am »
yes what chad said.

do a loop on the drive car

public void drive()
    {
       if(hood_1 != null)   // only if it's painted already...
        {

loop 500 times

            hood_1.slowMoveHorizontal(-1);
            hood_2.slowMoveHorizontal(-1);
            hoodslant.slowMoveHorizontal(-1);
            bed_1.slowMoveHorizontal(-1);
            bed_2.slowMoveHorizontal(-1);
            bed_3.slowMoveHorizontal(-1);
            windshield.slowMoveHorizontal(-1);
            cab.slowMoveHorizontal(-1);
            window.slowMoveHorizontal(-1);
            headlamp.slowMoveHorizontal(-1);
            bumper_1.slowMoveHorizontal(-1);

etc.

        }   
    }

ChadTower

  • Chief Kicker - Nobody's perfect, including me. Fantastic body.
  • Trade Count: (+12)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 38212
  • Last login:June 22, 2025, 04:57:38 pm
Re: Java programmers look inside
« Reply #3 on: September 21, 2005, 11:29:59 am »

Don't write the code for him... this is for a class, not a personal project.

RayB

  • I'm not wearing pants! HA!
  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 11279
  • Last login:July 10, 2025, 01:33:58 am
  • There's my post
    • RayB.com
Re: Java programmers look inside
« Reply #4 on: September 21, 2005, 11:51:46 am »
Since he's still just learning, I would just use the double-buffer method.

Shmokes: Do it exactly the way you are already, but instead of drawing to the screen, first draw to some other memory you have reserved, same size as your actual screen drawing area. (this is your "buffer").

When your code is done moving all the truck parts, you can just "blit" over the entire buffer to your visible screen area in one shot. (A straight copy of the entire buffer).

This technique is called "double-buffer".

NO MORE!!

ChadTower

  • Chief Kicker - Nobody's perfect, including me. Fantastic body.
  • Trade Count: (+12)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 38212
  • Last login:June 22, 2025, 04:57:38 pm
Re: Java programmers look inside
« Reply #5 on: September 21, 2005, 11:54:25 am »

How is that simpler than a basic method and a for loop?  It's better than the method we've laid out but it's not simpler.

shmokes

  • Just think of all the suffering in this world that could have been avoided had I just been a little better informed. :)
  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 10397
  • Last login:September 24, 2016, 06:50:42 pm
  • Don't tread on me.
    • Jake Moses
Re: Java programmers look inside
« Reply #6 on: September 21, 2005, 11:56:24 am »
Don't worry about it.  That's exactly what I needed.  Driving the car off screen wasn't needed for the assignment.  We just had to make an original picture using at least one triangle, circle and square.

We got extra credit if we put motion in of some kind, which I initially tried to do with the car, but when it wasn't working as expected I just put in the eclipse.  The assignment is already turned in.

We are only two weeks into class and the reason I don't know how to call a method repeatedly is because we haven't got to that point.  I just wanted to figure out the car thing because It'll bug me that it doesn't work until it does.

Thanks for the info.


Ah...another response.  I understand conceptually what you are saying RayB, but I don't know how to do any of that.  I don't even know what size my screen is :)  My program just shows up on my Java preview window.
Check out my website for in-depth reviews of children's books, games, and educational apps for the iPad:

Best Kid iPad Apps

shmokes

  • Just think of all the suffering in this world that could have been avoided had I just been a little better informed. :)
  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 10397
  • Last login:September 24, 2016, 06:50:42 pm
  • Don't tread on me.
    • Jake Moses
Re: Java programmers look inside
« Reply #7 on: September 21, 2005, 11:59:23 am »

How is that simpler than a basic method and a for loop?  It's better than the method we've laid out but it's not simpler.

God....that's funny.  I asked my professor about it and he said to look into how to make a "for loop".  But he has an accent and I thought he said "full loop".   I thought it sounded a little but like "for" but I did a google search on "jave four loop".  When I didn't come up with anything I came here.
Check out my website for in-depth reviews of children's books, games, and educational apps for the iPad:

Best Kid iPad Apps

ChadTower

  • Chief Kicker - Nobody's perfect, including me. Fantastic body.
  • Trade Count: (+12)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 38212
  • Last login:June 22, 2025, 04:57:38 pm
Re: Java programmers look inside
« Reply #8 on: September 21, 2005, 12:02:31 pm »

Yep, the way described would be the method to move each part one pixel.  Then you write a very basic for loop that calls the method enough times to move the car across the screen.  It's about as basic as you could get the code to be, which is why I suggested it.  I'd show you the for loop but I can't remember the exact Java for loop syntax off the top of my head and don't have a book handy.

missioncontrol

  • MC-Retro says Wot!
  • Trade Count: (+13)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 7855
  • Last login:November 06, 2024, 06:22:12 pm
Re: Java programmers look inside
« Reply #9 on: September 21, 2005, 12:27:35 pm »
Your learning Java

My intro to programming class is teaching html and php

ChadTower

  • Chief Kicker - Nobody's perfect, including me. Fantastic body.
  • Trade Count: (+12)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 38212
  • Last login:June 22, 2025, 04:57:38 pm
Re: Java programmers look inside
« Reply #10 on: September 21, 2005, 12:29:26 pm »

HTML isn't programming, it's a markup language.

You must be taking an intro to web programming class.

SirPoonga

  • Puck'em Up
  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Offline Offline
  • Posts: 8188
  • Last login:July 17, 2025, 11:04:07 pm
  • The Bears Still Suck!
Re: Java programmers look inside
« Reply #11 on: September 21, 2005, 12:33:46 pm »
Or a while loop and have the loop stop when the truck is off screen :)

For programming all you really need to know is
1) Data type the particular language support, most have integers, floats, strings, arrays, etc.., it's the oddball ones like langauges that have a hashtable data type
2) logic statements (expressions and if statements)
3) function calling, code redirection (like goto statements)
4) syntax

You can pretty much get a good start on anything with that knowledge.  All langauges (and scripting langauges) have those basics.  Most will have some sort of looping, be it for and/or while loops.  I know one scripting langauge tha doesn't have a looping syntax and you have to create a loop manual with ifs and goto statements.

The thing is programmers know this, but HR people don't.  So if you don't have much experience in a certain langauge but alot in another, even if the syntax is simular like Java and C#, they won't even think about you during the screening process.

Chad, Java syntax is same as c++ I believe
for(init; exit; increment){}

Such as
for( i=0; i<500; i++)
{
bed_1.slowMoveHorizontal(-1);
}

SirPoonga

  • Puck'em Up
  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Offline Offline
  • Posts: 8188
  • Last login:July 17, 2025, 11:04:07 pm
  • The Bears Still Suck!
Re: Java programmers look inside
« Reply #12 on: September 21, 2005, 12:34:02 pm »

HTML isn't programming, it's a markup language.

You must be taking an intro to web programming class.
But php is.
Technically scripting but it supports object orientation, looping, data types, etc..  It just doesn't get compiled so it's a script. 
« Last Edit: September 21, 2005, 12:35:44 pm by SirPoonga »

missioncontrol

  • MC-Retro says Wot!
  • Trade Count: (+13)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 7855
  • Last login:November 06, 2024, 06:22:12 pm
Re: Java programmers look inside
« Reply #13 on: September 21, 2005, 12:39:00 pm »

HTML isn't programming, it's a markup language.

You must be taking an intro to web programming class.

No it's introduction to programming before they were teaching java they just changed it before this semester.

My introduction to web design is basically teaching us how to use Dreamweaver.

ChadTower

  • Chief Kicker - Nobody's perfect, including me. Fantastic body.
  • Trade Count: (+12)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 38212
  • Last login:June 22, 2025, 04:57:38 pm
Re: Java programmers look inside
« Reply #14 on: September 21, 2005, 12:39:35 pm »
PHP is programming, yes.
« Last Edit: September 21, 2005, 12:44:44 pm by ChadTower »

missioncontrol

  • MC-Retro says Wot!
  • Trade Count: (+13)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 7855
  • Last login:November 06, 2024, 06:22:12 pm
Re: Java programmers look inside
« Reply #15 on: September 21, 2005, 12:48:46 pm »
Now, if someone could explain to me why I spit all that out, I would be grateful. :)

because you couldn't think of anything else to say

SirPoonga

  • Puck'em Up
  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Offline Offline
  • Posts: 8188
  • Last login:July 17, 2025, 11:04:07 pm
  • The Bears Still Suck!
Re: Java programmers look inside
« Reply #16 on: September 21, 2005, 01:44:00 pm »
What SP has given is the very basic things a person needs to know to write code, which is true.  To become a professional, though, if you don't understand the aforementioned concepts, you won't be able to turn out strong code and won't last all that long in the field.
Which was my point, that's all you need to know to be able to program.  Now to be able to program and to program good are two different things :)

But I didn't assume shmokes was going into a programming field, I figured he is just taking a lcass for whatever reason.  It could be a graphic design field.  For UW-Stout, when I was there) requires engineers and graphic designers to take at least the first computer science class (basic c++ programming) so they'd understand the concepts of ifs and looping.  As programs like Flash and AutoCAD use scripting langauges.


But yes, to be good at programming you need to understand the differences in langauges (why a particular langauge exists), interpreted vs compiled, sorting algorithms, recursion, complex data structures (like hastables in case the langauge doesn't have them built in), data storage, software lifecycle, code optimzation (hmmm, big o notation), how to use linkers, debuggers, and profilers, what the computer is actually doing with your code when it compiles, how the computer works in terms of system level and how it processes machine code (this I think is a biggie).

I definately think that last one is the most important for a good programmer.  If you know how a computer knows what to do with all those 1s and 0s you will be able to figure out problems quicker.

Quote
Also, if you don't get the mathematic concepts involved, you're going to be in trouble.  You may not be writing code to perform calculations, but if you don't understand the discrete mathematic concepts of set manipulation you won't be very good at managing data.  Data is king now, and every year professional coders are being hired to write code to crunch information rather than perform user functions.  This shift is only going to continue as massive databanks (think retail chains here) become bigger and bigger, detailing every habit you have.
And that is why I have a B.S. in applied math, concentration in software development, minor in computer science :)

ChadTower

  • Chief Kicker - Nobody's perfect, including me. Fantastic body.
  • Trade Count: (+12)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 38212
  • Last login:June 22, 2025, 04:57:38 pm
Re: Java programmers look inside
« Reply #17 on: September 21, 2005, 01:45:55 pm »

Hashtables?  Took me 5 minutes to figure that out.  I'm like okay WTF, I have no idea what a hastable is.

SirPoonga

  • Puck'em Up
  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Offline Offline
  • Posts: 8188
  • Last login:July 17, 2025, 11:04:07 pm
  • The Bears Still Suck!
Re: Java programmers look inside
« Reply #18 on: September 21, 2005, 02:01:21 pm »
Heh.  Hashtables rule.  A hashtable is just key/value pairs.  An array is basically an ordered hashtable where the key is a number.
Hash lists/tables are your basic list data types, most everything else is derived from that.   Though most people think arrays are the most basic because they are common and taught first.
Actually modern langauges have list datatypes that can be used as an array, hashtable, link list, enumerations, etc...
In .NET the Array class is an abstract of IList which is inherited from ICollection which is inherited from IEnumerable.  You look on msdn at all of those and you will find trees, hashtables, lists, arrays, etc.. is derived from one of those classes.

As long as you don't say you don't know what a tree or binary tree is.... which is a extention of a hash tree.


shmokes

  • Just think of all the suffering in this world that could have been avoided had I just been a little better informed. :)
  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 10397
  • Last login:September 24, 2016, 06:50:42 pm
  • Don't tread on me.
    • Jake Moses
Re: Java programmers look inside
« Reply #19 on: September 21, 2005, 02:02:45 pm »
I ain't gonna be a computer programmer.  I'll probably never take another computer programming class beyond this one and, for that reason, everything I learn in the class will soon be deleted from my caller id-like memory to make room for other stuff.  It's required for my degree, though.  C'est la vie.
Check out my website for in-depth reviews of children's books, games, and educational apps for the iPad:

Best Kid iPad Apps

shmokes

  • Just think of all the suffering in this world that could have been avoided had I just been a little better informed. :)
  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 10397
  • Last login:September 24, 2016, 06:50:42 pm
  • Don't tread on me.
    • Jake Moses
Re: Java programmers look inside
« Reply #20 on: September 21, 2005, 02:04:08 pm »
I get the impression that Chad's familiar with hashtables, but didn't immediately recognize hastable as a typo (so much for that Cambridge study).
Check out my website for in-depth reviews of children's books, games, and educational apps for the iPad:

Best Kid iPad Apps

ChadTower

  • Chief Kicker - Nobody's perfect, including me. Fantastic body.
  • Trade Count: (+12)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 38212
  • Last login:June 22, 2025, 04:57:38 pm
Re: Java programmers look inside
« Reply #21 on: September 21, 2005, 02:04:22 pm »
I know what a hash table is... I spent years as a PERL developer.

SirPoonga

  • Puck'em Up
  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Offline Offline
  • Posts: 8188
  • Last login:July 17, 2025, 11:04:07 pm
  • The Bears Still Suck!
Re: Java programmers look inside
« Reply #22 on: September 21, 2005, 02:05:26 pm »
Shmokes, what degree?

I take it you haven't learned about function parameters yet since most of what you posted could be greatly simplified :)

I know hash tables because my data structures class, but never really used it until I had to do some crypto stuff.

ChadTower

  • Chief Kicker - Nobody's perfect, including me. Fantastic body.
  • Trade Count: (+12)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 38212
  • Last login:June 22, 2025, 04:57:38 pm
Re: Java programmers look inside
« Reply #23 on: September 21, 2005, 02:07:29 pm »

PERL makes heavy use of hashes.  The way they implement hashes, you can pass data around your code as huge blocks.  You can implement command line parameter reading with 3 or 4 lines of code.  You can put up full OO code and then violate it like a cheap hooker. 

Grasshopper

  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2380
  • Last login:March 04, 2025, 07:13:36 pm
  • life, don't talk to me about life
Re: Java programmers look inside
« Reply #24 on: September 21, 2005, 02:07:46 pm »

For programming all you really need to know is
1) Data type the particular language support, most have integers, floats, strings, arrays, etc.., it's the oddball ones like langauges that have a hashtable data type
2) logic statements (expressions and if statements)
3) function calling, code redirection (like goto statements)
4) syntax


I think you're essentially right for all languages used in the real world. In fact computer programming hasn't really changed much since the 1960s. Algol was the last truly innovative language IMHO.

Even object orientated programming isn't really new. Some programs were written in an object orientated style way before languages such as C++ appeared. Languages like C++ made object orientated programming easier but also introduced a load of new jargon for things that people were already doing.

There is one exception - Prolog. This is like no other programming language I've come across. Fortunately it's really only used for research and therefore very few people outside of universities need to know about it.
"Patriotism is the last refuge of the scoundrel." - Samuel Johnson

ChadTower

  • Chief Kicker - Nobody's perfect, including me. Fantastic body.
  • Trade Count: (+12)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 38212
  • Last login:June 22, 2025, 04:57:38 pm
Re: Java programmers look inside
« Reply #25 on: September 21, 2005, 02:10:00 pm »
Even object orientated programming isn't really new. Some programs were written in an object orientated style way before languages such as C++ appeared. Languages like C++ made object orientated programming easier but also introduced a load of new jargon for things that people were already doing.

Yeah, but those languages - things like lisp and scheme - were mostly research based.  They were used for AI research and academic work.  OO programming didn't really hit commercial applications until C implemented it in a basic way and then C++ was put out as fully OO capable. 

shmokes

  • Just think of all the suffering in this world that could have been avoided had I just been a little better informed. :)
  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 10397
  • Last login:September 24, 2016, 06:50:42 pm
  • Don't tread on me.
    • Jake Moses
Re: Java programmers look inside
« Reply #26 on: September 21, 2005, 02:17:25 pm »
Shmokes, what degree?

I take it you haven't learned about function parameters yet since most of what you posted could be greatly simplified :)

I know hash tables because my data structures class, but never really used it until I had to do some crypto stuff.

Information Systems (read: Networking).  It's completely separate from a computer science degree.  I'm 99% sure this is the only programming class required for me.
Check out my website for in-depth reviews of children's books, games, and educational apps for the iPad:

Best Kid iPad Apps

Grasshopper

  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2380
  • Last login:March 04, 2025, 07:13:36 pm
  • life, don't talk to me about life
Re: Java programmers look inside
« Reply #27 on: September 21, 2005, 02:18:42 pm »
I wish C++ had been based on something other than C, maybe Pascal would have been better. There is definitely room to improve C but for me it was always the ultimate super efficient portable assembly language. OOP is a fairly high level concept that would have been better tacked onto another language.

"Patriotism is the last refuge of the scoundrel." - Samuel Johnson

SirPoonga

  • Puck'em Up
  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Offline Offline
  • Posts: 8188
  • Last login:July 17, 2025, 11:04:07 pm
  • The Bears Still Suck!
Re: Java programmers look inside
« Reply #28 on: September 21, 2005, 02:24:13 pm »
I wish C++ had been based on something other than C, maybe Pascal would have been better.
Dephi is to Pascal as C++ is to C basically.

Actually, full original name was Delphi Pascal.
« Last Edit: September 21, 2005, 02:28:30 pm by SirPoonga »

SirPoonga

  • Puck'em Up
  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Offline Offline
  • Posts: 8188
  • Last login:July 17, 2025, 11:04:07 pm
  • The Bears Still Suck!
Re: Java programmers look inside
« Reply #29 on: September 21, 2005, 02:25:59 pm »

PERL makes heavy use of hashes.  The way they implement hashes, you can pass data around your code as huge blocks.  You can implement command line parameter reading with 3 or 4 lines of code.  You can put up full OO code and then violate it like a cheap hooker. 
Doesn't that sum up everything perl in a nutshell.  Pretty much anything will interpret, may no do what you want, but will execute.

RayB

  • I'm not wearing pants! HA!
  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 11279
  • Last login:July 10, 2025, 01:33:58 am
  • There's my post
    • RayB.com
Re: Java programmers look inside
« Reply #30 on: September 21, 2005, 02:27:38 pm »
Sorry, I didn't know he was looking for a way to REPEAT what he already coded. (I thought he was advanced enough to know about loops).

What I described was a solution to what I thought the problem was: He said that each part of the vehicle was moving one at a time independantly. A double buffer would fix that by drawing the whole truck off-screen first, then displaying the end result only.

NO MORE!!

jbox

  • BYOAC Poet Laureate
  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1032
  • Last login:November 30, 2007, 08:00:54 am
Re: Java programmers look inside
« Reply #31 on: September 22, 2005, 03:45:28 am »
Bah, I scoff at these so called "high level languages". Real programmers can code in their BLOOD.

And if you don't know what a 'contract language' is, then you are probably doing real work so STOP SLACKING OFF and get back to work!  ;D

EDIT: Attaching the photo manually since it didn't seem to work inside the post.
« Last Edit: September 24, 2005, 02:28:54 am by jbox »
Done. SLATFATF.

ChadTower

  • Chief Kicker - Nobody's perfect, including me. Fantastic body.
  • Trade Count: (+12)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 38212
  • Last login:June 22, 2025, 04:57:38 pm
Re: Java programmers look inside
« Reply #32 on: September 22, 2005, 08:56:40 am »

Well, I've written good code in 6502 (nes), 6507 (2600), and 6809 (Vectrex) if that helps.

shmokes

  • Just think of all the suffering in this world that could have been avoided had I just been a little better informed. :)
  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 10397
  • Last login:September 24, 2016, 06:50:42 pm
  • Don't tread on me.
    • Jake Moses
Re: Java programmers look inside
« Reply #33 on: September 22, 2005, 08:58:56 pm »
When I put in what seems like a correct for loop my compiler gives me this error:

cannot find symbol - variable i

Do I need to define i somewhere?
Check out my website for in-depth reviews of children's books, games, and educational apps for the iPad:

Best Kid iPad Apps

ChadTower

  • Chief Kicker - Nobody's perfect, including me. Fantastic body.
  • Trade Count: (+12)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 38212
  • Last login:June 22, 2025, 04:57:38 pm
Re: Java programmers look inside
« Reply #34 on: September 22, 2005, 10:37:09 pm »
When I put in what seems like a correct for loop my compiler gives me this error:

cannot find symbol - variable i

Do I need to define i somewhere?

Yeah, you'd have to declare i in the declaration section of that method.  It's good practice to give the thing an initial value, too, so you don't have some random memory contents at first.  Something like:

Int i = 0;

shmokes

  • Just think of all the suffering in this world that could have been avoided had I just been a little better informed. :)
  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 10397
  • Last login:September 24, 2016, 06:50:42 pm
  • Don't tread on me.
    • Jake Moses
Re: Java programmers look inside
« Reply #35 on: September 22, 2005, 10:57:48 pm »
Okay...I'm at least getting a different compiler error now.  Here's my code:


public void drive()
    {
       if(hood_1 != null)   // only if it's painted already...
       
       int i=0;
       for( i=0; i>500; i++)
        {
            hood_1.slowMoveHorizontal(-1);
            hood_2.slowMoveHorizontal(-1);


Two questions.  1- Should that termination read:  i<-500 ?   Because it seems to me that if I keep adding -1, i will never be greater than 500 since it would start at 0 and move negatively.

2- Now I'm getting the compiler error:  '.class' expected and it highlights my int i=0

Sorry...I suspect that I'm getting ahead of myself and maybe in a few weeks that error message would make perfect sense to me.  But at least I'm going to understand the stuff really well when we do get to it as a class.
Check out my website for in-depth reviews of children's books, games, and educational apps for the iPad:

Best Kid iPad Apps

shmokes

  • Just think of all the suffering in this world that could have been avoided had I just been a little better informed. :)
  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 10397
  • Last login:September 24, 2016, 06:50:42 pm
  • Don't tread on me.
    • Jake Moses
Re: Java programmers look inside
« Reply #36 on: September 22, 2005, 11:29:28 pm »
error
Check out my website for in-depth reviews of children's books, games, and educational apps for the iPad:

Best Kid iPad Apps

SirPoonga

  • Puck'em Up
  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Offline Offline
  • Posts: 8188
  • Last login:July 17, 2025, 11:04:07 pm
  • The Bears Still Suck!
Re: Java programmers look inside
« Reply #37 on: September 22, 2005, 11:33:29 pm »
Errr, the int 1 is my fault, he copy and pasted what I wrote in chat :)

the .class error was happening on the int1=0; line, had him put the int declaration in the for loop to see where the error would move to.

Does white space make a difference in java?  Maybe with that BlueJ compiler.  Because he said he got it to work after I suggested changing some formatting to make it more readable to me :)  It works now.
« Last Edit: September 22, 2005, 11:43:50 pm by SirPoonga »

shmokes

  • Just think of all the suffering in this world that could have been avoided had I just been a little better informed. :)
  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 10397
  • Last login:September 24, 2016, 06:50:42 pm
  • Don't tread on me.
    • Jake Moses
Re: Java programmers look inside
« Reply #38 on: September 23, 2005, 12:34:45 am »
yeah...thanks SirPoonga and Chad.  It's working now. 

The int 1 just happened to be on there when I made that screenshot, but the screenshot was showing him the error I was getting and it definitely was not from the int 1.  I had only happened to put that in there just before taking the screenshot.

But I had been copying and pasting and deleting and writing new code so much that I had messed up the indents so they didn't look right, as you can tell by looking at the screenshot.  SirPoonga wondered aloud, so to speak, why my indents were funny and I told him that it was from me (figuratively) banging my head against the keyboard to get the code to work.  Anyway, I went back and fixed the indents and the bastard compiled.

Of course, it could be coincidence and maybe I actually unknowingly fixed some syntax error at the same time, but....
Check out my website for in-depth reviews of children's books, games, and educational apps for the iPad:

Best Kid iPad Apps

ChadTower

  • Chief Kicker - Nobody's perfect, including me. Fantastic body.
  • Trade Count: (+12)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 38212
  • Last login:June 22, 2025, 04:57:38 pm
Re: Java programmers look inside
« Reply #39 on: September 23, 2005, 08:37:36 am »

Whitespace does not matter in java.  That is what end of command markers (;) and controls are for.  There are actually very few languages in modern use that care about whitespace.