PDA

View Full Version : I Hate Java Programming



rinny
10-09-2010, 09:01 PM
I just started this Java course after finishing the entry level C programming course.

Im having a hell of a time transferring over to this new language with just some simple code posted for my assignment.

After spending 4 fruitless hours trying to decipher how to put my concepts into count, Im here to ask for help.

Anyone have recommendations for people like me?

I've looked through the code and it seems like its all a bunch of pass by referencing but Im terrible at tracing this stuff.

For instance:
If I have an object filled with random numbers, how do I change this to a string so that I can use the Array.sort() function in Java?

All I want to do is sort the data in the object in ascending order.

Any insight is appreciated!

sabad66
10-09-2010, 09:07 PM
Might as well just post the assignment, it's hard to tell what you mean by your question.

Critical
10-09-2010, 09:10 PM
Java is the easiest language to pick-up in my opinion, just got to give it time.

Are the random numbers in the object stored in a int[] array? The Array.sort(...) method can take in an array, no need to convert it to a string, and sorts it in ascending order by default.

rinny
10-09-2010, 11:29 PM
Well the assignment is 5 pages of code so I wont post it. Im just releasing my frustration and hoping to find some assistance be it people or websites. Critical already offered to help which is great.

Gist of the code:
-Function called SetADT that contains an Object called bagarray


CODE (header in SetADT file):
private static Random rand = new Random();
private final int DEFAULT_CAPACITY = 100;
private final int NOT_FOUND = -1;
private int size;
private Object[] bagArray;

CODE:
public SetADT() {
size = 0;
bagArray = new Object[DEFAULT_CAPACITY];


-Fill this bagarray with random numbers
-Another function called


CODE
public SetADT(int capacity) {
size = 0;
bagArray = new Object[capacity];


-Fill this with random numbers
-Remove duplicates from the bags
-Print a union of the two combined to test and ensure duplicates removed

HERES WHERE I GET LOST:

-Add three methods: Difference method; Intersection method; Sort method

rinny
10-09-2010, 11:33 PM
There's much more code to that, 3 files linked together.

You can basically think of this as a Venn Diagram.

The union is Bag A and Bag B without duplicates

The Intersection is all of the duplicates.

The sort is ascending order of the union, SHOULD be easy.

The difference is Bag A without duplicates of Bag B AND Bag B without duplicates of Bag A.



This stuff should be easy, I just dont know how to work with Java and the conventions and extra functions that it has in library etc. If you have ideas of functions to use for any of this, Im all ears.

mazdavirgin
10-10-2010, 01:12 AM
How you managed to pass the C component of whatever class you are taking and are having trouble with Java is beyond me... Is this for something you are taking at SAIT?

Anyways all three functions are trivial to implement in Java even without using any features of the standard class library. Just implement bubble sort for the sort(google for the algorithm). The other two algorithms are simply nested loops one looking for collisions and the other looking for duplicates. It's like 10 lines or less of code for any of those functions

Anyways if you want to get creative you can always shove the arraylist into a set type object which disallows duplicates. Further you just had to cast the right type to the Object in order to be able to access the underlying values that should let you use the generic sort or you can choose to specify a comparator.

rinny
10-10-2010, 08:50 AM
Yup passed C with a B, only had issues with the last lab out of the 7 or so we did. I'm not the only one having issues with java, even the experienced who challenged and passed the C course are having issues.

Its hard to program a language when you don't necessarily know what's available to you in terms of features, and can't fully read the code written by someone else because you don't know the how some syntax works.

Its not SAIT, I'm actually out in Victoria. But big thanks to Critical who helped me out last night. I'm sure with time things will click for me and Java will be easier.

z2two
10-10-2010, 07:52 PM
practice, practice, practice. Being a cpsc major myself, you gotta keep programming, its all about developing a programmers mindset. good luck

boosted_Z
10-11-2010, 10:37 PM
To help build your Java/CPSC skills:

Do yourself a favour and build your fundamental skills. Don't cheat yourself by trying to hack and slash code you don't understand together.

Start every assignment by getting away from the computer (go outside!) and read it all, top to bottom. Now read it again while making notes of important things. For real, kill some trees, print it out, and write all over it.

Now find someone and brainstorm on a whiteboard or paper (make some friends!). Pseudo code as much of your solution as you can stand then write out as many lines of code as you can stand by hand. Seriously. It's important.

Now minimize SC2 and type that mother out. It should be pretty painless.

This isn't always possible, but it is well worth the time. You'll have a tan, friends, and learn so much more by writing it out, and researching methods/functions as you go.

Once you get better, use an IDE (Eclipse is great for Java).



Java API (SE 6, others available): http://download.oracle.com/javase/6/docs/api/

Eclipse: http://www.eclipse.org/