9dc24638923a6aee9fd3571c14f01066

How would you refactor this in java?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function amortization_array($principal, $interest_rate, $start_year, $start_month, $term, $group_by = 'M, Y', $month_names){
	$periods  = $term * 12;
	$balance  = $principal;
	$interest = $interest_rate / 100 / 12;
        $payment  = $principal * $interest / (1 - pow((1 + $interest), -$periods));

	for($period = 0; $period < $periods; $period++){
		$date = get_date($start_year, $start_month + $period, $group_by, $month_names);
		$results[$date]['date']       = $date;
		$results[$date]['p']	  = $period + 1;

		$results[$date]['year']       = substr($date, -4);
		$results[$date]['interest']  += $balance * $interest;
		$results[$date]['principal'] += $payment - $balance * $interest;
		$results[$date]['balance']    = $balance = $balance - $payment + $balance * $interest;

		if($results[$date]['balance'] < 0) $results[$date]['balance'] = 0;
	}
	return $results;
}

Refactorings

No refactoring yet !

22e33503870d8e20493c4dd6b2f9767f

rikkus

September 25, 2008, September 25, 2008 16:59, permalink

No rating. Login to rate!

You're confusing the terms 'refactor' and 'reimplement'

503dc458e66746c5ac681e7057d209dd

McDole

September 26, 2008, September 26, 2008 16:25, permalink

No rating. Login to rate!

rikkus == useless troll.

Bfec5f7d1a4aaafc5a2451be8c42d26a

macournoyer

September 26, 2008, September 26, 2008 18:00, permalink

No rating. Login to rate!

yo guys, what's up with all the hate?
You need sweat and tender loving.
xx

151e36cc7f789a4790c8ca437e3a1f60

Chris Dean

October 28, 2008, October 28, 2008 07:34, permalink

No rating. Login to rate!

Maybe you should post this under the java category?

That said I'd expect it to work pretty much as is, just with a change to how you reference the variables php uses $varname, not sure how java does this...

Hope that helps

Your refactoring





Format Copy from initial code

or Cancel