System.out.println(max.getAccountNumber().\"\"+max.get Balance()]; System.out.pr
ID: 3831701 • Letter: S
Question
System.out.println(max.getAccountNumber().""+max.get Balance()]; System.out.println(min.getBalance(). ""+min. getBalance()]; } } Consider the algorithm that we used for determining the maximum value in an array list. We set largest Yet to the starting element, which meant that we were no longer able to use the "for each" loop. An alternate approach is to initialize largest Yet with null, then loop throughout all elements, of course, inside the loop you need to test whether largestYet is still null. Modify the loop that finds the bank account with the largest balance. using this technique. Is this approach more or less efficient than the one used in the text? BankAccount largest Yet accounts get(); for (int i=1.i largestYet.getBalance ()) largestYet=a; } return largestYet; Rewrite the following loop without using the "for each" construct. Here, data is an array of double values, for (x-data) if(x==target) return true; Consider an enhancement of the Die class with a static field: public class Diel public Die [int s] (..) public int cast ()(,...) private int sides: private static Random generator new Random () }Explanation / Answer
Bank Accout problem:
BankAccount largestYet = null;
for(BankAccount acc : accounts){
// initialization of largestYet
if(largestYet == null){
largestYet = acc;
}else{
if(acc.getBalance() > largestYet.getBalance()){
largestYet = acc;
}
}
}
8)
for(int i=0; i<data.length; i++){
if(data[i] == x)
return true;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.