LOGO
General Discussion Undecided where to post - do it here.

Reply to Thread New Thread
Old 10-19-2010, 07:04 PM   #1
Signabeademia

Join Date
Nov 2005
Posts
379
Senior Member
Default Programming question
For starters, you want a class member
Code:
Code
int index = 0;

and change those to
Code:
Code
ptArray[index][0] = timeValue; ptArray[index][1] = paymentValue; index++;

Regarding your TextArea issue, you can't do:

Code:
Code
textarea.append(ptArray);

textarea.append takes a string as an argument. When you cast an object to a string (arrays are a subclass of Object), if there isn't a specific function for converting that object to a string it just prints out "gibberish" (actually, it's something like the memory address of the object IIRC, it should look like "[I@10b62c9"). You want to do something like the following:

Code:
Code
for (int i = 0; i < index; i++) textarea.append("time: " + ptArray[i][0] + "; payment: " + ptArray[i][1] + "\n");

Signabeademia is offline


Old 10-19-2010, 07:25 PM   #2
Cgnebksb

Join Date
Oct 2005
Posts
357
Senior Member
Default
Your for loop condition is backwards. The loop is running forever.

Why are you appending them to reportArea every time the enter button is pressed? I thought you only wanted to do that when the report was generated? If you append to reportArea each time, you don't want the for loop, you just want to say:

Code:
Code
reportArea.append("Time: " + ptArray[index][0]...); index++;

and of course remove the earlier index++;
Cgnebksb is offline


Old 10-19-2010, 07:54 PM   #3
Nzmoafzn

Join Date
Oct 2005
Posts
464
Senior Member
Default
And here I was just about to suggest you simply modify the phase variance.
Nzmoafzn is offline


Old 10-19-2010, 09:58 PM   #4
georgshult

Join Date
Oct 2005
Posts
552
Senior Member
Default
Code:
Code
int index = 0; ... ptArray[index][0] = timeValue; ptArray[index][1] = paymentValue; index++;

index is being set to zero each time that runs so it will always be zero when enterActionPerformed is run. it needs to be handled differently, and since you're doing java you should go with Kuci's suggestion.
georgshult is offline


Old 10-19-2010, 11:01 PM   #5
DoniandaCoado

Join Date
Oct 2005
Posts
518
Senior Member
Default
Sorry, I didn't catch that in your rewrite earlier. "int index = 0" is a class member, i.e. you define it up at the top of the class rather than inside a method.
DoniandaCoado is offline


Old 10-19-2010, 11:35 PM   #6
trubreTab

Join Date
Oct 2005
Posts
520
Senior Member
Default
I really hate Java, but I bet learning Python will be a breeze after all this.
I won't speak for anyone else but after a while I started to appreciate Java. It seems like it's really limiting and annoying when you're doing things that are straightforward but it just adds structure and sense to large programs that someone else wrote. As an example, there was one time when I spent 40 minutes searching a PHP program I wrote trying to find out why a value was turning null and throwing an exception until I discovered that I had misspelled the variable $current in a function call as $curent. In Java, it would have just said that curent had never been defined anywhere and fixing the bug would have taken more like 4 seconds. But when I was taking classes that were taught in Java, I hated it.

That said, there's the right tool for the right job and I think Python should be very easy to learn, I learned the basics over a weekend and just picked up the more advanced stuff as I encountered it. Python's a breeze.
trubreTab is offline


Old 10-20-2010, 12:00 AM   #7
NodePark

Join Date
Oct 2005
Posts
500
Senior Member
Default
The way they are teaching you Java is very, very stupid. The way your TutorUI class works is a reasonably advanced application of object-oriented programming, and you'd be better-served by learning the principles of OOP first and then why TutorUI is designed the way it is.
NodePark is offline


Old 10-20-2010, 12:12 AM   #8
Charryith

Join Date
Oct 2005
Location
Italy
Posts
587
Senior Member
Default
I quite like Java, from a language standpoint. It's great for writing console apps, web apps, etc.

C# is still far better.
Charryith is offline


Old 10-20-2010, 12:19 AM   #9
cmruloah

Join Date
Oct 2005
Posts
490
Senior Member
Default
Err, don't even bother to take up C++, C#, Python or for that sake VB before you can handle multidimensional arrays.
cmruloah is offline


Old 10-20-2010, 12:27 AM   #10
rozneesitcn

Join Date
Nov 2005
Posts
455
Senior Member
Default
The book I'm using is called Big Java third edition. You can download it if you want to take a look at it, that's how I got mine. It's from 2007 I think. Also, that link is much clearer and much more to the point. From what I have read so far am I correct in understanding that there is no way to have an undefined first parameter in the array? Which would explain why everyone first asks if I must use a multidimensional array. I went ahead and set it to 5 and just said **** it so I can move on to writing the calculations and other stuff they want. If they don't like it they can tell me later.
rozneesitcn is offline


Old 10-20-2010, 01:32 AM   #11
gettoblaster

Join Date
Oct 2005
Posts
634
Senior Member
Default
I could use pages on what has become obsolete in those 25 years I have been in the business - consider this as a lesson of your future
gettoblaster is offline


