Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Can you be a bit more specific, please? A few things we'd need to know include:

  • The version of Python you're using, and the platform it is running on.
  • Your goal - is this to test the program, or spoof it in some way? Did you want this to be in the same program, or between two different programs?
  • Is this a console program, or a GUI program? If a console program, do you need to have 'raw' input, or is standard, buffered input enough? If for a GUI program, what toolkit are you using?
  • What kind of input do you need to simulate? Text, mouse button-downs, mouse movements?

I might add that chances are, you don't actually need to fake the user input; usually when that kind of thing comes up, it's a sign that your coupling the input to tightly with the computation. What I mean by this is, it is usually better to separate the parts of the program that actually work on the data from the parts that read in and print out the data. By decomposing the program this way, you usually get a more robust program, and one that is easier to test and maintain as well.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

In the future, when getting this kind of error, please post the traceback and error message as well as he code where it is occurring. I was able to work out the problem this time, but the traceback makes it much easier to figure out the problem once you learn how to read it.

Also, always mention the version of Python you are using; Python 3.x, which is what you seem to be working in, is very different from the older Python 2.x regarding several things, including basic console I/O.

The specific error you are getting is on line 22:

    numPumpkins = input("Enter the number of pumpkins: ")

You are reading in the user input as a string, but - unlike in the code below it on line 29 - you don't convert it to an integer. You need to write it as:

    numPumpkins = int(input("Enter the number of pumpkins: "))

