Alex Edwards 321 Posting Shark

I want to split these two different lines up into words so then I can compare them. To see which is in one and not in the other. Should I be splitting them up and putting them into vectors or arrays? I dont think if if just split them into tokens that will work, or will it?

Split the lines up into words and place the words for a corresponding line into a vector.

For example, vector<string> a has elements "I", "believe", "in", "you" and vector<string> b has elements "You", "believe", "in", "you".

If you use a == b it will return false because the first element in a isn't equal to the first element in b.

The way the values are compared are defined in the vector's equal operator which is explained here
and more thoroughly explained in this link.

Edit: I do not know if the vector class handles the exception between unequally lengthed vectors, but in the event that you obtain a set of words that are more or less than the vector to be compared against, you should handle the possibility if the operator implementation in vector does not.

Alex Edwards 321 Posting Shark

push_back does NOT separate the line into words. That's a separate problem. There's more than one way of doing that and I don't know whether this is for a school assignment or not, or what you've been exposed to. As far as splitting the string into words, you may use the find and substr functions from the string library.

http://www.cplusplus.com/reference/string/string/

Take a look at the functions from cctype too. They could be very useful.

http://www.cplusplus.com/reference/clibrary/cctype/

Oddly enough I was working away at a tokenizer. I think that my snippet might be helpful, but maybe not if this is an assignment.

If it is an assignment, and you absolutely feel the need to split the line of characters (the string) into separate words, refer to this C-style method here

VernonDozier commented: Haven't tried your snippet yet, but will. strtok is a good link. +7
Alex Edwards 321 Posting Shark

Here's yet another example, though probably overkill--

import java.util.concurrent.*;
import java.net.*;

public class ConcurrentExample{

	public final ExecutorService es;
	private Future currentFuture = null;

	public ConcurrentExample(){
		es = Executors.newFixedThreadPool(1);
	}

	public static void main(String... args){

		ConcurrentExample ce = new ConcurrentExample();

		ce.optionSelected("http://www.google.com"); // invokes the run method - main process takes 5 seconds
		ConcurrentExample.advance(4, false); // silently wait 4 seconds before performing new task
		ce.optionSelected("http://www.yahoo.com"); // this request should fail since current request is still occurring
		ConcurrentExample.advance(6, false); // silently wait 6 seconds before performing new task
		ce.optionSelected("http://www.msn.com"); // this request should succeed since the previous task should have finished
		ce.es.shutdownNow(); // shut down processes so the JVM can exit naturally.

	}

	public static void advance(int seconds, boolean displayStatus){
			long first = System.currentTimeMillis(); // get current time
			long second = (seconds * 1000) + first; // get time arg seconds ahead of the first
			int count = 0;

			// while the first time is not equal to the second, assign first to the current time
			while(first < second){

				if((second - first) == 1000 && displayStatus){
					System.out.println( "Second: " + (++count));
				}

				first = System.currentTimeMillis();
			}
	}

	private class Error242 extends Exception{
		public Error242(String arg){
			super(arg);
		}

		public Error242(){
			super("An error occurred with the specified request!\nPlease try again!");
		}
	}

