tux4life 2,072 Postaholic

Define your setHireDate as follows and put it in your Employee class (remove the other one from ProductionWorker, my bad):

public void setHireDate(String date)
{
    hireDate = date;
}
tux4life 2,072 Postaholic

Please post the modified version of your code.

tux4life 2,072 Postaholic

please correct the problem with the Braces...

What do you mean by "problem with the braces"? Are you referring to code indentation?
If so, run your code through a code formatter / code beautifier.
If you're using an IDE look if there's an option available, most IDEs come with a code formatter.

tux4life 2,072 Postaholic

Instead of defining the name attribute as of type char *, I'd define it using the std::string type instead.

tux4life 2,072 Postaholic

It seems like you haven't defined a setHireDate() method in your ProductionWorker class.

tux4life 2,072 Postaholic

The exception message tells you exactly what the problem is: Multiple decimal separators in pattern "#.##0.00"
A decimal separator in this context is a dot, and your formatter pattern contains multiple (more than one, two to be precise) of these.

tux4life 2,072 Postaholic

File -> Import -> Existing Projects into Workspace (under General) -> Next
-> Select root directory: use the Browse... button and browse to the Workspace directory which contains the projects to be imported.
-> from the Projects list select the projects you want to import into the Workspace
(or use the Select All button to select all projects that are not yet into your workspace).

If you've copied your projects to your target Workspace already, and selected this Workspace as root directory, then click Finish.
Otherwise make sure that the Copy projects into workspace checkbox is checked.

tux4life 2,072 Postaholic

What is the type of your variable? Does the output file have to be human-readable?

tux4life 2,072 Postaholic

The following lines (lines 10-14 of TestProgram.java):

String[] arg = new String[4];
arg[0]="5";
arg[1]="7";
arg[2]="10";
arg[3]="12";

Can be compacted to one line as follows:

String[] arg = {"5", "7", "10", "12"};

In theory you could rewrite your summation() method more compact and efficient as follows:

public static void summation(int n)
{
    int sum = n * (n + 1) / 2;
    System.out.println("Sum: " + sum);
}

However, if this is an assignment to practice for loops, then you shouldn't do this.

tux4life 2,072 Postaholic

The following lines are causing compilation errors:

// lines 16-19
program.main(arg[0]); // line 16
program.main(arg[1]); // line 17
program.main(arg[2]); // line 18
program.main(arg[3]); // line 19

You declared arg as follows:

String[] arg = new String[4]; // arg is a reference to a String array

On lines 16-19 you index the array referred by arg, thus you get back a single element of type String.

You declared program as follows:

Sum program = new Sum();

On lines 16-19 you invoke the main method defined in class Sum.

Its signature looks like this:

public static void main(String[] args)

As you can see from the method signature, the parameter type args of that main is of type String[], but on lines 16-19 you passed in arguments that were of type String, this is causing the compiler error.

tux4life 2,072 Postaholic

I know I am nitpicking, but the backslashes need to be doubled in: mkdir("c:\one\two\three").

tux4life 2,072 Postaholic

I guess it is because the size of the return type of foo() is known at compile time, but I'm probably NOT correct on this.
I hope that someone else can clarify on this, I might learn something too then ;)

[EDIT]
Okay, apparently I was wrong

Standard C (ISO/IEC 9899:1999) section 6.5.3.4:

"The sizeof operator shall not be applied to an expression that has function type or an incomplete type, to the parenthesized name of such a type, or to an expression that designates a bit-field member."