Note that even this isn't foolproof; if the user makes a typing mistake or deliberately enters a value other than an integer, an exception will get raised. To do this properly, you really should wrap the line in a while: loop, and then in a try:...except: block.

    numPumpkins = 0
    while numPumpkins == 0:
        # get the input value separately so you can include it in any error msgs you print out
        numString = input("Enter the number of pumpkins: ") 
        try:
            numPumpkins = int(numString)
        except ValueError:
            print("{0} is not an integer. …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

To understand classes, you need to know both the conceptual meaning and their concrete implementation. Abstractly, a class is a description of a type, for example, the class Animal would describe the properties which all animals have. The class acts as a template for creating objects of it's type. A class describes both the state of a given Animal, and the behaviors it is capable of.

A class may have sub-classes; for example, Animal might have the subcategory Carnivore, which in turn might have the subclasses Canine and Feline, and so on down to the particular types of animals such as Lion or Cat. It is possible for a class to be a sub-class of more than one immediate parent class; for example, a Cat is both a Feline (and hence a Carnivore, and hence an Animal), and a Pet (which is a subclass of DomesticatedAnimal, which is a subclass of Animal). Each subclass inherits the properties and behaviors of it's parent classes.

As I said, a class consists of a set of properties (called instance variables) and behaviors (called methods). These properties may in turn be members of a class. For example, a Cat has teeth, claws, and fur. Now, it is important to differentiate here between the type of something and it's properties. A Cat is a Feline (inheritance), for example, but while a Cat has claws (composition), a Cat isn't a type of claw. This may seem obvious, but it can be surprisingly difficult to get this …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I see. No, PyDev is quite different from either PyScripter or PyCharm in this respect.

If you want to compare how the different environments suit you, you'll need to download Eclipse first, and copy the files in the archive to some suitable location - e.g., c:\Eclipse or possibly c:\Program Files\Eclipse - and run eclipse.exe to configure it, then close Eclipse and copy the files for PyDev into the plugins and features folders in the Eclipse folder. Then, you'll want to run eclipse.exe again (or put a shortcut to it onto you desktop and run that) and configure the Python settings.

That having been said, I would add that a lot of developers swear by Eclipse, for several different languages. It's all in your personal preferences, really. Myself, I like Eric quite a lot, but it is a bit of a pain to set up.

BTW, did you buy PyCharm, or are you using the 30-day trial? It's moderately expensive (unless you manage to finagle the free Open-Source Project version) especially if you aren't sure if you like it. I would definitely try a few others before dropping $100 on an IDE. While many do say it is the best IDE for Python, it is, as I said earlier, a personal matter that is hard to generalize about.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The keyword def is used to define functions (and methods, when you start studying classes and objects). It essentially allows you to give a name to a piece of code, so that you can use it over and over. For example, this is a one line function, followed by a for: loop that calls it five times:

def star():
   print '*',

for i in range(5):
    star()

Functions are also used to break the program up into easy to understand pieces. You can pass information to a function by passing it arguments, and the function can return a result. For example, this function calculates the area of a cube:

def cubeArea(size):
    return (size ** 2) * 6   # the area of each side, times the number of sides 

area = cubeArea(4)           # area should now equal 96

The import keyword is used to get functions and constants from other files of source code, called modules. Python includes a large library of modules which you can import, and you can import from a module you've written yourself into another module.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Well, to begin with, do you have Eclipse installed and running? Pydev is an add-on for Eclipse; it doesn't do anything by itself.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Just to clarify: the code posted is the mapmaker.py file, while the data is the contents of samos.txt, correct?

It seems to me that the first part of the problem is to figure out how to parse the data. Fortunately, the format seems fairly simple: each item starts with a terrain type, and a (I think) the number of coordinates, followed by a series of x, y coordinates, and separated by empty lines. You should be able to collect the data fairly easily given this.

If you know how to make a class, then I would make one to represent the figures to be drawn, and store the data in your Figure objects. Otherwise, you could use a list consisting of the terrain type, the size, and tuples representing the coordinate pairs.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

You may want to edit the code a bit; the indentation is off.

I was able to reproduce the results described, but without knowing what it means, or what it was supposed to come out with, I can't tell you why it isn't giving the desired results.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Actually, the error message is exactly correct - you invoked a class method (info(), which as written does not take a self argument) with the name of an instance, which in Python is the same as passing it an argument (namely,help_ itself). Just to make it clearer what is happening, you need to know that these two forms are equivalent:

help_.info()

and

Help.info(help_)

You should either invoke it with the name of the class, and no arguments, instead

Help.info()

or else add a self argument to the method parameters.

As an aside, I would like to point out that there is a standard module metadata variable named __author__ which you usually would use for this purpose:

__author__ = 'Jerome Smith'

This automagically gets included in the docstring for the module, if you use the standard help() built-in function. For more flavor, see PEP-258 for details on docstrings and the help() function, and this thread on StackOverflow about the Pydoc metadata variables.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The generator expression says, return a list of characters for every alphabetical character in string. The .join() method (applied to an empty string, and taking the generated list as it's argument) then fuses the list elements into a new string, with no separator character between them. The practical upshot of it is to filter out any character in string that isn't a letter.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

In retrospect, I would have used sample() had I thought of it. I was thinking mainly in terms of reorganizing the entire 'deck' of questions, but your solution makes more sense.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Yes, but sample() returns a list of samples out of the tuple; it doesn't modify the tuple itself, the way shuffle() does. When I ran shuffle on a tuple, I got the following traceback:

>>> random.shuffle((1, 2, 3, 4))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\random.py", line 288, in shuffle
    x[i], x[j] = x[j], x[i]
TypeError: 'tuple' object does not support item assignment

I have to admit that sample() is in some ways a better solution, as you can use it to limit the size of the questions list, obviating the need for the enumerate(). I wish I'd thought of using it myself.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

When you say that import random failed, just what do you mean? If you got an error message, post it with the full traceback. Otherwise, did it simply not do what you expected it to?

I would recommend using the random.shuffle() function on the series of questions; however, to do that, you'll need to make a small change, which is to make the outer tuple holding the question-answer pairs into a list.

questions = [("Denis Glover wrote the poem The Magpies ", 'yes'),
    ("God Save the King was New Zealand’s national anthem up to and including during WWII ", 'yes'),
    # several lines omitted for clarity...
    ("The Treaty of Waitangi was signed in 1901 ", 'no'),
    ("Aotearoa commonly means Land of the Long White Cloud ", 'yes')]

random.shuffle(questions)    # automagically rearrange the questions in a random order

Note that all I did was change one pair of parentheses to a pair of square brackets, and add the call to random.shuffle(). The reason for changing questions from a tuple to a list is simply that tuples are immutable: once they are created, they cannot be altered. You can reassign a different value to the variable, but you can't change the tuple itself. Lists, on the other hand, are mutable, so the shuffle() function can work on them.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Sounds rather open-ended, don't you think? Has the professor given you any further instructions or suggestions on how to do this? Or is that what you came here to ask for?

For future reference, you should never simply post your project requirements here and expect someone to do the work for you. We are, as they used to say in the Sixties, hip to that sh****, and we aren't going to let it slide unanswered. You need to demonstrate that you have made a good faith effort to solve the problem before posting here, or else you are in violation of the posting rules of DaniWeb:

Do provide evidence of having done some work yourself if posting questions from school or work assignments.

So, can you give us some idea of what help you need?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

OK, let's start from the top:

  • Do you know how to declare a class?
  • Do you know how to write the constructor for a class? (Hint: in Python, the c'tor has to have a special name.)
  • How would you write a non-c'tor method? What is the first argument in a method in Python?
  • Given a class, do you know how to create an object?
  • How do you invoke a method of an object?
  • How would you calculate the surface area of a cube, if you had to do it by hand (hint: the surface of a cube consists of six squares)? How would you calculate it's volume (hint: they call raising a number to the 3rd power 'cubing' for a reason)?

Try to answer those questions, and apply the answers to the problem. If you don't know them, ask.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

OK, can you post what you have so far?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Adding a score is fairly easy; all you need to do is have a variable score which is set to zero to start, then for every right answer, add one to it.

# make input equal to Python3 style input even in Python2
try:
    input = raw_input
except:
    pass


print("Welcome to my yes or no quiz!")
questions = (("Denis Glover wrote the poem The Magpies ", 'yes'),
             ("God Save the King was New Zealand’s national anthem up to and including during WWII  ", 'yes'),
             ("Kiri Te Kanawa is a Wellington-born opera singer  ", 'no'),
             ("Phar Lap was a New Zealand born horse who won the Melbourne Cup  ", 'yes'),
             ("Queen Victoria was the reigning monarch of England at the time of the Treaty  ", 'yes'),
             ("Split Enz are a well-known rock group from Australia who became very famous in New Zealand during the 80s  ", 'no'),
             ("Te Rauparaha is credited with intellectual property rights of Kamate!  ", 'yes'),
             ("The All Blacks are New Zealands top rugby team ", 'yes'),
             ("The Treaty of Waitangi was signed at Parliament  ", 'no'),
             ("The Treaty of Waitangi was signed in 1901 ", 'no'),
             ("Aotearoa commonly means Land of the Long White Cloud   ", 'yes'))

score = 0
maxQuestions = 0
while maxQuestions <= 0 or maxQuestions > len(questions):
    try:
        maxQuestions = int(input("Enter the number of questions to ask (more than 0 and less than to {0}): ".format(len(questions))))
    except ValueError:
        print("Please enter an integer value.")
        maxQuestions = 0

for count, (q, right) in enumerate(questions): …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I would try asking the user for the number of questions to ask before the for: loop, and use enumerate() to get a count of how many questions have been asked. Then, add an if: clause that checks whether you have reached the number of questions, and break if you have.

The enumerate() is a bit tricky, so I'll give that part to you:

for count, (q, right) in enumerate(questions):

The reason for this is because enumerate() returns a tuple containing the enumerated value, and the next value in the argument. Since the next value in questions is itself a tuple, you need the parens around the two variables to force it to unpack the inner tuple.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Can you please post the code you have so far, and describe any problems you're having with it?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Request For More Information Here

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Yes, please post your existing code for us, otherwise we won't know how to adivse you.

revelator commented: thanks, please do this help for me :) +1
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

In order to get the desired effect for the method getWord(), you will need to make three changes. First, you'll need to track the centerpoint of the circle; a simple list pair would do nicely:

self.center = [200, 200]  # initialize to the original center of the canvas

Then you need to alter moveCircle() so that the changes in the centerpoint are tracked as the circle moves:

    def moveCircle(self, event):
        """move circle up, down, left or right when user clicks an arrow key"""
        x=0
        y=0
        if event.keysym == "Up":
            y = -5
        elif event.keysym == "Down":
            y = 5
        elif event.keysym == "Left":
            x = -5
        else:
            x = 5

        self.canvas.move("circle", x, y)
        self.canvas.move("text", x, y)
        self.center[0] += x
        self.center[1] += y
        self.canvas.update()

Finally, you'll need to change the conditional of in getWords() to calculate the distance between the the current centerpoint and the mouse-down location, and compare it to the radius of the circle:

    def getWords(self, event):
        color = self.getRandomColor()
        self.canvas.delete("text")

        distance = math.sqrt((self.center[0] - event.x) ** 2 + (self.center[1] - event.y) ** 2)
        place = ''

        if distance <= self.radius:
            place = 'inside'
        else:
            place = 'outside'

        self.canvas.create_text(self.center[0],  self.center[1],
                                    text = "Mouse pointer is %s the circle" % place,
                                    fill = color, tag = "text")

This should do the job nicely. Note that I used another instance variable, self.radius, rather than hard-coding the 50 in; this would allow you to change the size of the circle dynamically, later on, and …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I assume here that the x and y coordinates refer to a particular point in the shape, such as the centerpoint, or the top left.

If I have x,y in Shape, I do not need x,y to exist in Square right?
Correct, they will be inherited by the child classes. You might consider declaring them protected rather than private, however, as it would make them visible within the child classes; you wouldn't need to use the setter/getter methods as much.

You might also want to make Shape and abstract class; you wouldn't want anyone trying to declare a Shape object directly, only as a member of one of the sub-classes.

Is there any good methods to store my x and y datas?
Well, you could collect them into a Point structure or class, I suppose. Right now, you are storing them in the class just fine, I think, though a Point class would make it a bit more explicit and regular.

For now, it is working fine when I did not use any virtual functions.
Previously I did use virtual functions.

Odd. What nethods did you have as virtual, and how did they fail? Could you post more of your code, please?

I had two arrays.

Shape *arrayShapes[100];
Shape *dataCoords[100][12];

I am using two arrays because I felt that this way I can store the data of the coords better, when I am trying to extract data out.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Certainly you can nest lists inside another list, and you wouldn't necessarily need another method to do it. If you already have the list to insert, the it is as easy as

>>> alist = [1,2,3]
>>> blist = [4,5,6]
>>> clist = []
>>> clist.append(alist)
>>> clist.append(blist)
>>> clist
[[1, 2, 3], [4, 5, 6]]
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

A few questions:
Are BufferPixels, Bpp, height, and width instance variables? They aren't declared or passed anywhere in the method as shown.

Why couldn't unsigned char* Pixels = &BufferPixels[0]; be written as unsigned char* Pixels = BufferPixels;?

What does Bpp represent? Pixel depth (bits per pixel)? If so, shouldn't the pixels be a 32-bit unsigned, rather than an 8-bit unsigned (even if only 24 bits are actually used at times)? Or is this the reason why you have unrolled the loop by three (or four, in cases where Bpp is greater than 24)?

Why is Result a void pointer?

Do the pixels have to be aligned on word or doubleword boundaries in order to be rendered correctly? Is byte order significant?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The only processor architecture I know of which has a register file that large is the UltraSPARC, which has (IIRC) 128 64-bit registers (divided into 8 overlapping register windows of 32 registers each).

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

OK, I went and wrote a full test program for the sorting and swapping functions, and found another bug in it, which I've since fixed. Here's the final test program:

#include <stdio.h>

struct pair
{
    int master, slave;
} arr[5];


struct pair* sort(struct pair a[], int n);
void swap(struct pair x[], int i, int j);

int main()
{
    int i;

    arr[0].master = 5;
    arr[0].slave = 20;

    arr[1].master = 2;
    arr[1].slave = 30;

    arr[2].master = 4;
    arr[2].slave = 60;

    arr[3].master = 9;
    arr[3].slave = 10;

    arr[4].master = 1;
    arr[4].slave = 90;

    printf("original array: ");
    for (i = 0; i < 5; i++)
    {
        printf("{%d, %d}", arr[i].master, arr[i].slave);
        if (i < 4)
        {
            printf(", ");
        }
    }


    sort(arr, 5);

    printf("\n\nSorted Array: ");
    for (i = 0; i < 5; i++)
    {
        printf("{%d, %d}", arr[i].master, arr[i].slave);
        if (i < 4)
        {
            printf(", ");
        }
    }
    puts("");

    return 0;
}



struct pair* sort(struct pair a[], int n)
{
    int i, j;

    for(i = 0; i< n-1; i++)
    {
        for(j = i+1; j<n; j++)
        {
            if (a[i].master > a[j].master)
            {
                swap(a, i, j);
            }
        }
    }
    return a;
}

void swap(struct pair x[], int i, int j)
{
    struct pair temp;

    temp.master = x[i].master;
    temp.slave  = x[i].slave;

    x[i].master = x[j].master;
    x[i].master = x[j].master;

    x[j].master = temp.master;
    x[j].slave  = temp.slave;
}

This version of the swap() function should work correctly.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

No. Turbo C (at least the version most people here seem to talk about) is a 16-bit DOS compiler, and cannot create Windows DLL files.

Frankly, you would do well to drop both Turbo C and Visual Basic 6.0 and get modern compilers for both languages (OK, so VB.Net is very different from VB 6.0, but were talking about a 15 year old compiler).

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

sigh I also dropped the word struct in the declaration of temp. That line should read:

struct pair temp;
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I was wondering why you weren't using the Time class out of the datetime module. It correctly handles a lot of what you are doing manually right now.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Oops, I dropped the void type on the function. Sorry about that.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

1-Q1. It would be easiest to give an example, rather than explain it. Let's say you have the files
foo.h

int foo(int x);
int bar(char* str);

foo.cpp

#include "foo.h"
#define QUUX 23

int foo(int x)
{
   return x * QUUX;
}

Then when the pre-processor has gone over it, the source would be:

int foo(int x);
int bar(char* str);

int foo(int x)
{
   return x * 23;
}

1-Q2. It depends on the compiler suite in question. Traditionally, the pre-processor was a separate program called cpp, and in most Unices this is still the case. Most Windows compilers, however, combine the preprocessor and the compiler into a single program.

3-Q1. Mostly out of simplicity; the assembler already exists, so it makes sense to use it rather than duplicate the code needed to generate an object file. Note that, once again, some compilers don't use a separate assembler, but instead generate the executable directly.

3-Q2 For compilers that work that way, yes.

3-Q3 Yes, though the word 'force' is a bit inaccurate.

4-Q1 Again, it depends on the compiler tool suite. Usually, it is a separate program; in Unix (and Linux), it is called ld and can be used separately from the compiler and assembler entirely.

4-Q2. What the linker does is take a copy of the object code from the object file and the library files, and copies it to the new executable file, making the necessary changes to resolve certain things which …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

There are several unit testing frameworks for each of those languages; an extensive (but not complete) list of them can be found here.

Of the ones for Java, far and away the best known is JUnit. It is derived from the original Smalltalk SUnit testing library, and strongly influenced several others including NUnit (for C#) and the Python unittest library (formerly PyUnit, now part of the language library proper).

There are plenty of tutorials for unit testing around, you just have to know which framework you want to use.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Actually, my own approach to this would be to bundle the pairs into a struct:

struct pair
{
    int master, slave;
} arr[5];

Then sort them based on the value of the master element:

struct pair* sort(struct pair a[])
{
    int i, j;

    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if (a[i].master > a[j].master)
            {
                swap(a, i, j);
            }
        }
    }
    return a;
}

swap(struct pair x[], int i, int j)
{
    pair temp;

    temp.master = x[i].master;
    temp.slave  = x[i].slave;

    x[i].master = x[j].master;
    x[i].master = x[j].master;

    x[j].master = temp.master;
    x[j].slave  = temp.slave;
}

All this assumes you're familiar with structures already.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Actually, no. There are definite limits to computability. Look up Alan Turing and the Halting Problem for one well-known example of an undecidable proposition.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

If you need to sort two different arrays, then you need to test both of the arrays separately. It would make far more sense (in general, and in this specific case) to re-write the sorting algorithm as a function, which could then be passed the array to sort. Here is your code re-done in this manner (with minor corrections):

int* sort(int a[])
{
    int i, j;

    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if (a[i]>a[j])
            {
            swap(a[i],a[j]);
            }
        }
    }
    return a;
}