	public void optionSelected(String str){

		// A new thread should only execute after the previous is finished--
		if(currentFuture == null){
			try{
				currentFuture = es.submit(new Request(str));
			}catch(Exception e){
				System.out.println(e);
			}
		}else System.out.println("There is currently a task in process... …
peter_budo commented: Thank you for advise +10
Alex Edwards 321 Posting Shark

I don't think it's the run method that isn't executing, Peter.

I think the problem is that you are not submitting a Runnable target as the argument for the Thread to execute.

I actually don't understand why the Thread class is not abstract if it allows one to simply give a Thread a title, but I will investigate this a bit more thoroughly and help you find a conclusion.

Alex Edwards 321 Posting Shark

I also just move from c to java and i found this book "java how to program sixth edition" very useful.
you can e-mail me on
<snipped email>
so that i can send it as an attachment

The Deitel and Deitel books are always awesome.

I also, second the recommendation for Java, how to Program... though you should really get the newest edition if possible (I believe it is currently 7e that is newest, though I could be mistaken).

Alex Edwards 321 Posting Shark

>This is checking you haven't done a self-assignment right?
Yes, though that check is actually less effective than simply writing your code in such a way as to make it unnecessary.

>Sorry what is sceleton slang for though?
It's slang for skeleton, and I'm sure any dictionary will tell you the definitions.

>But now you risk changing the original object, which may
>or may not be in respect to the way the class is defined.
As far as I can tell, the thread has devolved into a debate about the assignment operator's return value. In the case of the assignment operator, it's generally best practice to match the behavior of built-in types. If you don't return a reference, you fail in such cases as ( a = b ) = c , which is perfectly legal and where the result should have a == c rather than a == b . Here's that exact test with an assignment operator that returns the result by value:

#include <iostream>

class integer {
  int x;
public:
  integer ( int init ): x ( init ) {}

  integer operator= ( const integer& rhs )
  {
    x = rhs.x;
    return *this;
  }

  friend std::ostream& operator<< ( 
    std::ostream& out, const integer& i )
  {
    return out<< i.x;
  }
};

int main()
{
  int a = 1;
  int b = 2;

  ( a = b ) = 123;

  std::cout<< a <<'\t'<< b <<'\n';

  integer c = 1;
  integer d = 2;

  ( c …
Alex Edwards 321 Posting Shark

I joined Daniweb about 3 months ago, and during that time I started self-learning C++.

Amazingly, a lot of knowledge of Java migrated to my understanding of C++ and vice-versa! By understanding pointers and references as well as learning the Object Model of C++, I started to better understand Java!

Some advice? Don't reinvent the wheel! Use vectors (or safe/auto_ptr) instead of raw pointers if performance isn't an issue.

Also, a few books you might want to pick up if you want to make effective programs--

Suggested list (in order)--

-The C++ Primer (by Stanley B Lippman)
-(Any book, or reference that goes over standard STL)
-Effective/More Effective C++ (By Scott Meyers)
-Exceptional/More Exceptional C++ (By Herb Sutter)
-Effective STL (By Scott Meyers)
-(Any book that thoroughly goes over Data Structures and Algorithms in C++)
-C++ Templates (the first 2 chapters) (By David Vandevoorde and Nicolai M. Josuttis) [optional]
-The C++ Programming Language (By Bjarne Stroustrup)
-C++ Templates (the last 2 chapters) [optional]
-Inside the C++ Object Model (By Stanley B Lippman) [optional]
-(Any book/reference that goes over Boost)

-- if you go over those books, in that order, and also make effective practice of rules and guidelines from each book and have a solid understanding of the material presented in each, you can tackle most obstacles presented to you via C++

But of course this might be a long, repetitive and tedious …

Alex Edwards 321 Posting Shark

Ok, I'm slightly confused about what just happened in this topic...

A fair amount of individuals stated that returning a reference of the actual object that represents the class is more preferable than returning a copy that has the reflected changes made on the object.

Sure, for performance reasons, it might be better. But now you risk changing the original object, which may or may not be in respect to the way the class is defined.

Also, since the original object has no pointer-members, the default copy-constructor is suitable for making a copy of the object after the changes are made.

Without the ampersand (&) the function creates and returns a temporary copy of the object it is acting on. This involves invoking a copy constructor and (when the caller has finished with the returned object) destroying it.

While a compiler is allowed to eliminate temporary objects in some circumstances, it is usually better to return a reference for performance reasons.

I don't know about you, but whenever I need to use something (like a copy for example) I only use it in the same scope it is declared/defined.

A not-so-perfect example of copy vs reference--

#include <iostream>

class ThreeD
{
    int x,y,z;

    public:
    ThreeD() {x=y=z=0;}
    ThreeD(int i, int j, int k){setLocation(i, j, k);}
    void setLocation(int i, int j, int k);
    ThreeD operator+(ThreeD op2);
    ThreeD& operator=(ThreeD op2);
    ThreeD copy();
    void show();

};

ThreeD& ThreeD::operator=(ThreeD op2)
{
    x=op2.x;
    y=op2.y;
    z=op2.z;

    return *this;
}

void …
Alex Edwards 321 Posting Shark

>I like what your saying.... to be a good programmer we must love the program..!!
To be a good programmer, you need to know how to make a program.

Seconded.

Alex Edwards 321 Posting Shark

Works fine with VC++ 2005/2008

Alex Edwards 321 Posting Shark

I didn´t know that there was 2 arguments. Good to know now :)
So if I understand correct for a simpler example below, all 36 elements
is declared to: -1
Thank you !

std::vector<std::vector<int> > vec2(5, std::vector<int>(5, -1));

I'm pretty sure you meant 25 (5*5), but I believe you get the idea.

Have fun =)

Alex Edwards 321 Posting Shark

Vectors have an overloaded Constructor that allows two arguments...

I do believe, in that scenario, the first argument is the initial size and the second is the default value for all values in the vector.

std::vector<std::vector<int> > vec2(100, std::vector<int>(50, -1));

Source

Alex Edwards 321 Posting Shark

Are Model 2 projects allowed?

Aka, MVC, JSP/JavaScript front-end, Servlet controller, Database back-end...?

Alex Edwards 321 Posting Shark

Maybe this will do the trick?

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Ball extends JApplet implements MouseListener {
   private MyThread blueBall[] = new MyThread[MAX_BALL_COUNT];
   private boolean bouncing; // xUp, yUp
   //private int x, y, xDx, yDy;
   int ballcount = 0;
   final private static int MAX_BALL_COUNT = 20;


   //init is called by the browser to inform the applet that Ball has been loaded
   public void init()
   {
      //xUp = false;
      //yUp = false;
      //xDx = 1;
      //yDy = 1;
      bouncing = true;
      addMouseListener( this );
      Thread repaintThread = new Thread(rt);
      repaintThread.setPriority(1);
      repaintThread.setDaemon(true);
      repaintThread.start();
   }


   public void mousePressed( MouseEvent e )
   {
      if ( ballcount < MAX_BALL_COUNT ) {

         blueBall[ballcount] = new MyThread();
         blueBall[ballcount].x = e.getX(); //PB: get the X position
         blueBall[ballcount].y = e.getY(); //PB: get the Y position
         Thread temp = new Thread(blueBall[ballcount]);
         temp.setPriority(2);
         temp.setDaemon(true);
         temp.start();
         ballcount++;
      }
   }

   public void stop()
   {
      //if ( blueBall != null )
      //   blueBall = null;
      for(MyThread element : blueBall){
		  if(element != null)
		  	element.running = false;
	  }
	  bouncing = false;

   }

    public void start ()
    {
    //    for(int i = 0; i < blueBall.length; i++)
    //        if(blueBall[i] != null)
    //            blueBall[i].start();
    }

	Runnable rt = new Runnable(){
		@Override public void run(){
			while(bouncing){
				try{
					Thread.sleep(25);
				}catch(Exception e){}
				repaint();
			}
		}
	};


   public void paint( Graphics g )
   {
      super.paint( g );

      if ( bouncing ) {
         g.setColor( Color.blue );

         for(MyThread element : blueBall){
			if(element != null)
         	   g.fillOval( element.x, element.y, 10, 10 );
		 }
      }
   }

   public class MyThread implements Runnable{
	   public int …
Alex Edwards 321 Posting Shark

After running some tests I realized that somehow your transform is jumping between 1-22 on the (result?) matrice--

import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.io.*;
import javax.swing.*;
import java.util.*;
import java.lang.*;



public class ColorForms extends JFrame
{
    LeftPanel leftPanel;
    TopPanel topPanel;
    CanvasPanel canvasPanel;
    JSplitPane wholePanel, bottomPanel;

    public static void main (String args[])
    {
        ColorForms cf = new ColorForms ();
    }


    public ColorForms ()
    {
        this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        this.setSize (400, 400);
        this.setVisible (true);

        leftPanel = new LeftPanel ();
        topPanel = new TopPanel ();
        canvasPanel = new CanvasPanel ();

        bottomPanel = new JSplitPane (JSplitPane.HORIZONTAL_SPLIT, leftPanel, canvasPanel);
        bottomPanel.setDividerLocation (50);
        wholePanel = new JSplitPane (JSplitPane.VERTICAL_SPLIT, topPanel, bottomPanel);
        wholePanel.setDividerLocation (70);

        this.getContentPane ().add (wholePanel);
    }
}


class LeftPanel extends JPanel
{
    public LeftPanel ()
    {
    }
}


class TopPanel extends JPanel
{
    public TopPanel ()
    {

    }
}


class CanvasPanel extends JPanel
{
    public CanvasPanel ()
    {
    }


    public void paintComponent (Graphics g)
    {
        System.out.println (((Graphics2D)g).getTransform());

        int ovalCenterX = 100;
        int ovalCenterY = 100;
        int ovalWidth = 200;
        int ovalHeight = 100;
        int ovalUpperLeftX = ovalCenterX - ovalWidth / 2;
        int ovalUpperLeftY = ovalCenterY - ovalHeight / 2;
        double angle = 0.5;

        super.paintComponent (g);
        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        setBackground(Color.GREEN);

        AffineTransform orig = g2.getTransform();
        AffineTransform af = new AffineTransform ();
        af.rotate(angle, ovalCenterX, ovalCenterY);
        g2.setTransform(af);
        g2.setColor (Color.BLACK);
        g2.fillOval (ovalUpperLeftX, ovalUpperLeftY, ovalWidth, ovalHeight);
        g2.setTransform(orig);
    //    g2.setTransform(af);
    }
}

-but I can't say much else with my lack of knowledge in transformations =/

Alex Edwards 321 Posting Shark

Nice read, another article I really liked linked with developing skills in the programming field is Peter Norvig's Teach Yourself Programming in Ten Years

I disagree with this article.

The author claims that personal training and experience is far better than simply reading a book.

Without the basis, or knowledge of discrete details brought to you by experts, it's hard to say how far your personal training will go.

I suppose this is an "Eye of the beholder" opinion, but maybe you can understand how I feel with my statement?

-Alex

Alex Edwards 321 Posting Shark

Even if someone did do the project, they would never post the solution and keep it to themselves.

That's how we roll =P

Alex Edwards 321 Posting Shark

Man where is Salem when you need him...

Anyways, yeah Masijade is correct. You should really experiment and try things on your own until you come across an error. Then ask for help =P

Alex Edwards 321 Posting Shark

Alex,
Could you tell me what is the use of Red-Black Tree. Actually I am supposed to give session on DS and to make it interactive I want it to be like problem discussion.

Narue explains it best here.

Alex Edwards 321 Posting Shark

I strongly recommend learning PHP (or JSP) and Oracle together.

Knowing how to design a Web page and manage a database can get you MANY jobs in the IT field, especially when integrating a Database to store information sent from forms in HTML processed requests.

Knowing XHTML is also a plus. ASP is another topic you may want to consider tackling.

From there you can proceed to a back-end language like Java, VB, C# and integrate those with the Web and Database knowledge.

I'm starting from the other end (learned (and still learning) Java as well as some C++) and I'm approaching Oracle to integrate with new projects and concepts. I find the web much harder to understand, though I always hear it's "easy."

Eye of the beholder I guess... anyways good luck! =)

Alex Edwards 321 Posting Shark

Classes can be used for many things...

The Programming perspective:

-Restricting access to encapsulated data/ standing in for the same type (Proxy)
-Abstractions for future data (Strategy, Bridge)
-Adding functionality to existing objects with the same interface (Decorator)
-Adapting an object to the interface of another (Adapter)
-Providing a commonality for iterating through a collection of objects (Iterator)
-Granting transparency between using one object, or many of the same type (Composite)
and so on in terms of patterns--


The Client/Programmer perspective:

-Easy to relate ideas into programmable objects.
-Easy (or easier) to identify problems in existing code when classes are used for job delegation.
the list goes on, but these are some advantages to name a select few #_#

Alex Edwards 321 Posting Shark

Try creating a Red-Black Tree.

See attached.

Alex Edwards 321 Posting Shark

>>Here's a correction
I'm afraid not. Line 38 is wrong.

Oh, I didn't even catch that @_@.

Looks like I need to do more I/O in C++ =/

Edit: After reading this link I suppose it is better to use ifstream.get() and assign it to the char? char c = ins.get();

Alex Edwards 321 Posting Shark

You were nearly right! Here's a correction--

#include <iostream>
#include <fstream>
using namespace std;

const int MAX = 30;

struct node
{
    char base;
    node* next;
};
node* head;

void initialise();
void insertion(char);
void printlist(node& root);

int main()
{
    ifstream ins;
    char filename[MAX];
    int count = 0; // initialize it! =)
    char x;

    initialise();

    cout << "Enter the name of the file you wish to open: " <<endl;
    cin >> filename;

    ins.open(filename, ios::in);

    if(ins.good())
    {
        cout<<"File opened successfully\n" <<endl;

        while(!ins.eof())
        {
            ins.get(x);
            insertion(x);

            count++;
        }

    }
    else
    {
        cerr <<"Error opening the file" <<endl;
    }

    printlist(*head);

    return 0;
}

void printlist(node& root){
    node* temp = &root;

    if(temp != NULL){
        while(temp->next != NULL){
            std::cout << temp->base << std::flush;
            temp = temp->next;
        }
    }else std::cout << "List is empty" << std::endl;

}

void initialise()
{
    head = NULL;
}

void insertion(char x)
{
    node* tmp = new node;

    if (tmp == NULL)
    {
        return;
    }

    //strcpy(tmp->base, x);
    tmp->base = x; // no need to allocate memory for this char
    tmp->next = NULL;

    if (head == NULL)
    {
        head = tmp;
    }
    else
    {
        node* newhead = head;

        while (newhead->next != NULL)
        {
            newhead = newhead->next;
        }

        newhead->next = tmp;
    }
}

I'm sure it can be done tons of better ways, but you were incredibly close.

There was no need to allocate memory to the non-pointer declared in your struct. Although it was not initialized, it is not a pointer. It is simply an "object" that exists on the stack …

Alex Edwards 321 Posting Shark

I hope I'm not out of place by asking this, but does it have something to do with calling conventions?

>_>

Alex Edwards 321 Posting Shark

From what I understand, all objects are saved as .dat files for Java to reinterpret back into an object during deserialization.

To save files with an extension, I'd assume you'd use FileOutputStream and specify the kind of File you'd like to save.

If you mean to save an Object into a file other than the what's provided by Java, you will most likely have to do a 2-in-1 process of saving the Object as .dat file then opening a new file with the desired extension (Click) then opening a Stream to write bytes to that file, in which you'd have to read bytes from your Object file first then write those bytes to the desired file.

You could save yourself time by making a copy of the object file and attempting to change the extension manually, though I'm not sure if this is entirely recommended (or safe). It may be best to use a program that does this for you - one that Java provides most likely.

Alex Edwards 321 Posting Shark

your professor is correct except for one thing, Scanner Doesn't have a nextChar method, i believe it is the only primitive not supported.

use this instead:

Scanner yourName = new Scanner(yourInput);
char c = yourName.next().charAt(0);

where yourName and yourInput are whatever you want them to be

Yes, this version is much easier to understand.

Also the DataInputFilterStream is flawed and will only work for the InputStream provided by the System class, and does not work well with files.

The reason why I don't like the Scanner class very much, and felt the need to make my own is due to this test (and many others regarding Scanner), below--

import java.io.*;
import java.util.*;

public class DriverProgram_64{

	public static void main(String... args){
		BufferedReader br = null;
		Scanner kb = null;
		try{
			br =
				new BufferedReader(
					new InputStreamReader(
						new FileInputStream(
							new File("Test_Text.txt")
					)
				)
			);

			kb = new Scanner(
							new FileInputStream(
								new File("Test_Text.txt")
							)
			);

			System.out.println("BufferedReader test:");
			while(br.ready()){
				System.out.println((char)br.read());
			}

			System.out.println("\n\n\nScanner test: ");
			while(kb.hasNext()){
				System.out.println(kb.next().charAt(0));
			}
		}catch(Exception e){}
		finally{
			try{
				br.close();
				kb.close();
			}catch(Exception e){
				System.exit(1);
			}
		}
	}
}

--with the attached .txt file

Alex Edwards 321 Posting Shark

Are you required to use C headers/functions or are you allowed to use C++?

Alex Edwards 321 Posting Shark

This approach was probably unnecessary, but I took it anyways.

Try this--

import java.io.*;

public class DataInputFilterStream extends FilterInputStream{

	public DataInputFilterStream(InputStream is){
		super(new DataInputStream(is));
	}

	@Override public int read() throws IOException{
		skip(available());
		return (available() == 0) ? super.read() : 0;
	}

	public char readChar() throws IOException{
		return (char)read();
	}
}
import java.io.*;

public class CharScanner{


	public static void main(String... args){
		DataInputFilterStream difs = null;
		try{
			difs = new DataInputFilterStream(System.in);
		}catch(Throwable t){
			System.out.println("Unable to initialized object dis - shutting down.");
			t.printStackTrace();
			System.exit(1);
		}
		boolean decision = true;
		do{
			try{
				System.out.println("Enter a char--");
				System.out.println("You enterred: " + difs.readChar());
				System.out.println("To Continue enter the character y");
				char userInput = difs.readChar();
				decision = ((userInput == 'Y') || (userInput == 'y'));
			}catch(Throwable t){
			}
		}while(decision);

		try{
			difs.close();
		}catch(Exception e){
			try{
			}finally{
				System.out.println("An error occurred during stream closing - exiting program--");
				System.exit(1);
			}
		}
	}
}
Alex Edwards 321 Posting Shark

Yes, the fact that you can store items that aren't what other programmers may expect when handling the data. That and most likely issues in memory, though I can't confirm this.

The only reason raw types are allowed is for compatibility between legacy versions of Java (before Erasure types) and of course the current standard.

import java.util.*;

public class BigOopsDaisyClass{

	private static ArrayList<String> supposedlyStrings;
	private static ArrayList supposedlyObjects = new ArrayList<Integer>(0);

	public static void main(String... args){

		ArrayList badList = new ArrayList(0);
		badList.add(new Double(2.2));
		badList.add(new Byte((byte)200));

		supposedlyStrings = badList; // Very bad!

		supposedlyStrings.add(new String("HORRIBLE"));

		supposedlyObjects.add(new Short((short)30000)); // not even an Integer, but legal?
		supposedlyObjects.add(new Long((long)1919191)); // again!?!?

		System.out.println( "Result of supposedlyStrings: " + supposedlyStrings);
		System.out.println("\n\n\n\n\n\n\n");
		System.out.println("Result of supposedlyObjects: " +supposedlyObjects);
	}
}
Alex Edwards 321 Posting Shark

You may find these links helpful--
javax.swing which is adjacent to the .NET Frameworks.

Threads/Concurrency in the event that you need your application to do multiple operations for the end-user, though the EDT in javax.swing Components should be sufficient.

If this is to be deployed on a Web Page for the end-user to access without needed to install the application on their computer, you could consider using either a JApplet or possibly a combination of a Servlet with a JSP front-end, though the idea of implementing JSP is beyond the scope of standard Java since it requires HTML/XHTML knowledge.

What criteria must be met for the clients?

Alex Edwards 321 Posting Shark

I've tried the above using tests with unsigned __int8, __int16, __int32 and __int64 (for the class and cast) and received either contiguous or non-contiguous results.

More likely than not, we missed something (like padding factor for certain values), though I can't confirm this...

*Heads for the C++ Object Model*

>_>

Alex Edwards 321 Posting Shark

Very interesting!

Though, I'm not very familiar with digital circuits. Are you trying to union two components together so they act as one?

Alex Edwards 321 Posting Shark

You forgot to add the Panel that you were adding everything too!

/*
Page #:		Page 372 #3
Filename:	Checkerboard.java
*/

import java.awt.*;
import java.awt.event.*;

public class Checkerboard extends Frame implements ActionListener
{
	//declare variables
	Panel checkerPanel = new Panel();
	TextField[] board = new TextField[16];

	int start, stop, step;

	Panel fieldPanel = new Panel();
	TextField fieldStart = new TextField(5);
	TextField fieldStop = new TextField(5);
	TextField fieldStep = new TextField(5);
	Label LabelStop = new Label("Start");
	Label LabelStart = new Label("Stop");
	Label LabelStep = new Label("Step");
	Panel buttonsPanel = new Panel();
	Button goButton = new Button("Go");
	Button clearButton = new Button("Clear");

	public Checkerboard()
	{
		start = 0;
		stop = 0;
		step = 0;

		this.setLayout(new BorderLayout());
		checkerPanel.setLayout(new GridLayout(4, 4));
		fieldPanel.setLayout(new GridLayout(2, 3));
		buttonsPanel.setLayout(new FlowLayout());

		for(int i = 0; i<16; i++)
		{
			board[i] =  new TextField();
			board[i].setText("" + i);
			board[i].setEditable(false);
			checkerPanel.add(board[i]);
		}

		fieldPanel.add(fieldStart);
		fieldPanel.add(fieldStop);
		fieldPanel.add(fieldStep);
		fieldPanel.add(LabelStart);
		fieldPanel.add(LabelStop);
		fieldPanel.add(LabelStep);
		buttonsPanel.add(goButton);
		buttonsPanel.add(clearButton);
		goButton.addActionListener(this);
		add(fieldPanel, BorderLayout.NORTH); // edit
		add(buttonsPanel, BorderLayout.SOUTH); // edit

		//add windowListener p.350
		addWindowListener(
			new WindowAdapter()
			{
				public void windowClosing(WindowEvent e)
				{
					System.exit(0);
				}
			}
		);

	}

	public void actionPerformed(ActionEvent e)
	{
		String arg = e.getActionCommand();
		if(arg == "Go")
		{
			start = Integer.parseInt(fieldStart.getText());
			stop = Integer.parseInt(fieldStop.getText());
			step = Integer.parseInt(fieldStep.getText());

			if (start < 0 || stop < 0 || step < 0) arg = "clear";

			for (int i=0; i<16; i++)
				board[i].setBackground(Color.magenta);

			for (int i=start; i<=stop; i=i+step)
				board[i].setBackground(Color.yellow);
		}

		if (arg== "Clear")
		{
			fieldStop.setText("");
			fieldStart.setText("");
			fieldStep.setText("");

			for (int i=0; i<16; i++)
				board[i].setBackground(Color.white);
		}
	}

	public static void main(String[] args)
	{
		Checkerboard f = new Checkerboard();
		f.setBounds(50, …
Alex Edwards 321 Posting Shark

What version of the JRE are you using on the MAC?

Alex Edwards 321 Posting Shark

It sounds like you need a map, or an algorithm to determine a match for a set amount of values.

Personally, to get things working, I'd take the easy way out until I found a more efficient solution.

What immediately comes to mind is something like this--

#include <iostream>
#include <map>
#include <utility>
#include <string>
#include <vector>

using std::string;
using std::map;
using std::pair;
using std::vector;

template<class L, class N> void safeInsert(map<L, vector<N> >&, L, N);
template<class L, class N> pair<L, vector<N> > safePair(L, vector<N>);

template<class L, class R>
void safeInsert(map<L, vector<R> > &m, L key, R value){
    if(&m[key] == NULL){
        vector<R> temp;
        temp.push_back(value);
        m.insert(safePair<L, R>(key, temp));
    }
    else m[key].push_back(value);
}

template<class L, class R>
pair<L, vector<R> > safePair(L lhs, vector<R> rhs){
    pair<L, vector<R> > p (lhs, rhs);
    return p;
}

int main(){

    map<string, vector<string> > myList;
    safeInsert(myList, string("Joe"), string("Joe"));
    safeInsert(myList, string("Joe"), string("Joe Smith"));
    safeInsert(myList, string("Bob"), string("Bob Marley"));

    vector<string> result = myList[string("Joe")];

    for(vector<string>::iterator next = result.begin(); next != result.end(); next++)
        std::cout << *next << std::endl;

    return 0;
}

-- though again it might not be perfect, but it meets the criteria without dipping far into algorithms or relying on queries to achieve similar results.

Edit: Rereading the post, I realized you need either a regex or a parser to determine the key to use the above method.

This link might also help - substr

Alex Edwards 321 Posting Shark

I hope these questions don't seem stupid!

If an elaboration is needed, the intent is to make the Snaker animated in the View for the Model 2 scenario. Unfortunately this means that the Model must be updated constantly along with the View.

I want to hold true to the MVC pattern, though I'm not sure if I can do it in this way. The only other option is to allow the Controller to have a thread to constantly change the state of the model so the view can reflect the changes.

Alex Edwards 321 Posting Shark

You can try getting in touch with the recruiters to see what kind of skills they're seeking.

You may also find yourself required to read or take a course on a different subject (such as Database Access/Administration via SQL/Oracle, XML, HTML (XHTML), C#, Java, .NET, etc), and possess other skills (QA, Leadership, Experience in Agile Methods, Unit Testing experience, etc), to match the pre-req of some jobs.

It really depends on what it is you want to do. If you just want to code in C++, it may be possible especially with 7 years of experience, though I'm not sure @_@

Obviously, don't give up! Your best bet is just to talk with the recruiters over the phone and see if they can schedule an interview with you at some point and time.

Anyways good luck =)

Alex Edwards 321 Posting Shark

Most of the information is pretty straightforward in terms of Model 2.

However, I'm still struggling to understand how to implement my design for this project...

I don't know if what I need is an Active Server Page, or a Page that, somehow, listens for changes in the database and refreshes accordingly... or simply (if possible) have a thread active that will (somehow) refresh the page whenever a state change in the Model is visible.

I'm completely at the mercy of learning Servlets more thoroughly, which I don't have a problem with. I'd just like to know if what I'm attempting to do is easy, or hard, from an experienced Servlet/JSP-user's perspective.

-Alex

Edit: Will I need to implement Java-code in the View instead (for example, a Panel or some kind of Swing component)? I don't know of what's allowed in a HTML, but I'd assume that Swing components are ok.

Alex Edwards 321 Posting Shark

Can u pls explain the o/p for the following,

char* str = 0;
std::cout<<[B]&str[/B]<<std::endl;

Output : 0012FF24

Amit

Most likely because--

// *str is equivalent to... I don't know, most likely undefined behavior so don't dereference @_@

// str is equivalent to NULL because all pointers can point to the NULL address which is represented by 0

// &str is most likely the address of the actual pointer O_O
Alex Edwards 321 Posting Shark

For the sake of documentation,
can you tell me where got this info.
(for my boss)

thanks

If he is citing 8.5.3 that should be the chapter/item in the C++ standard documentation...

Alex Edwards 321 Posting Shark

Here's a way to filter out what you need without worrying about hideous "blocks" from the Scanner class--

import java.util.Scanner;
import java.io.*;
import java.util.ArrayList;

public class arrayManipulator{
        public static void main(String... args) throws IOException{
		ArrayList<Integer> myArray = new ArrayList<Integer>(0);
		BufferedReader s = null;
		try{
			s = new BufferedReader(new FileReader("C:/Documents and Settings/Mark/My Documents/usrnames.txt"));
				while(s.ready()){
					String value = "" + (char)s.read();
					try{
						Integer x = Integer.parseInt(value);
						myArray.add(x);
					}catch(Exception e){
						continue;
					}
				}
				System.out.println(myArray);
		}finally{ 
			s.close();
		}
	}
}
Alex Edwards 321 Posting Shark

Though this doesn't quite answer my question, a good amount of information provided by peter_budo was found here.

Alex Edwards 321 Posting Shark

I'm making a Servlet application using the a MVC-like implementation, however I'm slightly confused on how I should delegate concurrent modification of the state of the Model object?

I intend to use a database to hold information from a given session for a particular individual (the data will be retrieved based on a username and password).

It doesn't seem possible or practical to store a Thread in the Model object, so that's really not an option.

I do want to respect the MVC implementation such that the View is dependent on the Model object and the Controller changes the state of the Model.

The question is, how do I make the View update when the Model changes state? The View is going to be a JSP that has action-value attributes. Since the View is really just a page (and not an object), how do I tell the page to refresh based on the new information? Must I rely on the Controller to do so?

I understand that Servlets run in a multi-threaded server environment, though I'm not sure how this is exercised upon the model. It seems like a waste to force the page to be refreshed every millisecond (and potentially costly to the client), though I don't understand any other way for the type of program I wish to write.

To be slightly more specific, I'm planning on remaking Snake-it in a Servlet environment as a practice program for JSP and Servlet programming. …

Alex Edwards 321 Posting Shark

why do we need interfaces in java?,if the functions are to be defined in implementing class only then why declare these in an interface first?????????

There needs to be some kind of simple commonality between classes.

An interface allows for many benefits via the implementation of the Object Model and how objects communicate with each other, encapsulate other objects, and additional inherit information from existing classes.

For example, suppose I have an Expert System that was incredibly difficult for developers to produce. It issues commands on a Module object--

ExpertSystem es = ExpertSystem.getCurrentSystem(); // get the current ExpertSystem

es.startModule(); // executes the Module object
// inside the Module class

void start(ExpertSystem ex){

       // perform operations for the given ExpertSystem

}

--however, what if an improved Module is produced, and the ExpertSystem needs to use it, but the improved Module does not have the same implementations as the one the ExpertSystem is used to using?--

Module2 nextModule = new Module2(); // doesn't share the same data as a regular Module

// ExpertSystem cannot use the new Module!

--Now this is a pain... we have a new Module and we can't even use it with the existing system!

Fortunately, knowing that the System can use Modules is a convenient thing. What we can do is treat Module's the System is used to as the abstraction.

Let's pretend Module is a class--

class Module{

      public void start(ExpertSystem ex){
          // perform operations for ExpertSystem     
      }

}
Ezzaral commented: Good post +11
Alex Edwards 321 Posting Shark

That probably wont work for a number of reasons.

First of all, you're specifying a URL as a combination of of values that compiler doesn't know how to parse. You will need to wrap those letters in a String--

String location = "C:\Documents and Settings\Imran Sabir\My Documents\Computing Work\Picture Silde";

--even so, this is still inappropriate because \ is considered a special character for expressions like "\n" (newline) or "\s" (space), so you will either need to provide a hint to the compiler by double-forward slashing or using the backslash in place of the forward slash.

EVEN THEN you are still not being 100% compliant to the platform you're invoking the command from, since the back and forward slash are file-system dependent. For simplicity, stick to the above suggestion and do this--

String location = "C:/Documents and Settings/Imran Sabir/My Documents/Computing Work/Picture Silde";

--or--

String location = "C:\\Documents and Settings\\Imran Sabir\\My Documents\\Computing Work\\Picture Silde";

-- and you should be ok, but at the moment we're storing the location in a string and not exactly extracting the much needed image @_@.

To achieve this, you'll need to consider looking into API's that allow you to easily retrieve an image from a File. The Image abstraction is a good place to start--

import javax.swing.JFrame;
import java.awt.Image;
import java.awt.Graphics;
import javax.imageio.ImageIO;
import java.io.File;

public class MyFrame2 extends JFrame{

	Image img = null; // placeholder for an Image object

	public MyFrame2(String location) throws Exception{
		img = ImageIO.read(new File(location)); // …
Alex Edwards 321 Posting Shark
//assuming img is the reference-variable for an actual image

final short AMOUNT = <insert amount of images you want>;
Image images[] = new Image[AMOUNT]; // can now hold AMOUNT number of images

images[0] = img; // assigns the address of img to the first indice of array images

// images[0] points to the same object as img so changes can be done to the object from either reference

Hopefully this helps.

Alex Edwards 321 Posting Shark

Are you talking about the IDE or the java.beans package? If you mean the IDE then this link will help http://www.netbeans.org/kb/

I think he means an extension of a HttpServlet or possibly a Bean implementation via a NetBeans JSP session where the tools are provided for manipulating the View and Controller.

Alex Edwards 321 Posting Shark

I actually don't have control over glutMouseFunc (I mean I suppose I could edit the glut source, but that sounds like a bad idea)

Why is it so much different to pass a member function than a normal function?

Is there no way to do this without overloading glutMouseFunc?

Thanks!

Dave

You could just overload the function to accept a pointer-to-member function.

Alex Edwards 321 Posting Shark

>>What about individual characters? Is it possible to get the address of those,

What do you mean? Do you want to get the address of a char variable when it's declared as a straightforward, stand alone variable, when it's an element of a char array, when it's an individual char as part of a string, or when it's an element of a string whose address is stored in a pointer and you want to access it by dereferencing the pointer?

>>or are char values stored in a special way?

Not that I know of.

Then again I suppose it's not hard...

const char *c_string = "c-string";

const char& refChar = c_string[0];

std::cout << &refChar << std::endl;

...though I'm not near a C or C++ compiler at the moment so I can't confirm if this will work or not @_@