TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-07-2009, 02:59 PM   #1 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default Java help(again)

Hiya, again!

I'm here with another Java problem.
I have a Bank program, and an add button, which would let you add a customer to the Bank. Problem is, that I need the social security number to be of the type "long".

Currently looks like this:
Code:
public Boolean addCustomer_logic()
{
		
	String number = this.addCustNumber_textfield.getText();
	String name = this.addCustName_textfield.getText();
	int nr = Integer.parseInt(number);
		
	return this.logic.addCustomer(nr, name);
		
}
As you see, I'm parsing Int. How can I convert an input string to long??
__________________
Tanax is offline  
Reply With Quote
Old 05-07-2009, 03:13 PM   #2 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
Hiya, again!

I'm here with another Java problem.
I have a Bank program, and an add button, which would let you add a customer to the Bank. Problem is, that I need the social security number to be of the type "long".

Currently looks like this:
Code:
public Boolean addCustomer_logic()
{
		
	String number = this.addCustNumber_textfield.getText();
	String name = this.addCustName_textfield.getText();
	int nr = Integer.parseInt(number);
		
	return this.logic.addCustomer(nr, name);
		
}
As you see, I'm parsing Int. How can I convert an input string to long??
Would this work?

long nr = Long.parseLong(number);
allworknoplay is offline  
Reply With Quote
Old 05-07-2009, 03:20 PM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Yea, lol, I found out via Java docs 1 min after I posted >.<

Anyway, thanks!
__________________
Tanax is offline  
Reply With Quote
Old 05-07-2009, 03:33 PM   #4 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Okay, so here's something interesting(I can't be bothered to create yet another Java help thread xD).

For those who don't know I've created a bankprogram, with customers, and each customers can have several accounts(savingsaccounts and creditaccounts), and each account you can add money to, or deduct money from. Creditaccounts also has a creditlimit.

Anyhow, the feature that is giving me error, is when I'm trying to remove a customer. What should happen is that it should remove all the belonging accounts, then remove the customer. This is not the case.

Quote:
Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
at java.util.TreeMap$PrivateEntryIterator.nextEntry(T reeMap.java:1100)
at java.util.TreeMap$EntryIterator.next(TreeMap.java: 1136)
at java.util.TreeMap$EntryIterator.next(TreeMap.java: 1131)
at Logic.deleteAccounts(Logic.java:707)
at GUI.actionPerformed(GUI.java:333)
at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
at javax.swing.AbstractButton.doClick(AbstractButton. java:357)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Bas icMenuItemUI.java:1220)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mou seReleased(BasicMenuItemUI.java:1261)
at java.awt.Component.processMouseEvent(Component.jav a:6041)
at javax.swing.JComponent.processMouseEvent(JComponen t.java:3265)
at java.awt.Component.processEvent(Component.java:580 6)
at java.awt.Container.processEvent(Container.java:205 8)
at java.awt.Component.dispatchEventImpl(Component.jav a:4413)
at java.awt.Container.dispatchEventImpl(Container.jav a:2116)
at java.awt.Component.dispatchEvent(Component.java:42 43)
at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:3986)
at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:3916)
at java.awt.Container.dispatchEventImpl(Container.jav a:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2440 )
at java.awt.Component.dispatchEvent(Component.java:42 43)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 599)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:121)
GUI action performed:
Code:
else if(option.equals("Remove customer")) 
			{
				
				int selection = JOptionPane.showConfirmDialog(null, "Are you sure?\nThis action cannot be undone.\n", "Delete customer " + this.logic.getName(), 
								JOptionPane.YES_NO_OPTION);
								
				if(selection == 0) 
				{
					
					String custName = this.logic.getName();
					String accounts = this.logic.deleteAccounts();
					double interest = this.logic.removeCustomer();
					String text = "Upon deletion of customer " + custName + "(ID: " + this.logic.id() + ") and all belonging accounts(" + accounts + "), ";
						   text = text + "the total amount of interest was " + interest + "kr!";
						   
					this.manageCustomers();
					JOptionPane.showMessageDialog(null, text);
					
				}
				
			}
Logic deleteAccounts:
Code:
public String deleteAccounts()
	{
		
		SavingsAccount currentSAccount;
		CreditAccount currentCAccount;
		String accounts = "";
		double interest = 0.0;
		this.totalInterest = 0.0;
		
		Map sAccounts = this.customer.getSavingsAccounts();
		Map cAccounts = this.customer.getCreditAccounts();
		
		Map.Entry account;
    	Iterator allSavingsAccounts = sAccounts.entrySet().iterator();
    	Iterator allCreditAccounts = cAccounts.entrySet().iterator();
    	
    	while(allSavingsAccounts.hasNext())
    	{
    		
    		account = (Map.Entry) allSavingsAccounts.next();
    		currentSAccount = (SavingsAccount) account.getValue();
    		interest = currentSAccount.prepareDelete();
    		
    		if(accounts != "") accounts += ", ";
    		
    		accounts += currentSAccount.getAccountNumber() + ": " + interest;
    		this.totalInterest += interest;
    		
    		this.customer.removeAccount(currentSAccount.getAccountNumber());
    		
    	}
    	
    	while(allCreditAccounts.hasNext())
    	{
    		
    		account = (Map.Entry) allCreditAccounts.next();
    		currentCAccount = (CreditAccount) account.getValue();
    		interest = currentCAccount.prepareDelete();
    		
    		if(accounts != "") accounts += ", ";
    		
    		accounts += currentCAccount.getAccountNumber() + ": " + interest;
    		this.totalInterest += interest;
    		
    		this.customer.removeAccount(currentCAccount.getAccountNumber());
    		
    	}
    	
    	return accounts;
		
		
	}
Line 707:
Code:
account = (Map.Entry) allSavingsAccounts.next();
The thing is, it works great if you only have 1 account. It's when you have more than 1 account that it gets the error. It actually removes 1 account when you click remove customer, then the exceptions are thrown, so the while loop runs one time, but the second time it get's weird. Obviously the customer does not get removed due to the script aborting when the errors occur. But it removes 1 account from the customer(I'm guessing the first account it iterates).

Any ideas???
Reply if you need to see some of the functions I used within these codes.
__________________
Tanax is offline  
Reply With Quote
Old 05-09-2009, 02:32 PM   #5 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Anyone ??
__________________
Tanax is offline  
Reply With Quote
Old 05-09-2009, 02:46 PM   #6 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
Anyone ??
Wish I could help you dude....
allworknoplay is offline  
Reply With Quote
Reply



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

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
passing a java variable to php pipesportugal Advanced PHP Programming 11 08-27-2009 10:49 PM
Anyone here knows Java? Tanax The Lounge 4 04-21-2009 05:29 PM
Should I drop PHP for Java? webosb General 11 04-05-2009 06:58 AM
Java Server Pages really worth it? Orc The Lounge 6 03-24-2008 08:04 PM
Where do start Java from? Haris The Lounge 23 01-23-2008 11:02 PM


All times are GMT. The time now is 08:08 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design