package no.valg.valgnatt.backend.mandatberegning.domene;

import java.math.BigDecimal;

import no.valg.valgnatt.database.Konstanter;

public class Kvotient {

	private BigDecimal kvotient;

	public Kvotient(int k) {
		this.kvotient = new BigDecimal(k);
	}

	public Kvotient(BigDecimal kvotient) {
		this.kvotient = kvotient;
	}

	// Lager en kvotient gjennom en brøk
	public Kvotient(int teller, int nevner) {
		this.kvotient = new BigDecimal(teller).divide(new BigDecimal(nevner), Konstanter.MAKS_PRESISJON, BigDecimal.ROUND_HALF_UP);
	}

	public Kvotient add(Kvotient k) {
		return new Kvotient(this.kvotient.add(k.getKvotient()));
	}

	public BigDecimal getKvotient() {
		return kvotient;
	}

	public Kvotient divide(BigDecimal bd) {
		return new Kvotient(this.kvotient.divide(bd, Konstanter.MAKS_PRESISJON, BigDecimal.ROUND_HALF_UP));
	}

	public Kvotient multiply(BigDecimal bd) {
		return new Kvotient(this.kvotient.multiply(bd));
	}

	public Kvotient subtract(Kvotient k) {
		return new Kvotient(this.kvotient.subtract(k.getKvotient()));
	}

	public String toString() {
		return kvotient.toString();
	}

}
