• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Quick beginner Java help pls

LuDaCriS66

Platinum Member
public class MaxBalanceProcessor extends AccountProcessor
{
public void processAccounts()
{
double maxBalance = account[0].getBalance();
for (int k = 1; k < account.length; k++)
{
double balance = account[k].getBalance();
if (balance > maxBalance)
maxBalance = balance;
}
System.out.println("The maximum balance is " + maxBalance);
}
}


How would I go about:
a) changing it so that it finds the minimum balance instead & displays the ones in the array having the minimum balance
b) displays the ones in the array with balance less than $1000?

I think I know how to find the minimum balance by modifying that IF statement.. but do I just use another IF statement to display the accounts that are the minimum?

 
Originally posted by: LuDaCriS66
public class MaxBalanceProcessor extends AccountProcessor
{
public void processAccounts()
{
double maxBalance = account[0].getBalance();
for (int k = 1; k < account.length; k++)
{
double balance = account[k].getBalance();
if (balance > maxBalance)
maxBalance = balance;
}
System.out.println("The maximum balance is " + maxBalance);
}
}


How would I go about:
a) changing it so that it finds the minimum balance instead & displays the ones in the array having the minimum balance
b) displays the ones in the array with balance less than $1000?

I think I know how to find the minimum balance by modifying that IF statement.. but do I just use another IF statement to display the accounts that are the minimum?

You can deposit my fee in my paypal account, hehe.


(A)
public class MinBalanceProcessor extends AccountProcessor
{
public void processAccounts()
{
double minBalance = account[0].getBalance();
for (int k = 1; k < account.length; k++)
{
double balance = account[k].getBalance();
if (balance < minBalance )
minBalance = balance;
}
System.out.println("The minimum balance is " + minBalance );
}
}

(B)
public class LessBalanceProcessor extends AccountProcessor
{
public void processAccounts()
{
System.out.println( "Balances less than a $1000: " );
for (int k = 0; k < account.length; k++)
{
double balance = account[k].getBalance();
if (balance < 1000 )
System.out.println( "$" + balance );
}
}
}




 
wow man, i dont know a bit of java but that's some pretty simple code. you really should do a bit more studying or something instead of asking for answers on the internet...
 
well crap... programming screws with my brain. I can never think of the code but when it's right in front of me it seems to simple...

thanks joeSmack
 
I been there man. My first CS course I was racking my brain trying to understand the concept of the while loop. Hehe.

Here are some tips:
1. Practice coding as much as possible.
2. Do your own stuff. Nothing too hard, keep it fun.
3. Program a little at a time to limit the number of potential bugs.
 
Back
Top