All pastes #214279 Raw Edit

Miscellany

public text v1 · immutable
#214279 ·published 2006-10-21 23:03 UTC
rendered paste body
import java.util.ArrayList;

public class Money {
	private ArrayList<int> hours;
	
	public Money() {
		hours = ArrayList<int>();
	}
	
	public void addHours(String startTime, String endTime) {
		String[] sTime = startTime.split(":");
		String[] eTime = endTime.split(":");
		int h1, h2, m1, m2, t1, t2, total;
		
		m1 = 0;
		m2 = 0;
		
		h1 = Integer.parseInt(sTime[0]);
		h1 *= 60;
		if (sTime[1] != null)
			m1 = Integer.parseInt(sTime[1]);
		
		h2 = Integer.parseInt(eTime[0]);
		h2 *= 60;
		if (eTime[1] != null)
			m2 = Integer.parseInt(eTime[1]);
		
		if (t1 > t2) {
			System.err.println("Invalid hours.");
		}
		else {
			total = t2 - t1;
			hours.add(total);
		}
	}
	
	public void earnings()
	{
		double t, amount;
		int rounded;
		t = 0;
		for (int x : hours) {
			t += x;
		}
		amount = (t/60) * 7.40;
		rounded = (int) amount;
		
		System.out.println("Rounded earnings: " +rounded);
	}
}