Old 10-20-2010, 02:08 AM   #12
bahrain41

Join Date
Oct 2005
Posts
419
Senior Member
Default
I could use pages on what has become obsolete in those 25 years I have been in the business - consider this as a lesson of your future
The difference here is that the arrays are actually a literal and a crucial feature and the fact that they've been deprecated for something with astonishingly uglier syntax is obnoxious.
bahrain41 is offline


Old 10-20-2010, 02:11 AM   #13
Cyncceply

Join Date
Oct 2005
Posts
495
Senior Member
Default
The difference here is that the arrays are actually a literal and a crucial feature and the fact that they've been deprecated for something with astonishingly uglier syntax is obnoxious.
Actually, arrays kind of suck. It's hard to come up with a case where I'd actually want to use them if a halfway decent collections library is available.
Cyncceply is offline


Old 10-20-2010, 02:57 AM   #14
PZXjoe

Join Date
Oct 2005
Posts
655
Senior Member
Default
They aren't more efficient at handling arrays of unknown sizes, they just hide the ickiness of it all behind a veneer of convenient syntax.
PZXjoe is offline


Old 10-20-2010, 03:09 AM   #15
2swasseneons

Join Date
Oct 2005
Posts
385
Senior Member
Default
I said that if you know the limits then arrays are more efficient - knowing the limits mean that you don't expect them to change.

Dude, we're talking about ****ing managed code. ArrayList and equivalents are not going to be measurably "less efficient" in any plausible use case.

Do we really have to play the "BlackCat defends some dumb comment he made long past the point that it's obvious to everyone else that he's wrong" game again?

I don't use fixed arrays today because CPU speed easily can handle it, but my first "PC" was a 2 MHz 64 kb (OS took a third) and if anyone had suggested using dynamic versus static arrays, they would probably be fired.

asd;lfkjdsaf;
the only performance difference between a "dynamic array" and a regular array is the overhead of a method call.
2swasseneons is offline


Old 10-20-2010, 03:45 AM   #16
CO2490pL

Join Date
Oct 2005
Posts
437
Senior Member
Default
Holy ****, you are dumb.

HERE ARE THE RELEVANT PIECES OF CODE FROM ARRAYLIST.JAVA IN THE ACTUAL ****ING JDK VERSION 6.18:

Code:
Code
/* * @(#)ArrayList.java    1.56 06/04/21 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */  package java.util;  public class ArrayList {     private Object[] elementData;      private int size;      public ArrayList(int initialCapacity) {         this.elementData = new Object[initialCapacity];     }      public E get(int index) {         return (E) elementData[index];     }      public void set(int index, E element) {         elementData[index] = element;     }      public boolean add(E e) {         ensureCapacity(size + 1);         elementData[size++] = e;         return true;     }      public void ensureCapacity(int minCapacity) {         int oldCapacity = elementData.length;         if (minCapacity > oldCapacity) {             int newCapacity = (oldCapacity * 3)/2 + 1;             if (newCapacity < minCapacity) newCapacity = minCapacity;             // minCapacity is usually close to size, so this is a win:             elementData = Arrays.copyOf(elementData, newCapacity);         }     }      public E remove(int index) {         E oldValue = (E) elementData[index];          int numMoved = size - index - 1;         if (numMoved > 0) System.arraycopy(elementData, index+1, elementData, index, numMoved);         elementData[--size] = null; // Let gc do its work         return oldValue;     } }

It is literally a thin shim over a Java array.
CO2490pL is offline


Old 10-20-2010, 04:10 AM   #17
glazgoR@

Join Date
Oct 2005
Posts
529
Senior Member
Default
Those would not be any different.

Strings are a bit special actually, as I recall. They aren't like C's char* arrays. But Java string literals are adequate.
glazgoR@ is offline


Old 10-20-2010, 04:12 AM   #18
accotMask17

Join Date
Nov 2005
Posts
333
Senior Member
Default
It is literally a thin shim over a Java array.
Really? Okay, I was under the false impression that they were some special structure or whatnot.

The most annoying thing about string arrays is Java's refusal to overload == to test string equality as opposed to just comparing the references. I don't know, I feel like they should have just made an exception for strings.
accotMask17 is offline


Old 10-20-2010, 04:13 AM   #19
interbaoui

Join Date
Oct 2005
Posts
447
Senior Member
Default
Oh, and overhead can actually be an issue .
No, I'm sorry, the overhead of a method call in Java is never an issue unless you are completely incompetent.
interbaoui is offline


Old 10-20-2010, 04:14 AM   #20
flielagit

Join Date
Oct 2005
Posts
289
Senior Member
Default
Really? Okay, I was under the false impression that they were some special structure or whatnot.

The most annoying thing about string arrays is Java's refusal to overload == to test string equality as opposed to just comparing the references. I don't know, I feel like they should have just made an exception for strings.
No, that would be horrible. The correct answer is to make == syntactic sugar for an equals() call and make === or some other operator test reference equality.
flielagit is offline



Reply to Thread New Thread

« Previous Thread | Next Thread »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

All times are GMT +1. The time now is 02:37 AM.
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 PL2
Design & Developed by Amodity.com
Copyright© Amodity