This also allows you to test the sorting algorithm with known test data, before trying to work on user input.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Sorry, looking at it now I see that I wasn't clear. The code for updating the values (incrementing them on each millisecond, second and minute, as appropriate) should be in the timer.actionPerformed() handler; only the code to reset all the values back to zero should be in reset.MouseClicked(). I hope that makes more sense now.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

In the future, please use the 'code' menu button at the top of the editing window to paste in code samples. By default, the forum software does not retain indentation, which makes reading Python code especially difficult.

As it happens, the causes of the problem are plain to see. First off, you omitted the double-underscores around the __init__() method, which means that it is just an ordinary method of that name, not the constructor as you intended. This is a common enough error, so don't feel too put out about it. The second issue is that you are reading the integer values in using input() function; in Python 2.x, this would work (though it is dangerous because it evaluates the input as a Python statement), but in Python 3.x, the input() function only reads in strings. You will need to convert the strings to integers before passing them to the c'tor. Finally, the values you are passing to the c'tor are the same as the default values; you will want to use the values you've just read in instead. Thus, the code ought to look something like this:

class Rectangle(object):
    """A 2D Rectangle"""

    def __init__(self, width = 1, height = 2):
        self.width = width
        self.height = height

    def Perimeter(self):
        "Return the Perimeter of the rectangle"
        return (2 * self.width) + (2 * self.height)

    def Area(self):
        "Return the area of the rectangle"
        return self.width * self.height