(source: http://stackoverflow.com/questions/2666392/what-does-sizeof-function-name-return)
[/EDIT]

tux4life 2,072 Postaholic
tux4life 2,072 Postaholic

In general yes. The only one I know is some Swing components (eg Jist, JTable) have convenient constructors that accept Vectors of data but not ArrayLists (they really should have been updated to accept Lists, but hey ho).

True. But even then you could work around it by applying the Adapter design pattern and writing a ListModel implementation with a constructor that accepts a List.
No doubt that there's some work involved in that, but once written you can reuse it :)

xHellghostx commented: I agree with you guys.. Reusing the same functions or the constructors reduce the load on memory, and I know that most of modern devices have a lot of memory but when it comes to mobile devices we still need to pay attention to how much memory the process +0
tux4life 2,072 Postaholic

Now, this is an excellent example of why you should use type parameters: you are adding the array to your Vector instead of a String, and Java will happily allow it, since you are using a raw type.
Your compiler should've given you a warning about this.
As illustrated by your code you should NEVER ignore a compiler warning without having a good reason for doing so.

This is the compiler output you get when you declare without type parameters:

Note: VectorDemo.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Your declaration without type parameters looks like this:

Vector firstCourseDetail = new Vector();
Vector secondCourseDetail = new Vector(4);

Compiling with -Xlint:unchecked gives the following warnings:

VectorDemo.java:28: warning: [unchecked] unchecked call to add(E) as a member of
 the raw type Vector
            firstCourseDetail.add(courseName[counter]);
                                 ^
  where E is a type-variable:
    E extends Object declared in class Vector
VectorDemo.java:37: warning: [unchecked] unchecked call to add(E) as a member of
 the raw type Vector
            secondCourseDetail.add(courseName);
                                  ^
  where E is a type-variable:
    E extends Object declared in class Vector
2 warnings

The compiler is informing you here that it cannot guarantee you that the arguments you pass to the add() method will always be of the same type.
They could literally be everything that is an Object, and in Java every class conforms to the is an Object rule.
And that is what happened in your code. In Java an array is an Object.

xHellghostx commented: You sir deserve more likes.. That was the answer I wanted.. Some explanation of what's going on.. And I believe you are right, Vectors are rarely used.. But you know Instructors. +0
tux4life 2,072 Postaholic

That material is covered by any basic course in C. Do a Google search and/or check your course notes.

tux4life 2,072 Postaholic

Thank you, problem solved :)

tux4life 2,072 Postaholic

by Vector, I'm pretty sure he means : Vector.
when you iterate over your array, extract the elements one by one and add those to the vector.

Well, in that case my suggestions would still work. Since Vector implements the List interface as of Java 1.2, and since it has a constructor that takes in a Collection, the only thing (s)he needs to do is replace the ArrayList constructor calls by Vector constructor calls.

As of the Java 2 platform v1.2, this class was retrofitted to implement the List interface, making it a member of the Java Collections Framework. (Java API - Vector)

tux4life 2,072 Postaholic

Hello,

I'm mostly active in the Java forums these days, and often I find the desire to link to a method in the Java API, but the markdown syntax doesn't seem to handle the URL format quite well.

Here's an example of a URL that I was recently trying to link to:

http://docs.oracle.com/javase/6/docs/api/java/util/Arrays.html#asList(T...)

I guess you can easily notice that it breaks a valid URL.

tux4life 2,072 Postaholic

Is there anyway to move a string array elements to a vector and have an output that list these elements?

Let me ask again: What do you mean by vector?
Also please post the smallest compilable piece of code that demonstrates your problem with the exception.

tux4life 2,072 Postaholic

What exactly do you mean by vector? Do you mean the Vector class?

ArrayList is much more common nowadays, prefer that container class over Vector.

As stated in the API:

This class is roughly equivalent to Vector, except that it is unsynchronized.

Also you don't need a loop, you can use the Arrays utility class.

Here's how:

String[] sArr = {"A", "B", "C", "D", "E"};
List<String> list = Arrays.asList(sArr);

However the asList() method will return a fixed-size list that is backed by the array you pass in as the argument, this means that you cannot structurally modify [1] the returned list.
If this behaviour is required, you use it in conjunction with one of the ArrayList constructors that take in a Collection.

Here's how:

String[] sArr = {"A", "B", "C", "D", "E"};
List<String> list = new ArrayList<String>(Arrays.asList(sArr));

However if you want to do it manually using a loop, here are two ways:

Using a counter-controlled for loop:

String[] sArr = {"A", "B", "C", "D", "E"};
List<String> list = new ArrayList<String>();

for (int i = 0; i < sArr.length; i++)
    list.add(sArr[i]);

Using an enhanced for loop:

String[] sArr = {"A", "B", "C", "D", "E"};
List<String> list = new ArrayList<String>();

for (String s : sArr)
    list.add(s);

