Alex Edwards 321 Posting Shark

Notice the import statements --

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

/*from Arrays*/ static <T> T[] Arrays.copyOfRange( T[] array, int from, int size )

Alex Edwards 321 Posting Shark

HI..
The information will vary only with 44 and 32... so i'm adapting the code for 32 as well...

I'm going to try first.. and then will tell Further more.. THHHAANNNKKK YOOUUU SOO MUCH...

For the final values declared in global scope of the class, you may additionally (or inversely) want to declare an array or enum that holds those values so you can simply iterate through them when processing your information.

I hope everything turns out well for you.

-Alex

Alex Edwards 321 Posting Shark

How often do your lines vary in information? You could go about this a few ways

-Create classes to handle those cases
-Adapt the current class to simply handle all cases.

I'd go for number 2 to be safe, but in order to do that more information about what's varying will be needed.

Alex Edwards 321 Posting Shark

Here's a test I ran using this file--

INSPECT.txt

,07/19/2008,00:48:55,#280,Module 1 ,IC2,TSOP8,SOP8_1,F,138.539642,238.000000,84.000000,140.000000,P,9.226400,140.000000,P,427747.781250,729933.140625,243311.046875,486622.090000,P,26717.400391,486622.093750,P,60986780.000000,122628772.800000,34063548.000000,68127092.600000,P,3087930.000000,68127096.000000,-22.886625,-23.317499,-0.039985,-0.131595,P,0,1,P,0,1,P,0,1
,07/19/2008,00:48:55,#280,Module 1 ,C38,0402,0402_1_3,P,131.077194,238.000000,84.000000,140.000000,P,12.636800,140.000000,P,265426.750000,470565.468750,156855.156250,313710.320000,P,5929.500000,313710.312500,P,36161180.000000,79054999.200000,21959722.000000,43919444.800000,P,2340260.000000,43919444.000000,-26.636499,-28.285000,-0.201710,-0.635564,P,0,1,P,0,1,P,0,1
,07/19/2008,00:48:55,#280,Module 1 ,C66,0402,0402_1_3,P,146.934555,238.000000,84.000000,140.000000,P,4.062300,140.000000,P,266860.500000,470565.468750,156855.156250,313710.320000,P,15511.000000,313710.312500,P,40048568.000000,79054999.200000,21959722.000000,43919444.800000,P,235260.000000,43919444.000000,-32.004501,-21.340000,-0.163571,-1.147347,P,0,1,P,0,1,P,0,1
import java.io.*;
import java.util.Arrays;

public class InspectionResults{

	public static final byte  HEIGHT_AVG_RESULT = 7,
							  HEIGHT_RANGE_RESULT = 12,
							  AREA_AVG_RESULT = 15,
							  AREA_RANGE_RESULT = 20,
							  VOLUME_AVG_RESULT = 23,
							  VOLUME_RANGE_RESULT = 28,
							  HAV_FAILED_FEATURE_RESULT = 35,
							  REG_FAILED_FEATURE_RESULT = 38,
							  BRIDGE_FAILED_FEATURE_RESULT = 41;
	private String retrievedData[];
	private boolean failed[];

	/**
	 * Constructs this InspectionResult with the data stored in the args.
	 * This class expects 44 values within the range of the args.
	 */
	public InspectionResults(String... args){
		retrievedData = args;
		boolean temp[] ={
			((retrievedData[7].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[12].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[15].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[20].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[23].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[28].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[35].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[38].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[41].equalsIgnoreCase("F")) ? true: false)
		};
		failed = temp;
	}

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

		FileReader fr = null;
		BufferedReader br = null;
		try{
			fr = new FileReader(new File("INSPECT.txt"));
			br = new BufferedReader(fr);
		}catch(Exception e){e.printStackTrace();}


		String dwArray[][] ={ {""}, {""}, {""} };

		for(int i = 0; i < dwArray.length; i++){
			String temp[] = null;

			try{ temp = br.readLine().split(",");}catch(Exception f){f.printStackTrace(); System.exit(1);};
			temp = Arrays.<String>copyOfRange(temp, 1, temp.length);
			dwArray[i] = temp;
		}


		InspectionResults ir[] =
		{
			new InspectionResults(dwArray[0]),
			new InspectionResults(dwArray[1]),
			new InspectionResults(dwArray[2])
		};

		System.out.println(ir[0]); // as an example
		spacer(3);

		try{
			System.out.println(ir[0].hasFailed(InspectionResults.HEIGHT_AVG_RESULT));
			System.out.println(ir[0].getAdjacentValue(InspectionResults.HEIGHT_AVG_RESULT));
		}catch(Exception e){
			System.out.println(e);
		}

		try{
			fr.close();
			br.close();
		}catch(Exception e){
		}
	}

	private static void spacer(int lines){
		for(int i = 0; i < lines; i++)
			System.out.println();
	}

	/**
	 * Returns true if …
Alex Edwards 321 Posting Shark

I'm assuming you mean something like this--

//...
            else{
                System.out.println("Program exiting. Thank you, and have a nice day!");
                break;
            }
        } // end while (true)
//...
Alex Edwards 321 Posting Shark

if(!emp.getName().equalsIgnoreCase("Stop"));// try removing the semicolon at the end of your if statement

Alex Edwards 321 Posting Shark

sciwizeh, thank you. I'll play around with that. Alex, thank you too. Hopefully this is the easier way we were thinking of.

I don't doubt sciwizeh, especially when it comes to image-handling. Check out his site for example =).

Alex Edwards 321 Posting Shark

This is the error I'm getting when trying to load this using FireFox (after 3 attempts)

Java Plug-in 1.6.0_07
Using JRE version 1.6.0_07 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\Mark


----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
p:   reload proxy configuration
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------

java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM.1)
	at java.security.AccessControlContext.checkPermission(Unknown Source)
	at java.security.AccessController.checkPermission(Unknown Source)
	at java.lang.SecurityManager.checkPermission(Unknown Source)
	at java.lang.SecurityManager.checkExit(Unknown Source)
	at java.lang.Runtime.exit(Unknown Source)
	at java.lang.System.exit(Unknown Source)
	at MainPanel.<init>(MainPanel.java:24)
	at AppletWithPNG.<init>(AppletWithPNG.java:20)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at java.lang.Class.newInstance0(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at sun.applet.AppletPanel.createApplet(Unknown Source)
	at sun.plugin.AppletViewer.createApplet(Unknown Source)
	at sun.applet.AppletPanel.runLoader(Unknown Source)
	at sun.applet.AppletPanel.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

Edited*

Edit2: Ok I commented out the System call and now I'm getting just the background without the image (most likely your main issue).

VernonDozier commented: Thanks for spending time to work on this! +5
Alex Edwards 321 Posting Shark

I know for a fact that there must be an easy way around this...

If not, you could consider setting up a server, send the files to the server from your computer, keep it up and running then read the files from the Server into the JApplet (once, to prevent concurrent and expensive I/O operations) then use the image references obtained.

I'm sure there's another way. I'm not sure if it's possible to set up a database that has this information on it then simply query it... but even so you'd have access permissions if you're using a restrictive OS like Windows Vista.

I remember someone else having this problem... but I don't recall how they solved the problem.

Edit: Actually this might not be a good solution, because you will still have access-privilege issues since the server exists separately from the location of the JApplet.

Alex Edwards 321 Posting Shark
public class OtherExample	{

	private Example e = new Example();
	
	public void someAction()	{
		if(e.getExample == 0){ // error, e.getExample not declared/found (forgot parenthesis)
			e.setExample(30);
		} else {
			System.err.println("Please wait before doing this action again");
		}
	}

	/* Is refreshed every 600ms */
	public void process()	{
		if(e.getExample() > 0)	{
			e.getExample() -= 1; // error,! methods cant be used as lvalues
		}
	}
}

