473,508 Members | 2,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

please help!!

45 New Member
Hi,

i've been trying to solve some java questions, to prepare for a test. I came across a question and im not sure if my answer is correct or not. Is it ok if you guys check it for me and give me your feedback?

this is the question:

What does the following code do with the array list accounts.

Expand|Select|Wrap|Line Numbers
  1. public class Bank
  2. {
  3.     public BankAccount doSomething(int accountNumber)
  4.    {
  5.       for (BankAccount a : accounts)
  6.       {
  7.           if (a.getAccountNumber() == accountNumber) 
  8.           return a;
  9.        }
  10.        return null; 
  11.     }
  12.        . . .
  13. }
This is the answer i came up with:

the for loop will check “for each BankAccount a in accounts.” Then it will check if (a.getAccountNumber() is equal to accountNumber) then it return the value of that account.

so what do you think?

thanks!!
Jan 5 '07 #1
3 1200
r035198x
13,262 MVP
Hi,

i've been trying to solve some java questions, to prepare for a test. I came across a question and im not sure if my answer is correct or not. Is it ok if you guys check it for me and give me your feedback?

this is the question:

What does the following code do with the array list accounts.

Expand|Select|Wrap|Line Numbers
  1. public class Bank
  2. {
  3. public BankAccount doSomething(int accountNumber)
  4. {
  5. for (BankAccount a : accounts)
  6. {
  7. if (a.getAccountNumber() == accountNumber) 
  8. return a;
  9. }
  10. return null; 
  11. }
  12. . . .
  13. }
This is the answer i came up with:

the for loop will check “for each BankAccount a in accounts.” Then it will check if (a.getAccountNumber() is equal to accountNumber) then it return the value of that account.

so what do you think?

thanks!!
Yes it returns that BankAccount. Also if no account is not found that has a.getAccountNumber()equal to accountNumber then the null reference is returned.
Jan 5 '07 #2
outofmymind
45 New Member
Yes it returns that BankAccount. Also if no account is not found that has a.getAccountNumber()equal to accountNumber then the null reference is returned.

thanks, i was worried that it might be wrong :s

outofmymind ;)
Jan 5 '07 #3
r035198x
13,262 MVP
thanks, i was worried that it might be wrong :s

outofmymind ;)
Anytime. If you are going for a test, might want to consider having a look at the java classes on this site as aonther revision point
Jan 5 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1913
by: m3ckon | last post by:
Hi there, had to rush some sql and am now going back to it due to a slow db performance. I have a db for sales leads and have created 3 views based on the data I need to produce. However one...
6
1763
by: James Walker | last post by:
Can some one help I get an error of 'checkIndate' is null or not an object can someone please help. I can't work out why Thanks in advance James <form> <td height="24" colspan="7"...
0
1679
by: Kurt Watson | last post by:
I’m having a different kind of problem with Hotmail when I sign in it says, "Web Browser Software Limitations Your Current Software Will Limit Your Ability to Use Hotmail You are using a web...
7
2364
by: Alan Bashy | last post by:
Please, guys, In need help with this. It is due in the next week. Please, help me to implement the functions in this programm especially the first three constructor. I need them guys. Please, help...
1
1372
by: Steve | last post by:
Hi, I've asked this question a couple of times before on this forum but no one seems to be nice enough to point me to the right direction or help me out with any information, if possible. Please...
22
2145
by: KitKat | last post by:
I need to get this to go to each folders: Cam 1, Cam 2, Cam 4, Cam 6, Cam 7, and Cam 8. Well it does that but it also needs to change the file name to the same folder where the file is being...
17
2265
by: Saps | last post by:
Hi all. Can anyone help me here. I have loads of .sql files and i need a way to call these from my asp page so the user can run them from the browser. Meaning i have a page with a list of all...
8
3140
by: CM | last post by:
Hi, Could anyone please help me? I am completing my Master's Degree and need to reproduce a Webpage in Word. Aspects of the page are lost and some of the text goes. I would really appreciate it....
1
1520
SKJoy2001
by: SKJoy2001 | last post by:
PLEASE HELP ME!!! P E R L!!! I have a CGI (PERL) file namely 'test.cgi' and it has the correct permission (755) on the FTP server and it is within the CGI path. I have the following code in it:...
6
3282
by: jenipriya | last post by:
Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors... The table structures i hav Employee (EmpID,...
0
7118
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5049
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.