It won't work though.. It will through an exception.

As for your problem, you probably didn't initialize your reference to refer to an ArrayList (or something equivalent).
If …

tux4life 2,072 Postaholic

In addition: don't forget to deallocate the memory ;)

tux4life 2,072 Postaholic
tux4life 2,072 Postaholic

Add a PATH entry for the bin directory of your JDK installation.

For example if your JDK's bin directory is located at

C:\Program Files\Java\jdk1.7.0_10\bin

Then you'd add that to your PATH like this:

C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;
%SystemRoot%\system32;
%SystemRoot%;
%SystemRoot%\System32\Wbem;
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;
C:\Program Files (x86)\Toshiba\Bluetooth Toshiba Stack\sys\;
C:\Program Files (x86)\Toshiba\Bluetooth Toshiba Stack\sys\x64\;
c:\Program Files (x86)\Common Files\Ulead Systems\MPEG
; <-- semicolon here!
C:\Program Files\Java\jdk1.7.0_10\bin

It doesn't matter if there are references to directories with 32-bit binaries.

The changes will take effect if you open a new console window (that is: they don't take effect automatically for any console window that was opened prior to adjusting the PATH variable's value).

tux4life 2,072 Postaholic

What about an expression parser?

tux4life 2,072 Postaholic

@AD: toupper() and tolower() seem to return int and not char.
Also if I recall correctly C++ has new style headers: #include <cctype>.

tux4life 2,072 Postaholic

I copied your equals signature without thinking alot, but it doesn't seem to be a good idea to use an overload here.

tux4life 2,072 Postaholic

The problem is if you will do that every time recursevile it will be changed.

Yes, that's one of the reasons why I said "quick and dirty".
In your current version it is happening too though.

But I'm wondering, can't you create a private helper method that works on the node level?

Perhaps something like the following?

private boolean recursiveEquals(Node a, Node b) {
    // Make this your recursive method.
}

public boolean equals(StringList list) {
    return recursiveEquals(this._head, list._head);
}
tux4life 2,072 Postaholic

The quick and dirty way to fix it would probably be creating a separate instance variable to help in the recursion.

Edit: Bad approach, don't use it. See later posts.

tux4life 2,072 Postaholic

``You use class Stack, this is a legacy datastructure in Java, and it extends from Vector (another legacy datastructure - still used in Swing however), my personal recommendation would be not to use it. Prefer something more recent like ArrayDeque.