Other than the errors listed above, you're simply trying to monitor time being elapsed then do something, correct? The class I'm going to provide may or may not be of use for you. Hopefully it will be. I call it Clock when really it's just a virtual stop-watch--

import java.util.concurrent.*;
import javax.swing.JOptionPane;

public class Clock{

	private ExecutorService es = Executors.newFixedThreadPool(1);
	private long startTime = 0, finishTime = 0, decided = 0;
	private boolean isStarted = false, wasReset = true;
	public static final long SECONDS = 1000000000, DECASECONDS = 100000000, CENTISECONDS = 10000000, MILLISECONDS = 1000000;

	public Clock(int timeType) throws Throwable{
		setTimeType(timeType);
	}

	public Clock(long timeType) throws Throwable{
		setTimeType(timeType);
	}

	public void setTimeType(int timeType) throws Throwable{
		if((!isStarted) && wasReset){
			switch(timeType){
				case 0: decided = SECONDS;
					break;
				case 1: decided = DECASECONDS;
					break;
				case 2: decided = CENTISECONDS;
					break;
				case 3: decided = MILLISECONDS;
					break;
				default:{
					this.finalize();
					throw new Exception("Improper timetype");
				}
			}
		}
		else JOptionPane.showMessageDialog(null, "Please reset the clock before using a different timetype.");
	}