print("Enter your values")

width = 0
height = 0

# read in the input …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

While I share stultuske's misgivings about external links, I went ahead and looked anyway - foolish, perhaps. Anyway, I noticed something that would not be evident if you had simply posted the code here, so you are fortunate that I did.

What I noticed is the compiler output that follows the code for Assignment3Form. Despite what you said earlier, it is clear that the code does not compile correctly - it depends on two more classes, Pilot and FlightSchedule, which you haven't written yet, and it does not find the two classes you have written in any case, probably because you haven't put them into a single file with the same name as the package, assignment3. For that matter, it complains that the filename does not match the name of the public class, something that is absolutely required in Java. So, it is safe to say that the program is not yet in a workable state.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Ah, this does clarify things somewhat. OK, then.

I think you'll want to fix calcdist() first; divorce it from the data stream as it is and have it take two three-tuples as it's argument:

def (a, b):
    return sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2 + (a[2]-z[2])**2)

Better still might be to write a Point3D class to represent your data, though that may be a bit heavyweight. On second thought, it would porbably save you a lot of trouble:

from math import sqrt

from sys import maxsize

class Point3D(object):
    """ Representation of a point in three dimensions."""

    def __init__(self,  *args):
        """ C'tor for the Point3D class. Can accept either a tuple, a list, or a set of three separate arguments as it's initialization. """
        if len(args) == 1 and (isinstance(args, tuple) or isinstance(args,  list)):
            self.x,  self.y,  self.z = args[0]
        elif len(args) == 3:
            self.x,  self.y,  self.z = args
        else:
            raise TypeError 

    def __str__(self):
        """ String representation of a Point3D. """
        return "<{0}, {1}, {2}>".format(self.x,  self.y,  self.z)

    def __repr__(self):
        """ Extended representation of the Point3D objects - the same as the string representation."""
        return str(self)

    def __eq__(self,  other):
        """ Test for equality between two Point3D objects."""
        return ((self.x == other.x) and (self.y == other.y) and (self.z == other.z))

    def __ne__(self,  other):
        """ Test for inequality between two Point3D objects."""
        return not self == other    

    def distance(self,  other):
        """ Computes the distance between two Point3D points."""
        return sqrt((self.x - other.x) ** 2 + (self.y - other.y) ** 2 + (self.z - other.z) ** …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

While it is certainl;y more an intermediate to advanced level project, you might consider going through the Scheme from Scratch process. It not only is a nicely incremental project, meaning that at no one point should you get overwhelmed by it, but it also exposes you to a radically different language which you can compare to C (which always gives some degree of enlightenment).

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

OK, I can see your getting flustered, so let's back away from the code for a bit and consider the overall problem you are trying to solve. Just what is the program supposed to compute, and how would you do it by hand if you had to? I don't mean you should actually go through it manually, just sketch out the process for us.

Also, I would recommend removing any import statements that aren't strictly needed. They simply clutter up both the code and the namespace.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I forgot something earlier: you need to add some code at the end of the program to ensure that the program exits correctly when the window is closed. This code I'll just give to you:

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                timer.stop();
            }
        });

