Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Does it have to be cigarette smoke, or would, say, secondhand fireplace smoke serve as well?

Oohhh, yeah, those filthy old fireplaces.. loitering about homes and smoking away with not a care in the world about the non-smokers! The nerve of those things!! :@

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Got it ... I think.
I put the Compactdisk class back in, and just modified it for the new array ... at least that is what I think I did.
It looks good, it runs well ( a few bugs to work out, but I think I have it)
Tell me what you think Ezzaral, I might have to put your name as a reference in this somewhere if I ever get it working! :o)
Just look at the name variable right now, that is all I have implimented at this point. Here is the main class.

Ok, I'll inline and comment a few things in your code below. It's very close, but inadvertently you have altered your loop to keep working on the same object over and over for several of the property sets. If you wish to use a simple variable to reference them, instead of cds[#], you will need to set the variable to point to the array entry you want to work with. If you are still confused by the cds[0].getName() style code, just remember that cds[] array contains all of your cd objects and by using cds[#] you can operate on the one you want exactly like you would any other variable that pointed to a cd (ie thisCompactdisk). Take a look at the parts I have changed in your code below.

import java.util.Scanner; //uses class Scanner

public class Inventory
{// begin class Inventory
    public static void main(String[] args)    
    {//begin …
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That depends on the operating system and the user permissions on that operating system...
On Windows it's indeed hard (but not imposssible) to remove an open file, on Linux it's quite possible.

Yes, that could be quite possible. All of our users for this app are on Windows, so no testing of the lock scheme has been done on Linux or Mac. In our case, it's not really a big concern since having multiple instances running will only cause them confusion, not critical application problems or a security risk.

It's good to know about the potential problems that might occur on they other OSs though, for future references. Thanks for the input :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You simply need an array of Compactdisk objects.

Compactdisk[] cds = new Compactdisk[5];

You can add a cd like so

cds[0] = new Compactdisk();

and you can still access the object by array reference like so:

cds[0].getName();

When working in a loop, you will want to use a counter variable for the array index:

int cdCount=0;
String nameInput = input.next();
while (!nameInput.equalsIgnoreCase("STOP")){
   cds[cdCount] = new Compactdisk();
   cds[cdCount].setName(nameInput);
... // set other properties

   cdCount++;
   System.out.print("Enter CD Name or STOP to Exit: ");
   nameInput = input.next();
} // end of while loop

Does that make more sense? You actually store the Compactdisk objects in the array, then you can access any method you want on them.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Also, it looks confusing. I'll give a pre-emptive sigh for the dozens of questions on this forum...

Yes, there is a lot of info in the Sun tutorial and that volume might actually a bit harder to understand the bare basics. You may want to look at this info first to get a quick take on the basics of JSP:
http://www.jsptut.com/

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

"Enterprise Edition" is just the name they gave to their collection of classes for web and "enterprise" services. They are separate from the Standard Edition (regular) java classes and require an application server (somewhat like a web server) architecture for their use. Tomcat is one such server that allows you to interact with servlets and JSP pages. It can be used by itself or integrated with a web server such as Apache.

In the section "About The Examples" (http://java.sun.com/javaee/5/docs/tutorial/doc/About5.html#wp87965 ), you will find links to download all you need to get started: J2SE, J2EE, and Netbeans (an development tool to write, deploy, and test your code).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Think about how the different entities interact. An inventory is simply a collection of things. Each of those things have properties such as a name, price, etc.

If you were using an inventory, what would it need to do? Perhaps list it's items, add a new item, remove an item. Arrays and other things like vectors allow you to manage a collection of things.

The things in the collection have various properties that describe them. To interact with each one, they provide methods to let you get or set their various properties and perhaps they may have other functions they can do. These methods define what you can do with a type of thing.

Keeping that in mind, consider how your inventory would keep track of many CDs, add a new CD, etc. A new CD object does not have any definition (or "state") until you set those properties on it.

I hope that helps a bit. I'm being a bit vague on purpose so that you will consider the parts of your program and how they should interact. Try to build them to act as real world entities, each with their own state and abilities.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

What class uses the CD class? A person or store may have many CDs and that would be an appropriate use for an array.

Compactdisk[] myCDs = new Compactdisk[100];
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try starting with Sun's J2EE tutorial trail:
http://java.sun.com/javaee/5/docs/tutorial/doc/

There is a lot of information there. Specifically you will want to focus on basic JSP and Servlets. Take a look through those and perhaps Google "JSP servlet tutorial" for some extra info. If you have specific questions that you can't seem to get past then feel free to post them here for help :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That was part of my misunderstanding. I was going to create an array for each variable. (I thought each variable would be a different type and require its own array).
Now I understand that I can use a single array for all field types. I just left in named cdaName because that made the most sence to me, it will be an array of cd information.
My problem now is that I do not understand where to put this array. I want it to be populated with information input from the user, so I think I need to keep all my get and set code, but where does my array tie in? Do I need to create another class completley?
I think my array should look something like

String cdaName[]= new String{cdName, price, itemno, nstock};

but I cannot find any examples of such a beast for me to learn and build off of.

Actually, that is not going to help you in the way that you think it might. With the array you have, you will have string entries for the name of each field - but no values for them. Now, you could use a two dimensional array to allow for the name/value pair, but how does that make your class more functional? It doesn't. It just makes it more confusing to use.

In short, there is no compelling reason for you to combine all your variables into an array at this point. Keep them as …

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Glad it works for you. Keep in mind the points jwenting mentioned though. I don't think you will have those issues with the code I pasted, but testing is your best friend.

Be sure you release the lock and close the channel when you no longer need them:

lock.release();
lockChannel.close();
lockFile.delete();
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Why do you wish to use an array for cd name? A cd only has a single name.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

ppl i have no idea wut u ppl are talkin about but if it is smokin then i have to say that i love it i smoke pipe weed dont see me as a nerd the pc is my 2nd hobby my first is babes ;) and cause of babes i smoke :@ but i am loving it hahahha so no body talks trash about smokin yall understand u bit***s

Was that English?

christina>you commented: hahaha +20
EnderX commented: A variation on the English Slanguage, maybe. +4
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Take another look at the line you have bolded - the return line. Does it match any variable in your program?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

lockfiles are extremely risky.
What if the running instance of the application crashes (or the computer it's running on crashes which has the same effect)?

The lockfile will still be there when you start it again, causing it to never start until the file is manually removed.

Yes, depending on how you implement it, that is a risk. My code opens a FileChannel and obtains a lock with tryLock(). If the app crashes, this lock is lost. It deletes the existing lock file if one is present, so it doesn't really care if a previous lock was already there. I haven't been able to break it so far, but that doesn't mean it's bulletproof :)

try {
    lockFile = new File( env , "transport.lock");
    if (lockFile.exists())
        lockFile.delete();
    FileOutputStream lockFileOS = new FileOutputStream(lockFile);
    lockFileOS.close();
    lockChannel = new RandomAccessFile(lockFile,"rw").getChannel();
    lock = lockChannel.tryLock();
    if (lock==null) throw new Exception("Unable to obtain lock");
} catch (Exception e) {
    JOptionPane.showMessageDialog(this,"An instance of Job Selector is already running.","Warning",JOptionPane.WARNING_MESSAGE);
    e.printStackTrace();
    System.exit(0);
}

And what if some smartass finds out where the file is and removes it while the application is running? Now he can run as many instances as he wants side by side.

The file can't be deleted due to the lock in this case.

It works for us, but then I never though about the socket binding thing, so that may be an even easier and more well-behaved way to go about it.:)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can use a lock file in your base directory as well. We use that here at work for one particular app that should only be running a single instance.

I hadn't thought about a socket binding though. Interesting alternative.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Still have a classpath problem then.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Like I said... smoking can be beneficial if used in the right manner.

But most of the time in most people, the outcome is never good.

Well, I wouldn't even say the smoking is beneficial so much as the nicotine component has some beneficial properties. A delivery mechanism other than smoking would definitely be advisable.

(I'm a smoker who harbors no illusion that it's not bad for me)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, you are right that it isn't the most efficient way, but if your table is small and the performance is fine then stick with what works for you :) You can always come back to it if the performance becomes an issue.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

JavaMail is available here:
http://java.sun.com/products/javamail/index.jsp

However, from the following search results:
http://www.google.com/search?hl=en&q=+site:publib.boulder.ibm.com+javamail+websphere
It seems that WebSphere includes JavaMail. Many of the links above are references to older versions, so I am not sure if they have changed any of that, but they are probably worth checking out. It may be a simple alteration to your application classpath to find the jars.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Originally Posted by joshSCH http://www.daniweb.com/forums/myimages/buttons/viewpost.gif
Okay, perhaps you guys are taking this a little bit out of context. A little bit of anything is good. Ever heard of vaccines? Injecting a little bit of a virus into a human is enough to enable the human to build a sufficient immune response. If we look at things at such a microscopic level then just about EVERYTHING is good for you.

Finally.
Thank God for common sense.

Well of course not. It's a virus.

umm ....

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I highly doubt a little bit of Ebola is good for you.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

yeah but thats the case with everything

next peoplem will say that a little heroin is good, but too much....

you get my drift.

Perhaps a little heroin is good. I don't know that studies have shown that it is not. Obviously though, given the extremely addictive nature of heroin, most are not going to use it in moderation and the excess may kill them.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Where can i get bot for Silkroad ?

This is a Comp Sci forum - not Bots-R-Us. Look for your cheating software elsewhere please.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Did you specify the main class?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just read the "tools" part of your JDK documentation on how to use the jar utility. The form of the command is going to vary with how you want to jar or unjar your files.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Since you are using DefaultTableModel, take a look at the addRow() and insertRow() methods. They both take the row as a Vector, not an Object[] array row, but you could work around that easily.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Those methods stay in the Employee class. You use them to set the values of the properties you have defined for the Employee. They don't replace the Scanner. The Scanner allows you to collect the input from the user. That input is then used to set the property values with your set() methods. Perhaps it was confusing that I inlined the method that reads the Scanner input. This might be more clear:

Scanner input = new Scanner(System.in);

double inputRate = 0;
System.out.print("Enter Employee's Hourly Pay Rate: "); // prompt for rate
inputRate = input.nextDouble();
thisEmployee.setRate( inputRate ); // rate input

The setXX() methods allow you to set those values on the Employee that you are currently working with, so they are part of the Employee class definition.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, you're correct in your suspicion - you have the method displayMessage() declared inside your main method. You need to take that method declaration out, but leave the code to read from the Scanner and use your setXXX() methods to set the properties on the Employee object that you have created. Also, don't create a new Employee with your default constructor, but instead read in the name and create the Employee with the constructor that takes a name parameter :

Scanner newEname = new Scanner(System.in);
        System.out.print("Enter Employee Name or STOP to Exit: ");
        String name = newEname.nextLine();
        
        Employee thisEmployee = new Employee(name);

        while (!(name).equalsIgnoreCase("STOP"))
        {// begin main While
                        // you don't actually need a new Scanner here - you have one from above
                        Scanner input = new Scanner(System.in);

                System.out.print("Enter Employee's Hourly Pay Rate: "); // prompt for rate
                thisEmployee.setRate( input.nextDouble() ); // rate input from user.
... // the rest of your code
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

How long have you been doing this? Just so I can get an idea of how long I have to go before I can hope to become somewhat competent.

I've been using Java about 4 years now on custom in-house software at work, plus another 8 years with different languages before that :)

No worries though, you certainly don't need that much time to become competent with Java. Just keep at it and it will come. As a software developer, you never stop learning - you just learn to learn more easily :) Eventually you become very familiar with the structural concepts and then it's merely a matter of figuring out how to incorporate the various APIs available to you and apply them to the task at hand.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I am getting "illegal start of expression" for this line

public void displayMessage();

I have checked all my braces, all my semi colons, everything looks right to me. What am I doing wrong?

Here you have put a semicolon at the end of the method declaration, before the brace which begins the actual code. The semicolon ends a statement, so it interprets this as a single statement which makes no sense to it. Remove the semicolon so your method is properly defined.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I put in the other three; rate, hours, and result.
I had to comment out the first line in each one,

// snipped

otherwise I got an incompatible type error. It wanted double in there somehwere, I do not know why or where. Why does it work with the line commented out?

You are trying to initialize numeric values with an empty string "". Initialize those to valid numeric values, such as

public double rate = 0.0;

You don't need to put those initializations inside braces (blocks), you can initialize when you declare them as I did above;

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You haven't declared employeeName yet in your class. You have

public char eName;

which should be changed to

public String employeeName;

Also, getEmployeeName() should return employeeName.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

As far as the cmd output and exit codes, see the thread that peter_budo posted a link to above. As for the loop, you can run it in the following loop based on exit code for success:

Runtime runTime = Runtime.getRuntime();
try{
    int exitCode = 0;
    for ( int runCount=0; runCount<5 && exitCode==0; runCount++ ) {
        // set whatever you need in properties file here
        
        Process cmdProcess = runTime.exec("cmd /c start D:/Test/run.cmd");
        cmdProcess.waitFor();
        exitCode = cmdProcess.exitValue();   // will be 0 if successful
    }
    // if exitCode != 0 here, your process failed, so do whatever you need to do for that case
} catch(Exception e){
    
}

Note: This will still start five command windows, you can't get around that, but each will close before the other opens since you are using waitFor() and checking the exit value;

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Actually, the constructor does have a return type - it is an object instance of your class. That is it's entire purpose. Your first "constructor":

public void Employee(char newEname)
        { // initialize name of employee
        eName = newEname;
        }

wasn't really a constructor. It was a method called Employee. The reason your code worked previously is that when no constructor is specified at all, the compiler will provide a default no-argument constructor for the class. If you specify a constructor, as you did by removing the return type, you no longer had the default Employee() constructor and so it failed. If you want to create the employee with no parameter to the constructor, you will need to give it a default constructor like so:

public Employee(){
    // whatever you need to do to set up the object
}

Actually though, you probably want the main program to obtain the name of the employee (as you do in the displayMessage() method) and pass that name to your constructor with the name parameter. The name also should be a string, since char will only hold a single character.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Proper use of code tags? Or should I place them throughout my code, perhaps at each method or something?

The only thing I am thinking about it cleaning up this code somewhat. Separating it in to more methods, using some set and get statements for rate, hours, and all that so I can place up in the main class. Is that good technique? Is it even possible without creating more sub classes?

Yes, those code tags are fine :) You don't need to break out all of the methods, code tags just preserve the formatting so indentation and such remains visible and the blocks are easily seen.

You could certainly add methods to get and set other properties on your Employee, you don't need any subclasses for that. If you add getters and setters for those properties, make the variables private to the class.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

int value = p, q? 1 : 0;

This statement would not quite work (as the compiler will tell you rather quickly), instead something like this would be needed:

int intP = p ? 1 : 0;
int intQ = q ? 1: 0;

(I just arbitrarily used the variable intP for the integer value of p, so don't be confused by the double occurrence of int :) )

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

A tertiary expression is evaluated like so:
(logical expression) ? (value if true) : (value if false)
So given your values of p and q, you can use them each with an expression such as

p ? 1 : 0
q ? 1 : 0

Tertiary expressions can be used most anywhere that a variable could be used, though in many cases you will need to surround them with parens to force evaluation before the rest of the expression. Example:

p = false; q = false
  System.out.print((p ? 1 : 0) + "\t" + (q ? 1 : 0) + "\t");

I am not necessarily saying that is the best way to accomplish changing your program to use 1 and 0 instead of true and false, but tertiary expressions are a way to return 2 different values based upon a logical expression.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I think that is best up to you to decide for the exercise.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Have you browsed the forums at all? This question is asked all the time in one form or another.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just use a tertiary expresssion:
int value = booleanVar ? 1 : 0;

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Take a look at the "icobundle" utility here:
http://www.telegraphics.com.au/sw/

I think it will do what you want.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No. Random letters will rarely if ever generate executable code.

Though one thousand monkeys typing on one thousand typewriters...
:)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

But it's war! Look at Iraq, and the war on terror.. we have not done as well as we though. Why? Mostly because the damn media is there defiling the troops. They always portray everything in a negative light. If we were to send the media away, and let the military handle things their way.. who knows- maybe the war would be over tomorrow. They could torture, kill, destroy anything they wanted.. eventually we would destroy the terrorist networks.

Hook, line, and sinker.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It is impossible for us to do anything about the CIA, though. They are a secret organization run by the government. So long as the government is kept in check, all of its programs should follow into place as well.

I basically just believe the government should be constantly checked by the people to ensure that no civil liberties are lost. The CIA, however, is trying to ensure the American citizens are not harmed by other nations. I am a strong believer of allowing the military (including the CIA, NSA, etc.) to do whatever necessary in order to ensure our safety. If the military is torturing other people b/c they believe those people may be a threat to national security then so be it. I don't find anything wrong with that at all (unless the people being tortured are American citizens). The CIA should be allowed to do whatever they want to accomplish their goal (within a limited boundary, of course).

I don't think I am explaining my views efficiently.. they are not contradictory. I just view the CIA and government operating in different realms of limitation.

The people picked up off the streets, held without charges for long periods of time, and interrogated mercilessly when they have done nothing wrong whatsoever may tend to disagree with you.

I am not saying the agencies should be prevented from making investigations effectively. I am saying that giving them a blank check do "do whatever the hell they want" in the …

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well i can't spell first off :P
And most smokers are genuine nice people like yourself, who do care for others around them, but a proportion of smokers are just plane idiots who don't give a care in the world, and when they puff the smoke out, it goes right into your face. It's those sort of people that i just want to punch in the face quite honestly! And i'm not violent!

I understand that and figured that you did as well. I posted to call attention to the overly broad generalization.

Personally, I will not smoke in the home or car of a non-smoker even when they tell me it's fine to do so. I decline to sit in the smoking section of a restaurant when I am with non-smokers. I can wait until I am outside. I don't think this makes me special or a saint - I think it's just consideration of those around me.

Lack of consideration is a human trait - not a side effect of smoking.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I'm not saying the CIA can't become corrupt.. only that b/c they are so secretive, the American citizens would not even know if any CIA members did anything against the law. Because of this secrecy, it is pointless to suggest their corruptness... we can only hope that they are still on our side ;)

It is far from pointless to question things done in secret and merely hoping they are doing the right thing does little to ensure it.

I would just encourage you to think about the contradictory nature of the two positions you espoused. They cannot work together. Oversight and accountability are inherently necessary to preserve the freedoms you value.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

To put it in a way that you can understand it better: The effects of government decisions are directly related to all citizens, and can easily be traced to the government. The CIA operates under anonymity, and thus, its decisions do not affect us all, and neither can they be traced directly to th CIA.

I understand it perfectly, which is why I am trying to get you to understand the innate conflict of your statements.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So, an agency that is directly under the control of the government - and no one knows what that agency does - should be able to do whatever they like.

Re-read your post and tell me if that is not exactly what you state.