	public void setTimeType(long timeType) throws Throwable{
		if((!isStarted) && wasReset){
			if(timeType == SECONDS)
				decided = SECONDS;
			else if(timeType == DECASECONDS) …
Alex Edwards 321 Posting Shark

Math.random()

The above returns a random number between 0 and 1


Math.random()

Yes, and since it's a random number between 0 and 1 you can use this to your advantage by multiplying the result with a number that you want to be the "range" for randomness.

Math.random() * 35 generates a number that may be >= 0 or < 35.

Alex Edwards 321 Posting Shark
RandomAccessFile File = new RandomAccessFile(fdir,"r");
			long lastline=File.length();
			File.close();
			FileReader fileRead = new FileReader(fdir);
			BufferedReader bufferReader = new BufferedReader(fileRead);
			Scanner scan = new Scanner(fdir);
			while(scan.hasNextLine())
			{
				if(scan.nextLine().contains(F))
					count++;
			}
			
			fileRead.close();
			bufferReader.close();

Ok your problem is that you need to read a big line of text and yoou're using a Scanner instead of a Buffered Reader. Buffered Readers, as the name implies, are made for long lines of text and can be size for scanning lines of the appropriate length.

After scanning a line, you may want to do something like parse the first comma (since they are comma separated values and I believe the first value you encounter would be considered a " " or "" due to the comma that exists before the data).

Create a new object of my class immediately after doing so. It would look something like this--

BufferedReader br = new BufferedReader(fileRead/*, int line size*/ );

// set length of line you will be reading via BufferedReader constructor

while(br.ready()){
     StringBuilder sb = new StringBuilder(br.readLine());
     
     // truncate or replace or remove unnecessary values like first comma and the last

     InspectionResults ir = new InspectionResults( sb.toString(). split(","));

// perform some action if a particular fail is acknowledged via my class
//store information if needed
}

By the way, this smells like a sub-module or a part of a company project >_>

Alex Edwards 321 Posting Shark

I am trying to create a program that generates random passwords using the characters A-Z and the numbers 0-9. It will also have an input of what you want the length of the password to be.

What I don't know how to do is to create a method to choose random, arbitrary characters/ numbers.

Are there any objects that specialize in selecting random characters?

You may simply have to create your own.

The concept isn't too hard though.

In Ascii A is 65. I'd assume Z would be 65 + 25 (or maybe 26... too tired to think really).
Once the number is chosen do a cast to the char type.

import java.util.*;

public class Generator{

	private Random rgen = new Random();
	private byte decision, numValue;
	private char charValue;

	public static void main(String... args){
		System.out.println(new Generator().gen(9));
	}

	public String gen(int length){
		StringBuilder sb = new StringBuilder();
		while(sb.length() < length){
			decision = (byte)rgen.nextInt(2);
			numValue = (byte)rgen.nextInt(10);
			charValue = (char)(rgen.nextInt(25) + 65);
			sb.append( (decision%2 == 0) ? ( charValue + "" ) : ( numValue + "") );
		}
		return sb.toString();
	}
}
Alex Edwards 321 Posting Shark

Here's and updated version of the class I gave you - should allow you to use the constants to retrieve data relative to pass-fail fields more leniently.

public class InspectionResults{

	public static final byte  HEIGHT_AVG_RESULT = 7,
							  HEIGHT_RANGE_RESULT = 12,
							  AREA_AVG_RESULT = 15,
							  AREA_RANGE_RESULT = 20,
							  VOLUME_AVG_RESULT = 23,
							  VOLUME_RANGE_RESULT = 28,
							  HAV_FAILED_FEATURE_RESULT = 35,
							  REG_FAILED_FEATURE_RESULT = 38,
							  BRIDGE_FAILED_FEATURE_RESULT = 41;
	private String retrievedData[];
	private boolean failed[];

	/**
	 * Constructs this InspectionResult with the data stored in the args.
	 * This class expects 44 values within the range of the args.
	 */
	public InspectionResults(String... args){
		retrievedData = args;
		boolean temp[] ={
			((retrievedData[7].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[12].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[15].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[20].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[23].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[28].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[35].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[38].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[41].equalsIgnoreCase("F")) ? true: false)
		};
		failed = temp;
	}

	/**
	 * Returns true if the given value has failed, returns false otherwise.
	 * It's preferred to use the constants defined within this class to get the
	 * desired information, and not regular ints.
	 */
	public boolean hasFailed(byte result) throws Exception{
		switch(result){
			case HEIGHT_AVG_RESULT:
				return failed[0];
			case HEIGHT_RANGE_RESULT:
				return failed[1];
			case AREA_AVG_RESULT:
				return failed[2];
			case AREA_RANGE_RESULT:
				return failed[3];
			case VOLUME_AVG_RESULT:
				return failed[4];
			case VOLUME_RANGE_RESULT:
				return failed[5];
			case HAV_FAILED_FEATURE_RESULT:
				return failed[6];
			case REG_FAILED_FEATURE_RESULT:
				return failed[7];
			case BRIDGE_FAILED_FEATURE_RESULT:
				return failed[8];
			default :
				throw new Exception("Attempt to access invalid result type! Use the Result Constants to avoid this error!");
		}
	}

	/**
	 * Returns the value next to the specified …
Alex Edwards 321 Posting Shark

I used this as a reference, it might make the code clearer in case it isn't already--

,SRFF File: D:\SPI Master Program List\200-34-02\200-34-02-B-01-R.SRF
,Panel Name: Panel Description
,Units: Microns

,Date,
Time,
PanelId,
Board,
Location,
Part,
Package,
HeightAvgResult, // 7
HeightAvg,
HeightAvgUpFail,
HeightAvgLowFail,
HeightAvgTarget,
HeightRangeResult, // 12
HeightRange,
HeightRangeMax,
AreaAvgResult, // 15
AreaAvg,
AreaAvgUpFail,
AreaAvgLowFail,
AreaAvgTarget,
AreaRangeResult, // 20
AreaRange,
AreaRangeMax,
VolumeAvgResult, // 23
VolumeAvg,
VolumeAvgUpFail,
VolumeAvgLowFail,
VolumeAvgTarget,
VolumeRangeResult, // 28
VolumeRange,
VolumeRangeMax,
XOffset,
YOffset,
Rotation,
Scaling,
HAVFailedFeatureResult, // 35
HAVFailedFeatures,
HAVFailedFeatureMax,
RegFailedFeatureResult, // 38
RegFailedFeatures,
RegFailedFeatureMax,
BridgeFailedFeatureResult, // 41
BridgeFailedFeatures,
BridgeFailedFeatureMax



,07/19/2008,
00:48:55,
#280,
Module 1 ,
IC2,
TSOP8,
SOP8_1,
F, // 7
138.539642,
238.000000,
84.000000,
140.000000,
P, // 12
9.226400,
140.000000,
P, // 15
427747.781250,
729933.140625,
243311.046875,
486622.090000,
P, // 20
26717.400391,
486622.093750,
P, // 23
60986780.000000,
122628772.800000,
34063548.000000,
68127092.600000,
P, // 28
3087930.000000,
68127096.000000,
-22.886625,
-23.317499,
-0.039985,
-0.131595,
P, // 35
0,
1,
P, // 38
0,
1,
P, // 41
0,
1

,07/19/2008,00:48:55,#280,Module 1 ,C38,0402,0402_1_3,P,131.077194,238.000000,84.000000,140.000000,P,12.636800,140.000000,P,265426.750000,470565.468750,156855.156250,313710.320000,P,5929.500000,313710.312500,P,36161180.000000,79054999.200000,21959722.000000,43919444.800000,P,2340260.000000,43919444.000000,-26.636499,-28.285000,-0.201710,-0.635564,P,0,1,P,0,1,P,0,1
,07/19/2008,00:48:55,#280,Module 1 ,C66,0402,0402_1_3,P,146.934555,238.000000,84.000000,140.000000,P,4.062300,140.000000,P,266860.500000,470565.468750,156855.156250,313710.320000,P,15511.000000,313710.312500,P,40048568.000000,79054999.200000,21959722.000000,43919444.800000,P,235260.000000,43919444.000000,-32.004501,-21.340000,-0.163571,-1.147347,P,0,1,P,0,1,P,0,1
Alex Edwards 321 Posting Shark

regarding
"so you will need to use a tokenizer for each line you examine to tokenize a line of value separated by commas."

I have that as well...

Then all you need to do is store the tokenized values in an array and use that array to create an object of the class listed above (remember, it's expecting an array of Strings of length 44 (from indices 0-43)).

Alex Edwards 321 Posting Shark

I've provided a class that should help you with this project. Examine it closely--

public class InspectionResults{

	public static final byte  HEIGHT_AVG_RESULT = 0,
							  HEIGHT_RANGE_RESULT = 1,
							  AREA_AVG_RESULT = 2,
							  AREA_RANGE_RESULT = 3,
							  VOLUME_AVG_RESULT = 4,
							  VOLUME_RANGE_RESULT = 5,
							  HAV_FAILED_FEATURE_RESULT = 6,
							  REG_FAILED_FEATURE_RESULT = 7,
							  BRIDGE_FAILED_FEATURE_RESULT = 8;
	private String retrievedData[];
	private boolean failed[];

	/**
	 * Constructs this InspectionResult with the data stored in the args.
	 * This class expects 44 values within the range of the args.
	 */
	public InspectionResults(String... args){
		retrievedData = args;
		boolean temp[] ={
			((retrievedData[7].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[12].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[15].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[20].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[23].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[28].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[35].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[38].equalsIgnoreCase("F")) ? true: false),
			((retrievedData[41].equalsIgnoreCase("F")) ? true: false)
		};
		failed = temp;
	}

	/**
	 * Returns true if the given value has failed, returns false otherwise.
	 * It's preferred to use the constants defined within this class to get the
	 * desired information, and not regular ints.
	 */
	public boolean hasFailed(byte result) throws Exception{
		if(result >= 0 && result < failed.length)
			return failed[result];
		else{
			throw new Exception("Attempt to access invalid result type! Use the Result Constants to avoid this error!");
		}
	}

	/**
	 * Returns the value next to the specified result.
	 */
	public String getAdjacentValue(byte result) throws Exception{
		if(result >= 0 && result < retrievedData.length - 1)
			return retrievedData[result + 1];
		else throw new Exception("Error! Attempt to access column with either no adjacent value or outside of data-range!");
	}

	/**
	 * Simply …
Alex Edwards 321 Posting Shark

There are a few ways we can do this.

In my opinion, the best way to do this is create a class that accepts these kind of values and stores them in appropriate data types (the types listed in each column in the first row (Date, time... etc), so it would be wise to use Strings).

For now we'll have 3 classes (maybe more) and have them hold all of the data we need.

When you read the lines from the file you'll store them in the classes the same way I mentioned before.

The classes toString method will be overridden to display all of the information for that particular line of data.

Now this may or may not complicate things but you can write methods that return if a particular column is a fail or not.

Now you can just use an iterator (or array of these classes) where each has different information and when a fail comes up upon invocation of the classes's method and it returns true you can display the toString method of the class that has the information you need.

This is probably the simplest way to do it. I can provide an example but it'll take time to sift through the different value per column.

Alex Edwards 321 Posting Shark

Ok I'd like to apologize - I didn't realize your values extended so far!

What exactly deems a unit as a failure? I see many "passes" values in each row. What is the condition for a unit to be a "fail?"

Alex Edwards 321 Posting Shark

If you need a line to be read from a particular value (like a date), you could do one of many things--

-(Hard) create a regular-expression to match dates (in MM/DD/YYYY format) and separate lines once a new date has been analyzed.
-(Easy) create a method that takes a String argument and determines if it is a date by checking for the appropriate characters in a date-format String literal.

--I'd store each line in an ArrayList<String>.

From there I'd probably tokenize each comma separated value and for the particular line then store it in a <String, ArrayList<String> > Map.

Go to my profile, then code snippets and look at "Search Engine" to get an idea of why you'd do this.

You can easily change the separation from a space to a comma in my code snippet.

From there you can use "p" or "f" keys to locate all Modules that passed or failed.

Since the ones of interest are ones that failed, simply retrieve the ArrayList<String> associated with the key "f", and write the information to a file or do what you want with it.

Hopefully this post was helpful.


Edit: If you want to do this an easier way it may help to invest time in a Swing Application and implement a JTable with the columns and rows of the information then have some kind of iterator to retrieve particular rows of information of interest based on …

Alex Edwards 321 Posting Shark

I know the answer was probably already given but I made this simple chatting program from scratch.

It is a test - it does NOT cover things such as recycling threads that are no longer used when a client disconnects, nor is there any true exception handling when a client disconnects.

Also there is a flag-type system in this practice program that disables the same input from being entered twice. That can easily be removed, but it was only implemented because the original program (modified) sent information to the Server as if it were a type of information-storage unit (or a very watered down database).

Here's the code.

import java.io.*; // for ObjectInputStream and ObjectOutputStream classes
import java.net.*; // for Socket and ServerSocket classes
import java.util.*; // for a Scanner object
import java.util.concurrent.*; // for Executors and ExecutorService classes

public class ChatServer{

	private ServerSocket ss;
	private Socket theClient[];
	private ObjectInputStream ois[];
	private ObjectOutputStream oos[];
	private ChatServer cs = this;
	private String information = "No information", oldInformation = "No information";
	private boolean update = false;
	private static int numClients = 0;
	private int index = 0;
	static{
		System.out.println("Setting up a test server...");
		System.out.println("How many clients would you like to connect to the server? ");
		numClients = new Scanner(System.in).nextInt();
	}
	private ExecutorService es;

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

		ChatServer myCS = new ChatServer();

		while(true){
			if(!myCS.information.equalsIgnoreCase(myCS.oldInformation)){
				myCS.oldInformation = new String(myCS.information);
				myCS.update = true;
			}

			for(ObjectOutputStream element : myCS.oos){
				if((element != null) && myCS.update){
					try{
						element.writeObject(myCS.information + "\n");
					}catch(Exception e){e.printStackTrace();} …
Alex Edwards 321 Posting Shark

I found some links that rendered Images to .gifs, which seemed useless at first but then I looked into the Image class and all of the "helper" classes for its methods.

I think I'll try to look into how to read the pixels on a screen into an array (or double array) of ints to produce a valid Image so that you can use the Java Image I/O API located here--

http://java.sun.com/j2se/1.4.2/docs/guide/imageio/spec/imageio_guideTOC.fm.html

--If successful then anything like a Graphics-rendered Image, or something that yields pixels on the screen (like the acm.GraphicsProgram GObjects, etc) can be written to a valid Image extension.

There are other links I found for converting strictly "Images" to .gif, etc but it's only useful if you can produce an Image out of the drawn unit.

http://www.gif4j.com/java-gif4j-pro-gif-image-encode-save.htm

http://www.acme.com/java/software/Acme.JPM.Encoders.GifEncoder.html

Hopefully someone can find a more reasonable solution to this though. I hate re-inventing the wheel!

VernonDozier commented: Thanks for the links. +5
Alex Edwards 321 Posting Shark

The concept isn't hard to understand. I don't take a class, but I researched it all myself and that isn't the problem I am having. My goal was to make 1 server, and run multiple clients. Not multiple servers, and I didn't even expand over the simple network yet.

Currently, I have one computer trying to connect all clients to a server.
IP is just local host, because I am only doing it on my own computer. What I don't get is why new threads aren't forming after one client connects.

I thought it was the server's job to start new threads, but okay, I will give it a go with the clients. Although the user before said something was incorrect with my server code.

I picked up Java on my own, and started around June, so I am not exactly sure what he meant by debugging. I mean, there are no errors in the program, so I don't exactly understand how debugging will aid me. It just runs the program for me.

What I do know is that if you want to make your program accept multiple Clients, and do so Concurrently, I'd assume that you would provide a Threaded Client that had a reference to a non-null server, where the non-null server would block and wait for the Client to connect.

I goofed - I meant multiple clients @_@

Alex Edwards 321 Posting Shark

If you were knowledgeable about how Servers operated in Java, you wouldn't have this problem.

Really, this is nothing more than I/O with either streams or packets.

The scenario can be one of many.

If you're the Server, you wait for incoming Clients. The server can support a finite number of clients at its current location. You specify a port number for the Server to use, and typically the port number is set to a number that is not in use and that is valid.

If you're a Client, you can connect to a Server. The Client specifies the IP address the Server is located at and the port number. The IP address, I suppose is the home-base of the Server and the port number is the valid port number the Server is using.

Yes, this means you can have multiple Servers on one computer (by specifying different ports at the same IP).

Yes this means you can have multiple Clients per Server (where each client's action is listened for by the Server).

I do not know if a pure Client-to-Client connection can be made (in theory it seems possible but I haven't tried it yet) but unless you're incredibly proficient with Client/Servers I wouldn't recommend it (biased opinion since I'm fairly new to this myself).

What I do know is that if you want to make your program accept multiple Servers, and do so Concurrently, I'd assume that you would provide …

Alex Edwards 321 Posting Shark

Here's the code in code-tags.

// caja_paquete_2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>


int main(int argc, char* argv[])
{
	using namespace std;

	char tipo_servicio, dia;

	float peso, total_a_pagar = 0, diferencia; // CALCULA PRECIO UNITARIO DE CADA COSA
	int total_paquete = 0, total_carta = 0; // TOTALES POR TIPO ENTREGA, incializadas
	int total_dia_sig_prioritario = 0, total_dia_sig_normal = 0, total_2_dias_o_mas = 0; // TOTALES POR DIA, ya inicializadas
	int totales_de_entregas = 0; // PARA QUE CALCULE EL TOTAL DE ENTREGAS, ya inicializadas
	float porcentaje_dia_sig_prioritario, porcentaje_dia_siguiente_normal, porcentaje_dos_dias_o_mas; // PORCENTAJES
	float dinero_recaudado = 0; // TOTAL DINERO RECAUDADO, ya inicializada
	float hora, hora_fin, hora_inicio; // HORA DEL DIA PARA CARGAR LAS COSAS

	cout << "Ingrese hora a la que empieza a trabajar (hh.mm): ";
	cin >> hora_inicio;
	cout << "\n";

	cout << " Ingrese la hora a la que termina de trabajar (hh.mm): ";
	cin >> hora_fin;
	cout << "\n";

	for (hora = hora_inicio; hora < hora_fin; hora++)
	{
		cout << " Ingrese tipo de servicio:" << "\n"; ////////
		cout << " 1 - Carta" << "\n"; ////////
		cout << " 2 - Paquete" << "\n"; //
		cin >> tipo_servicio; //
		//
		cout << " Ingrese tipo de entrega: " << "\n"; // primer ingreso
		cout << " 7 - Dia siguiente prioritario" << "\n"; // de datos
		cout << " 8 - Dia siguiente normal" << "\n"; //
		cout << " 9 - Dos dias o mas" << "\n"; //
		cin >> dia; …
sarehu commented: I don't want to be a meanie and give a neg rep, but if the original poster is unable to use code tags, just let him suffer! Life is easier that way. +1
Alex Edwards 321 Posting Shark

Ok, this is a long-shot but it may be possible to prevent the optimization by marking the modifier entering the function as volatile.

Again, I have no idea because this is something an individual told me about in class (since I didn't think code could EVER be skipped unless it was a condition, but apparently it can?), and also because we have no clue what your code looks like at the moment.

If I'm wrong, please correct me. I was stating this as a possibility without any real research behind it.

But at the moment, you're shooting wind at us - show us the code.

Alex Edwards 321 Posting Shark

Try posting your code.

From the looks of it, you're trying to use a conditional expression on a function that doesn't return anything.

Again, it's a wild-out-of-the-backside guess, so post your code so we can confirm the real issue.

Alex Edwards 321 Posting Shark

Code reposted without any attempt to compile. Done to make copying/pasting a bit easier.

// Main Program
//
#include "square.h" // Derived Class square
int main()
{

//*******************************************************************************
cout << "\t\t\t+y";
cout << "\n\t\t\t +";
cout << "\n\t\t\t +" << "\tpoint a" << "\t\t\t\tpoint b";
cout << "\n\t\t\t +" << "\t ax,ay" << "\t\t\t\t bx,by";
cout << "\n\t\t\t +";
cout << "\n\t\t\t +";
cout << "\n\t\t\t +" << "\t\t\t point e";
cout << "\n\t\t\t +" << "\t\t\t ex,ey";
cout << "\n\t\t\t +";
cout << "\n\t\t\t +";
cout << "\n\t\t\t +" << "\tpoint c" << "\t\t\t\tpoint d";
cout << "\n\t\t\t +" << "\t cx,cy" << "\t\t\t\t dx,dy";
cout << "\n\t\t\t +";
cout << "\n\t\t\t +";
cout << "\n\t\t\t + + + + + + + + + + + + + + + + +";
cout << "\n\t\t\t0.0" << "\t\t\t\t\t\t\t\t +x";
cout << "\n\t\t\t\tCartesian Coordinate System";
cout << "\n";
cout << "\nPoint a is upper left, b is upper right" << endl;
cout << "c is lower left, d if lower right" << endl;
cout << "\nSide a is ad, b is ba, c is bd and d is dc" << endl;
cout << "\nDiagonal a is cb, Diagonal b is ad" << endl;
cout << "************************************************************" << endl;
cout << "For a rectangle use points 4,12,11,5,-12,-4,-5,-11" << endl;
cout << "\nFor a square use points 1,9,8,2,-6,2,1,-5" << endl;
cout << "************************************************************" << endl;
Square Square_Results;

Square_Results.Square_Data();

return 0;

}
******************************************************************************************************************************************

File Name: quad.h

// Base Class Quadrilateral
//
// …
Alex Edwards 321 Posting Shark

Knowing how to program is far more important than being able to write a for loop in 20 different languages.

Being able to construct a meaningful program in any language counts.

Writing "hello world" or a bunch of typical homework assignments in many languages doesn't.

"Understanding the fundamental concept is the key."

That pretty much sums up your quote.

Alex Edwards 321 Posting Shark

Get rid of the paranthesis around set--

bool Sort::test()
{
	Sort set;
bool answer = false;
Alex Edwards 321 Posting Shark

By the way, you may want to use a Port number greater than 5000, as suggested by my Instructor.

Alex Edwards 321 Posting Shark

An I/O Exception is being thrown.

You may find it useful to look up the Socket class in the java.net API

http://java.sun.com/javase/6/docs/api/java/net/Socket.html

Here's a quote from the Socket constructor you're using--

Socket

public Socket(String host,
              int port)
       throws UnknownHostException,
              IOException

    Creates a stream socket and connects it to the specified port number on the named host.

    If the specified host is null it is the equivalent of specifying the address as InetAddress.getByName(null). In other words, it is equivalent to specifying an address of the loopback interface.

    If the application has specified a server socket factory, that factory's createSocketImpl method is called to create the actual socket implementation. Otherwise a "plain" socket is created.

    If there is a security manager, its checkConnect method is called with the host address and port as its arguments. This could result in a SecurityException.

    Parameters:
        host - the host name, or null for the loopback address.
        port - the port number. 
    Throws:
        UnknownHostException - if the IP address of the host could not be determined. 
        IOException - if an I/O error occurs when creating the socket. 
        SecurityException - if a security manager exists and its checkConnect method doesn't allow the operation.
    See Also:
        setSocketImplFactory(java.net.SocketImplFactory), SocketImpl, SocketImplFactory.createSocketImpl(), SecurityManager.checkConnect(java.lang.String, int)

You may also want to try looking at PrintWriter and BufferedReader classes, or simply print a stack trace of the error to see where it was thrown and what is responsible for throwing it.

Alex Edwards 321 Posting Shark

I think I figured out the problem.

The link http://nxgenesis.blogspot.com/2007/11/rules-virtual-base-class-and-side.html states that Virtual Base classes are constructed before any Non-virtual Base class.

"virtual base classes and inheritance offer a set of rules which every c++ programmar should be aware of. Specifically:
virtual base classes are constructed before all non-virtual base classes.
virtual base class's constructor is directly invoked by the most-derived class's constructor."

When Second is instantiated, before the First constructor can run the Lock constructor runs before the First and because of that it's as if Second is trying to directly access Lock's private method since Second is the most-derived class and attempts to directly call the Lock constructor.

As stated previously, Friendship isn't inherited so even though First is a friend of Lock and Second derives from First, Second isn't a friend of Lock.

I'm fairly certain that this is the reason.

Alex Edwards 321 Posting Shark

Friendship isn't inherited.

You declared a private constructor for the Lock class, in which it is only accessible either within that class or within a scope that has the right to access that Constructor.

Also because you've defined a constructor there is no default/dummy constructor provided.

Because First is a friend of Lock, First has the right to access Lock's private constructor.

Second does not inherit friendship of Lock despite the fact that Second derives from First.

In order to make the code work, you'll have to make Lock declare Second as a friend also--

#include <iostream>

using namespace std;

class Lock
{
	friend class First;
	friend class Second;
	private:
		Lock()
		{
		}
};

class First : virtual public Lock
{
	public:
		void function()
		{
			cout << "function1" << endl;
		}
};

class Second: public First
{
	public:
		void function2()
		{
			cout << "function2" << endl;
		}
};

int main()
{
	First f;
	f.function();

	Second s;
	s.function2();
	cin.get();
       return 0;
}
Alex Edwards 321 Posting Shark
void add(CTreeComponent* elem){
                         if(m_anzahl >= 0 && m_anzahl < 2)
                               m_children[m_anzahl++]=elem;
                         else std::cout << "ERROR! Element full." << std::endl;
             }
Alex Edwards 321 Posting Shark

I think it was your do-while loop. Maybe the program misinterpreted the return 0 and was looking for a while loop. Consider your code--

int main(void)
{
	do 
	{
		cout << "         Copyright 2001, Welcome to the Angle Finder Program.          " << endl;
		cout << "        This program is designed to take only numeric values.          " << endl;
		cout << "       Make certain you only input numbers. Otherwise it will exit.    " << endl;
		cout << " Please choose:  1 for the Hip/Valley Angle. "         << endl;
		cout << "                 2 for the Cricket Valley Angle. "     << endl;
		cout << "                 3 for the Ridge Angle "               << endl;
		cout << "                 0 to exit. "                        << endl;
		char ch;
		cin >> ch;

		switch (ch)
		{ 
			case '1' :      
					int HipValley(int& Rise1, int& Rise2, double& Eave, float& a); 
					// this is the Hip/Valley choice.
				break;

			case '2' :      
					int CricketValley(int& Rise1, int& Rise2, double& Eave, float& a, float& Width); 
					// this is the cricket valley choice.
				break;

			case '3' : 	
					int RidgeAngle(int& Rise1, int& Rise2); // this is the Ridge Angle choice.
				break;
				
			default : 
				return 0; // this will end the routine.
				
		} while (ch != 27); //while loops after switch statement
	} //no while loop here, where program expects it
	
	return 0; //line 186
}

Try this --

int main(void)
{
	do 
	{
		cout << "         Copyright 2001, Welcome to the Angle Finder Program.          " << endl;
		cout << "        This program is designed to …
Alex Edwards 321 Posting Shark

I agree. If it isn't a boolean value, I (almost) always state the condition explicitly.

C, and consequently C++, lend themselves to a lot of "shortcuts" in style. After a while you will get used to looking at the funny jumble of punctuation and understand it easily enough.

Some people, however, like to take it waaay past readability. Ever hear of the IOCCC? It's enough to make anyone's head swim.

Sure is fun though. :)

I noticed that programming consists of many challenges...

-Besides writing code, you must be able to use the code with practical applications.
-Besides writing code, you must relate the system you're using/building to something tangible.
-Making code precise, readable, modifiable (OOP), etc...
-Being able to understand how to implement things on a business level, technical level and realistic level...

the list goes on... but I am not discouraged. Making code readable is definitely a challenge in my opinion since everyone has their own style and way of seeing things.

One could say "sure my code may not be as readable as yours, but if someone isn't experienced enough to understand my code then they really shouldn't be reading it!"

Of course I disagree. I think code should first be made readable. If code can be shortened later and you're not working on the project with others then compress it to your delight.

This is an opinion coming from a rookie programmer, still working towards my …

Alex Edwards 321 Posting Shark

I guess what i really didn't understand was the
== 0
on the end of the first line and the following line
If(found)

I guess what is confusing me is the assignment and test for equality all on the same line and then the following line
If(found)
I don't understand what that line is doing.

Typically conditions (in C++) can be measured as true (1) or false (0) in a boolean expression. For example...

while(1){} //infinite while loop, 1 equals true.

if(found){} //if found equals zero, then this statement wont run.

I try to avoid these kind of conditions when I code. Whenever I want to make a statement like the above I'll usually do something like..

if(found != 0){} //much more readable

Consider the following example--

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    if(1) //evaluates to true so it will run
    {
         cout << "true!" << endl;
    }
    
    if(0) //evaluates to false, so it wont run
    {
         cout << "false" << endl;
    }
    
    if(-1) //it's not zero - most likely will run
    {
          cout << "?" << endl;
    }
    
    cin.get();
    return 0;
}

--if I'm missing something please let me know.

(Shifty eyes at Narue >_>)

Alex Edwards 321 Posting Shark

Odd, I can use time without ctime, which is why I gave the OP the suggestions.

Here's my example--

#include <iostream>

using namespace std;

int main(){
   srand(time(NULL));  
   cout << rand() << endl;
   cin.get();
   return 0;
}

Works fine.

Alex Edwards 321 Posting Shark

try using time without ctime -

ctime has a function called time_t time ( time_t * timer ) which most likely masks the time function defined in std

Alex Edwards 321 Posting Shark

Try-- srand( time(NULL) );

Alex Edwards 321 Posting Shark

OH! I get it now! What it's doing is it's going through all the elements in the array, and checking each of their coordinates against the current coordinates. It increments to move onto the next object in the array, and if none of them match, the loop breaks and it returns to the top. =)

Does that mean that I need to change the value of LOCATIONS to however many special squares I want? Like for different towns, etc.

Yes and as you do you'd, of course, have to create more location-structs to do so. Furthermore, you'll want to give each a unique string name.

After that you'll have to add additional conditions in your doSomething() method. If needed you can rename it then go to the for loop with loc in your movement-for-loop and change the name of that method to whatever you change doSomething() to.

I wasn't being at all creative, I just wanted it to make sense.

Alex Edwards 321 Posting Shark

Yep, it does, thank you. As far as I'm concerned there's no way in HELL I would have come up with that on my own.

Again though the one thing I'm trying to puzzle out the specifics of:

for(int i = 0; i < LOCATIONS; i++)
         {
          if(loc[i].x == currentX && loc[i].y == currentY)
          	loc[i].doSomething();
          }

The reasons I'm confused are the i < LOCATIONS and the loc stuff. What part of the array is loc accessing? Where do you get the value for LOCATIONS? And why does i even need to be incremented? Sorry to ask the same general question as before, I just want to make sure I'm actually understanding this.

Remember, LOCATIONS is a macro that is defined by the preprocessor definition #define LOCATIONS 2 so any time the compiler sees LOCATIONS it really is 2.

The loc variable is the array defined here--

Location loc[] = { Inn, Start};

--and Inn is located at indice 0 of the array and Start is at indice 1.

Notice that although the size of the array is 2, we never get to 2. The reason is because of how elements are accessed in the array. You can only access from 0- to- (n-1) indices where n is the size.

In the for loop, I'm iterating through the loc array by incrementing i.--

for(int i = 0; i < LOCATIONS; i++)
       	      {
          		if(loc[i].x == currentX && loc[i].y == currentY)
          		loc[i].doSomething();
              }

--if I didn't increment i, …

Alex Edwards 321 Posting Shark
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

	typedef struct SomeStruct
	{
		
        private:
        	string name;
  		
    
   	    public:
       	    int x, y;
       	    SomeStruct(const char *arg, int xLoc, int yLoc) : name(arg), x(xLoc), y(yLoc){}
	
       void doSomething(){
       		if(name== "ok"){
       			cout<<"Okay!";}
       		else if(name== "inn"){
       			cout<<"You're at an inn." << endl;}
   			else if(name== "start"){
   			 	cout<<"Start!" << endl;}
      			
    			
	    }
}Location;

#ifndef LOCATIONS
#define LOCATIONS 2
#endif

Location Inn("inn", 2, 4), Start("start", 0, 4);

Location loc[] = { Inn, Start};



int main()
{
    int currentX= 2, currentY=4; //placed the coordinates outside of the for loop block
	for(;;)
	{
    	
    	
    		
      
      
      int direction;
      		cout<<"What direction do you want to go?";
   			cin>> direction;
   			
   			switch(direction)
            {
   				case 1:
   					if(currentX == 10){
   						cout<<"\nYou cannot go any farther that that direction."<< endl;
   						break;}
					else{
        			currentX++; //changed
   					cout<<"\nYour coordinates are " << currentX <<"," << currentY <<"." << endl;
        			break;
 					}
 					
 				 case 2:
      				if(currentX ==1)
                    {
          				cout<<"\nYou cannot go any farther in that direction."<< endl;
          				break;
                    }
      				else
                    {
     					currentX--;//changed
     					cout<<"\nYour coordinates are " << currentX <<"," << currentY <<"." << endl;
        				break;
                    }
  				case 3:
					if(currentY== 10)
                    {
						cout<<"\nYou cannot go any farther that that direction."<< endl;
   						break;
                    }
					else
                    {
        			    currentY++;//changed
   					   cout<<"\nYour coordinates are " << currentX <<"," << currentY <<"." << endl;
        			    break;
                    }
        			
     			case 4:
					if(currentY==1)
                    {
						cout<<"\nYou cannot go any farther that that direction."<< endl;
   						break;
                    }
					else
                    {
        			   currentY--;//changed
	                   cout<<"\nYour coordinates are " << currentX <<"," << currentY <<"." << endl;
        			   break;
                    }
          
            
              
                  }
        
              for(int i = 0; i < LOCATIONS; i++)
       	      {
          		if(loc[i].x == currentX && loc[i].y == …
Alex Edwards 321 Posting Shark

This seems to work well so far--

#include <iostream>
using namespace std;

template <class T>
class list
{
	public:
		list();
		list(int);
		void insert(T);
		void remove();
		bool empty();
		void print();
		~list();

	private:	
		int size;	
		T *thelist;	
		int numinlist;	
		int newsize;
};

template <class T> list<T>::list() : size(5),newsize (size)		
{	
	thelist = new T[list::size];	
	numinlist=0;	
}

template <class T> list<T>::list(int in_size): size(in_size), newsize(size)	
{
	thelist = new T[in_size];
	numinlist=0;
}

template <class T> void list<T>::insert(T write)
{
	if(numinlist < list::size)
	{
		thelist[numinlist] = write;
		numinlist++;
		cout << "Number of items in the list is now"  << "  " << numinlist << endl;		
		cout << thelist[numinlist - 1] << " " << (numinlist - 1) << endl;
	}
	else
	{
		T *temp = new T[newsize];			//make new pointer temp
		for (int i = 0; i < newsize; i++)	//copy list to new pointer		
			{				
				temp[i] = thelist[i];                            
			}
			delete[] thelist;				//delete old pointer the list

		newsize++;							//increment size

		thelist = new T[newsize];		//make new pointer the list		
		for (int i = 0; i < (newsize-1); i++)	//copy temp to new pointer
			{
				thelist[i]= temp[i];
			}
			delete [] temp;					//delete temp

		thelist[newsize-1] = write;			
		numinlist++;
		cout << "Number of items in the list is now" << "  " << numinlist << endl;	
	}
}


template <class T> void list<T>::remove()	
{
         
	if(numinlist > 0)
	{
		T *temp = new T[newsize];			
		for (int i = 0; i < newsize; i++)		
			{				
			     temp[i] = thelist[i];                            
			}
			delete[] thelist;				

		newsize--;

		thelist = new T[newsize];			
		for (int i …
Alex Edwards 321 Posting Shark

Something like this for the removal code?

T *temp = new T[newsize];			
		for (int i = 0; i < newsize; i--)		
			{				
			temp[i] = thelist[i];                            
			}
			delete[] thelist;				

		newsize--;

		T *thelist = new T[newsize]; //error	
		for (int i = 0; i < (newsize-1); i--)	
			{
			     thelist[i]= temp[i];
			}
			delete [] temp;								
		numinlist--;
		cout << "Number of items in the list is now" << "  " << numinlist << endl;

Ok I think I found another error

In your remove you declare thelist as a local variable which masks the real value of thelist.

Alex Edwards 321 Posting Shark

Wow, I actually understood the majority of that code.

Things I didn't:

#
}Location;

#ifndef LOCATIONS
#define LOCATIONS 2
#endif

This part: Why do you have Location; outside the SomeStruct braces? Also the #indef part, I've seen it before but I'm not entirely sure what it means.

Also the part within the for loop. I think I understand the part within the if braces, but I just don't understand the increment part in the for arguments.

SomeStruct is just a typedef for objects of its kind. It's like how int is a type-definition for ints.

When you say int x, you are declaring that x is a reference-variable for int objects (well, to an extent. ints are really primitive types and not objects, but they have good enough similarities for this example). The same applies for Location - it's just a shorter, and a more understandable name for "SomeStruct" and performs the same way a SomeStruct object would.

The preprocessor directives are pretty self explanatory. You can define a macro with a value or with actual code or anything and anytime your project is built/compiled and that exact word is found in the code, it will replace the word with the code/value that it is associated with. Example...

#define DBL double

DBL x = 2.2;

Whats really happening is DBL is being replaced by the keyword double during compile time, and it is interpreted like this-- double x = 2.2; #ifndef means "If not defined, then..." - basically …

Alex Edwards 321 Posting Shark

I only made a small change - its commented in the code below--

#include <iostream>
using namespace std;

template <class T>
class list
{
	public:
		list();
		list(int);
		void insert(T);
		void remove();
		bool empty();
		void print();
		~list();

	private:	
		int size;	
		T *thelist;	
		int numinlist;	
		int newsize;
};

template <class T> list<T>::list() : size(5),newsize (size)		
{	
	thelist = new T[list::size];	
	numinlist=0;	
}

template <class T> list<T>::list(int in_size): size(in_size), newsize(size)	
{
	thelist = new T[in_size];
	numinlist=0;
}

template <class T> void list<T>::insert(T write)
{
	if(numinlist < list::size)
	{
		thelist[numinlist] = write;
		numinlist++;
		cout << "Number of items in the list is now"  << "  " << numinlist << endl;		
		cout << thelist[numinlist - 1] << " " << (numinlist - 1) << endl;
	}     //^^ above, changed it so it displayed the number that was just entered
	else
	{
		T *temp = new T[newsize];			//make new pointer temp
		for (int i = 0; i < newsize; i++)	//copy list to new pointer		
			{				
				temp[i] = thelist[i];                            
			}
			delete[] thelist;				//delete old pointer the list

		newsize++;							//increment size

		T *thelist = new T[newsize];		//make new pointer the list		
		for (int i = 0; i < (newsize-1); i++)	//copy temp to new pointer
			{
				thelist[i]= temp[i];
			}
			delete [] temp;					//delete temp

		thelist[newsize-1] = write;			
		numinlist++;
		cout << "Number of items in the list is now" << "  " << numinlist << endl;	
	}
}


template <class T> void list<T>::remove()	
{
	if(numinlist > 0)
	{
		numinlist--;
		cout << "Number of items in the list …
Alex Edwards 321 Posting Shark

Can you post what you have currently? I'm not getting the same error somehow.

Alex Edwards 321 Posting Shark

Consider the following code, where I store created Location objects in an array then reference each of them. Notice the new name-parameter I gave them. This will help reduce the amount of code you write in your movement loop, but it will increase the code in your Location structs--

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

typedef struct SomeStruct
{ 
       private:
              string name;
               
       public:
              int x, y;
              
              SomeStruct(const char *arg, int xLoc, int yLoc)
              : name(arg), x(xLoc), y(yLoc){}
              
              void doSomething()
              {
                   if(name == "ok")
                   {
                          cout << "Ok!" << endl;         
                   }
                   else if(name == "inn")
                   {
                          cout << "I'm an inn!" << endl;
                   }
                   else if(name == "start")
                   {
                          cout << "Starting!" << endl;
                   }
                   /*
                   else if...
                   */
                   else//final case
                   {
                        
                   }
                  
              }
}Location;

#ifndef LOCATIONS
#define LOCATIONS 2
#endif

Location Inn("inn", 2, 4), Start("start", 0, 4); 

Location loc[] = {  Inn,  Start  };


int main(int argc, char *argv[])
{
     int currentX = 2, currentY = 4; //notice that these are the inn's cooridnates

     //inside your movement-loop...

     for(int i = 0; i < LOCATIONS; i++)
     {
           if(loc[i].x == currentX && loc[i].y == currentY)
              loc[i].doSomething();
     }
     
    
     cin.get();
     return 0;
}

--There's also another way of doing this, but it involves mid-first-quarter C++ knowledge.

Ellisande commented: Had to wait 24 hours +1