On an interesting note:

  • "This class is likely to be faster than Stack when used as a stack, and faster than LinkedList when used as a queue." (Java API - ArrayDeque))

  • "A more complete and consistent set of LIFO stack operations is provided by the Deque interface and its implementations, which should be used in preference to this class." (Java API - Stack)`

(Source: one of my earlier posts)

tux4life 2,072 Postaholic

Your algorithm is more complex than it should be, compare with the following:

iterativeInorder(node)
  parentStack = empty stack
  while not parentStack.isEmpty() or node != null
    if node != null then
      parentStack.push(node)
      node = node.left
    else
      node = parentStack.pop()
      visit(node)
      node = node.right

(Source: Tree Traversal - Wikipedia)

tux4life 2,072 Postaholic

Already looked here?

tux4life 2,072 Postaholic

Mike, it's almost like you can read my mind :)
While reading your previous post I was thinking of replacing the switch statement by callbacks.
Glad to see that idea confirmed.

tux4life 2,072 Postaholic

Yeh, but be careful for "micro-managing exceptions", sometimes you need to put a statement that doesn't throw an exception in a try block to guarantee that it won't execute if an exception is thrown from another statement that comes earlier in that try block.

However, apparently the OP deleted the code from his post (why?)...

tux4life 2,072 Postaholic

Apache POI, recommended two weeks ago in this post.

tux4life 2,072 Postaholic

The following Java books are on my shelf and I consider them as very good:

(haven't read these cover-to-cover though)

  • Kathy Sierra & Bert Bates - Head First Java: Introductory Java book

  • Elisabeth Freeman & Eric Freeman & K.S. & B.B. - Head First Design Patterns: Good read after you've gone through an introductory Java book.

  • Kathy Sierra & Bert Bates - SCJP Study Guide (now it is OCJP though, pick up this one after reading an introductory Java book, when you want to prepare for the certification exam)

  • Bruce Eckel - Thinking In Java (Intermediate, very thorough book about Java)

  • Cay Horstmann - Big Java (Introductory computer science book)

  • Cay Horstmann - Core Java Volume I and II (read after you've read an introductory book, Volume I is Intermediate, and Volume II is Intermediate - Advanced)

  • Deitel & Deitel - Java How To Program (introductory computer science book, similar to Big Java).

For reviews check amazon or another online seller.

I especially want to recommend the Core Java books. They are really useful because they cover a wide range of library features, using decent code examples.

More resources can be found in the Starting Java sticky thread.

<M/> commented: Thanks! +6
tux4life 2,072 Postaholic

Aaand.....What exactly do you mean by "not running properly"?

tux4life 2,072 Postaholic

I am wondering if the Builder pattern would be a candidate for being applied here?
Let me know your opinion.

tux4life 2,072 Postaholic

In the Java Language Specification I read the following:

"The result of a floating-point division is determined by the specification of IEEE arithmetic:"
...
"Division of a nonzero finite value by a zero results in a signed infinity."

(Source: JLS - 15.17.2 Division Operator)

tux4life 2,072 Postaholic

It's also possible using two HashSets, one that keeps track of the elements that occur only once, and another that keeps track of the elements that occur more than once.
At the end you check the size of the first HashSet, and if it is not empty you know that there are elements that occur only once :-)

I coded it in Java, but instead of the Java code I will post the pseudo-code for the algorithm:

SINGLE returns a boolean
    (true if there is at least one element in array that occurs only once,
     or false otherwise)

    array: an array of integers

single <- an empty set of integers
multiple <- an empty set of integers

for every integer i in array do:
    if single contains i then:
        remove i from single
        add i to multiple
    else if multiple does not contain i then:
        add i to single

return true if single is not empty, false otherwise

Have only tested it against the example in the first post.

tux4life 2,072 Postaholic

To be honest, I have never liked Java's Date and Calendar stuff, and luckily there's this available.

tux4life 2,072 Postaholic

Did you put a component scan into your beans configuration file?

More info:
http://static.springsource.org/spring/docs/3.0.0.M3/reference/html/ch04s12.html

tux4life 2,072 Postaholic

This is probably caused by your default locale setting for a decimal separator (which is probably a comma instead of a point).

More info:
http://docs.oracle.com/javase/6/docs/api/java/util/Scanner.html#localized-numbers

tux4life 2,072 Postaholic

Did this compile? This is the C forum.

void alterValueTwo (int& input)
tux4life 2,072 Postaholic

Read the rules and make sure you understand them. After that if you're still interested you could come back, reformulate your question and post your own attempt and point out which difficulties you are facing.

tux4life 2,072 Postaholic

@vijayan121:
Any specific reason why you chose to recurse on Problem 1 - Line 11? If the user enters a wrong input 5 times, then that function will return 6 times. I would suggest a do while to avoid that.

tux4life 2,072 Postaholic

Well, if you instantiate a Game object with the same initial state as the current game, then you've basically implemented a restart feature.
Don't forget to set your reference to the newly instantiated Game object then.

So, if the instantiation of a Game's initial state [1] done by calling the Game() constructor does not directly or indirectly depend on randomisation for intialising the initial state (or on something else that would make it possible for the initial state to end up differently than the original Game's initial state), then that could be a solution for your problem.

You can also apply object cloning, but you'll need to implement your own clone() method then.

[1] with Game state I mean the state in a Game object or in one of the objects that the Game relies on for it's logic.

tux4life 2,072 Postaholic

Your question seems pretty vague to me.
However you could keep a copy of the initial game state somewhere and restore it when the game needs to be restarted.
There are different ways to restore to the initial state of the game, and which one to pick depends on the way you've implemented your game.
(even though they might all work, there still is a difference in efficiency and ease of their implementation, that's the reason for why it depends on your implementation)

tux4life 2,072 Postaholic

Line 19 - scanf("%c",&ch);
This is overkill (reason).

tux4life 2,072 Postaholic

Try this next time.