Otherwise, the Java VM may hang on you.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The first thing to do is get rid of the existing code in the start.mouseClicked() event handler. Those loops aren't working; you need something that will run each time the Timer event fires. From here on in, all that start.mouseClicked() will do is start the Timer, and all stop.mouseClicked() will do is stop it. The code for resetting the values of msec, sec, and min, and the text of msecs, secs, and mins, will now go in the reset.mouseClicked() event handler.

Next, you need to move the msec, sec, and min integers out to the class level as static variables, while at the same time eliminating the variable flag (you won't need it any more). This allows you to have them changed by the various event listeners.

Next, you will need to declare a Timer, and define an ActionListener for it with a suitable actionPerformed() method. This I'll leave to you, but I want to remind you: don't loop inside the event handler. It will automagically get re-run every tim the Timer event fires. Write your code with that in mind.

As a last piece of advice, replace frame.show(); with frame.setVisible(true);, as show() is deprecated. Just a minor thing to fix.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

As a matter of kindness to you (and anyone else reading this), I'll post the existing code properly indented; however, no one here is going to fix the problem for you. We will give advice, but not free homework answers. In any case, the answer was already given to you above - use javax.swing.Timer, which will run without blocking the overall thread. See this tutorial for more details on how to use it.

As for the urgency of the problem... well, keep in mind that it isn't urgent to us, and that we are here mostly to help you learn, not to help you finish your homework. See this essay for further Illumination fnord.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import sun.audio.*;
class Stop_Clock {
    static boolean flag=true;
    public static void main(String argsp[]) {
        JFrame frame=new JFrame("Stop Clock");
        frame.setResizable(false);
        JLabel lbl=new JLabel(new ImageIcon("Stop CLock.png"));
        frame.setIconImage(new ImageIcon("078474-blue-jelly-icon-business-clock8.png").getImage());
        lbl.setLayout(null);
        final JLabel mins=new JLabel(" 00");
        mins.setFont(new Font("Impact", Font.BOLD, 45));
        mins.setBounds(125, 80, 75, 44);
        final JLabel secs=new JLabel(" 00");
        secs.setFont(new Font("Impact", Font.BOLD, 45));
        secs.setBounds(244,80, 75, 44);
        final JLabel msecs=new JLabel(" 000");
        msecs.setFont(new Font("Impact", Font.BOLD, 45));
        msecs.setBounds(355, 80, 95, 44);
        lbl.add(msecs);
        lbl.add(secs);
        lbl.add(mins);
        final JLabel start=new JLabel();
        start.setBounds(11,173,181,57);
        lbl.add(start);
        start.addMouseListener(new MouseAdapter() {
            public void mouseEntered(MouseEvent e) {
                start.setIcon(new ImageIcon("start-changed.png"));
            }
            public void mouseExited(MouseEvent e) {
                start.setIcon(new ImageIcon("start.png"));
            }
            public void mouseClicked(MouseEvent e) {
                flag=true;
                int sec=1, msec=1, min=1;
                while(flag==true) {
                    sec=1;
                    while(sec<=60&&flag==true) {
                        msec=1;
                        while(msec<=1000&&flag==true) {
                            try {
                                Thread.sleep(1);
                            }
                            catch(InterruptedException error) {}
                            String str=String.format(" %03d",msec);
                            if(msec==1000) msecs.setText(" 000");
                            else …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

OK, aside for the fact that the function header should be int main() and not just main(), what is the problem you are having?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Aside from the fact that you are asking us to do your assignment for you (as it is a rather simple one, really), you haven't given enough information to solve it, as it depends on the contents of the memory at address 2000:0004 (technically, it also depends on the specific assembler as well, as not all x86 assemblers use quite the same syntax for memory access; in this case, I'm guessing either MASM or NASM, which are similar enough in this regard to count as the same, IIRC).

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

It is pretty clear that you got this code from the TKInter tutorial and made the simple modification of trying to substitute a Button with an Entry box. Fair enough; that sort of thing is part of learning any new API. In this case, it didn't work out. It happens.

The issue is fairly simple: the Entry class constructor doesn't have an option called 'command'. This stands to reason, as you don't use an Entry box the same way you do a Button.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

First off, are you using a system Date (java.util.Date) or a database Date (java.sql.Date)? I am assuming the former, but if you are working with a SQL database, you may be talking about the latter.

Either way, you will want to use one of the Calendar classes, probably GregorianCalendar. The Calendar classes all support a method called .add() which will do the job you want.

However, when adding or subtracting time from a Calendar object, you need to tell it what incement of time to add - an hour, a day, a year, a month, whichever. so what you would have is something along these lines:

Calendar cal = new GregorianCalendar();   // default is current time and default zone
cal.add(Calendar.DATE, 5);

Note that I haven't addressed the question of time zone, which you may neecd to do.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

@Deceptikon: While your suggestions are well thought out, they really don't apply to the MIPS architecture, which works significantly differently from the x86 architecture, especially with regards to using the stack. Among other things, the standard word size is either 32 or 64 bits, depending on the model of the processor, not 16, and all memory access has to be word aligned. Also, it is a (mostly) pure load/store RISC architecure, so direct memory accesses are minimal; OTOH, there are 32 general registers (some of which are used for conventional purposes, such as the stack pointer, but which can in principle be used for anything any other register can be used for).

In MIPS, function calls are usually made using jal (jump and link, which jumps to the location of the function and copies the return value into $ra, the return address register). Arguments are passed using the $a0 through $a3 registers; if there are more than four arguments, you have to pass them on the stack.

The usual stack frame protocol for MIPS is to first decrement $sp by the amount that you need for the entire stack frame. You then save the frame pointer, $fp, from a zero offset with the new value of $sp as the base. You then add $sp by the amount needed for saving the local variables (that is, whichever of the $s0 through $s7 registers are used) save that to $fp, then use $fp as the base from which to save the the …