john lampard

Greenhorn
+ Follow
since Mar 23, 2015
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by john lampard

Rob Camick wrote:
Well, the readStates() method actually reads some text into the variable.

In your other code you set the variable to null and never add any text to the variable!!! Data doesn't just magically appear in the variable.



Gotcha change it to this:



Still nothing is coming up when i activate the openFile listener.
8 years ago
No, this part of the code is the only part where I declare an actual string, all the others would be an array or arraylist of strings, I don't get it because my readStates method handles that problem fine.

8 years ago

Rob Camick wrote:Look at your code:



You assign null to the line variable.



If I don't assign it to anything, I'll get an error saying "line" may not have been initialized.
8 years ago

Rob Camick wrote:Well you can use the JList.getSelectedValue() method which will get the data from the DefaultListModel for you.



That's what i'm doing, but my problem is actually trying to populate the list with my contacts names.
8 years ago

Rob Camick wrote:Why do you have a List of Contacts? The DefaultListModel holds all your Contacts.

If you want a specific contact when the user clicks on the list you get the contact from the ListModel or from the JList itself.

That is the selected item will be the Contact that was selected.



So, my contactsList would do the displaying, and if I select something I should call from the DefaultListModel?
8 years ago
This is just frustrating the brain cells out of me, so i've modified my read method to look like this.



then added the open action listener in the JMenu, which is here.


contactList, is my JList, and getContactList method is in my AddressBook class which looks like

list here being an ArrayList <Contacts>.

Whenever I run the program, and try to open the file, I get a load of errors, here's a snippet of that:



line 708 is where I declare String [] info = line. split(",");
and line 367 is where I call the loadFile();

What am I doing wrong here, please help!!
8 years ago

Make each item in the list a an object that contains all the information for a contact, i.e. when you read in a string of info, parse it into different values, each of which is a member of the contact object. You can create each object by passing the data values to the object's constructor. You might also want to consider overriding the toString() method in the object to define what you see in the list. When you click a list item, you now have access to the object that represents the entire entity.



Would I go about it something like this?

8 years ago
I have an addressBook GUI where I have a JList that populates with the contacts names, and once I double click a contacts name I'm wanting to fill the textfields with the contacts corresponding data.

ex) ContactType: Family (enum), Name: Zoidberg, Address: 111 Space Drive, City: New York City, etc...

I've got it to where I select open from the JMenu, it populates the JList, but once I select a contacts name, all the textfields are populated, but only with the contacts name

ex) Name: Zoidberg, Address: Zoidberg, City: Zoidberg, etc....

What am i doing wrong here, and how can i fix it to where it fills out the correct data?

Here's my code so far:



I'm certain the logic is messed up near the end where i set all text fields to the index, because no matter what field i want to fill it's at it's going to set it to whatever index I select, but I don't know how to fix it, any help would be great, Thanks.
8 years ago
Thanks I appreciate your help, I'll read the tutorial you posted and try to figure it out. I'll let you go to bed. Thanks again.
8 years ago
Will I have to do something like ?
8 years ago

Campbell Ritchie wrote:Try changing all the commas in the input file to spaces.



You mean like this?

Zoidberg 100.0
Homer Simpson 50.0
Peter Griffin 45.0
Lisa Simpson 100.0
Bob Burger 78.0
Marge Simpson 87.0

EDIT: That actually worked, but I'd like to keep the commas in there though. It also just appended the numbers only to my .txt How would I get it to print the names as well? Thanks.
8 years ago
I'm trying to sort the doubles in my .txt file in descending order, then overwrite it over the .txt file with it sorted. I have the method to sort the Strings done and finished already, but am having trouble sorting the doubles in the .txt file.

My .txt file looks like this :

Zoidberg,100.0
Homer Simpson,50.0
Peter Griffin,45.0
Lisa Simpson,100.0
Bob Burger,78.0
Marge Simpson,87.0


My code for the sorting the doubles looks like this.



I have it set up where the user can choose either to sort the names in alphabetical order, or to sort it by grades in descending order. When I select the sort grade option, nothing happens eclipse says it's terminated and nothing happens with my .txt file. Am I doing something wrong syntactically or logically? Any help would be great thanks.
8 years ago
I sort of figured it out it seems.

the dealAHand method in the Deck class


My driver:


The output:



How can i get it to print Player 1: cards....
Player 2: cards...
9 years ago

Guillermo Ishi wrote:If you put all the cards in an arraylist you can do this - choose a random number between 0 and its size-1 (51 to start with). Use that random number as an index into the arraylist. That will be the card you are dealing. Remove the element with that index from the arraylist from from the arraylist. That gives you a new upper bound for the next random number. The arraylist elements can be a Card object with suit and value fields.



If I had it my way, I would definitely would have used an arraylist, but it wasn't up to me. Just got to play with the cards i've been dealt
9 years ago

Stephan van Hulst wrote:



These methods are where i'm running into problems. In the hand class how would I go about seeing if there's enough room and how would I make room?
It's also the same problem with the dealAHand method, specifically checking to see if there are enough cards, creating, and filling the hand.
9 years ago