Please help, with java exam question?
hi
relating to an exam on mon and i do think a question just like this shall be on it.Could quite a few please explain to me in the event my respond to question (a) will be correct plus help my home answer query (b)
A training BankAccount is usually defined from the following value:
course BankAccount
//properties
exclusive String appoint;
exclusive int accountNum;
exclusive double balance;
//initialise a brand new bank consideration object
arrest BankAccount(String accountName, int num)
title = accountName;
accountNum = num;
harmony = 0;
arrest void deposit(double amount)
//increase stability by amount of the deposit
arrest void withdraw(double amount)
//decrease harmony by amount of money withdrawn in addition to alert
// individual if balance is down below zero
arrest String getAccountNum()
//returns account number
arrest double getBalance()
go back balance;
//bankAccount
(questions)
(a) finished the training BankAccount through providing code to the methods
(i) deposit
(ii) withdraw
(iii) getAccountNum
(my answers)
(i)
arrest void deposit(double amount)
harmony += amount;
go back amount;
(ii)
arrest void withdraw(double amount)
harmony = stability C amount
if (balance < 0)
Procedure.out.println(you include overdrawn);
(iii)
arrest String getAccountNum()
go back num;
(question (b) is usually where we are really encountering, could an individual please guide me resolution it
(b)
Create range capable connected with storing SEVERAL references to BankAccount things.Create some seperate instances of a BankAccount ans assign that reference to be able to each object(returned through the new operator) to a component within that array
this is actually the answer i have so significantly, I consider i have learned to create that instances yet dont learn about the array part.
BankAccount account1 = different BankAccount (” Jenny Bloggs “, 998757384);
account1.deposit(450);
account1.withdraw(200);
account1.getBalance();
Any help is going to be greatly appreciated, thanks
iii)
arrest String getAccountNum()
go back this.accountNum;
b)
BankAccount arrayAccounts = different BankAccount3;
arrayAccounts0 = different BankAccount(” Jenny Bloggs “, 998757384);
arrayAccounts1 = different BankAccount(” Jen Bloggs “, 345763457);
arrayAccounts2 = different BankAccount(” Bloggs “, 434563457);
Anticipation that will help.
=D
Ok, therefore in answer a), that all looks fine, but within iii) you need to be returning the proper instance variable – num may be a variable local for the constructor which is out connected with scope anywhere else…
Intended for answer b), you happen to be creating the actual instance good.The plethora stuff is admittedly not of which difficult, but I don’t even think that POST should inform you how to perform it while, it’s much much better to discover it out for your own.
What you ought to do is usually google with regard to ‘java array’….in simple terms you have got to create an array of Banking account objects, while using initial sizing obviously becoming 3.
This can create a strong empty array of BackAccount physical objects.For each component this number, you and then assign certainly one of your developed accounts.
Therefore.
ONE.You create the 3 accounts.
ONLY TWO.You create several accounts with a short size connected with 3.
THREE.You then assign each and every account with a specific component of the variety.
Hope this kind of helps
You employ a few difficulties.As that stands, your code will not likely even make.The surest method to see for those who have these responses right should be to compile as well as run your code.That is what software engineers do.
the.i.This process has any return form of void, therefore it should possibly not return a value.Take away the give back statement.
the.ii.You’re with a dash when you need to be using any minus indicator.If you will be writing this specific in Microsoft Word or maybe some same word processing program, stop right now and make use of a text manager instead.It’ll help you save a great deal of headaches.
the.iii.This process returns on line casinos of a variable referred to as num, which often doesn’t exist.You’re saving the consideration number around an case in point variable labeled accountNum, not necessarily num.In addition, accountNum is usually an int, but this process is defined to come back a Stringed.I’m uncertain if that is definitely really what you long for.
b.Read the actual link down below to learn to define arrays within Java.
Leave a Reply
You must be logged in to post a comment.