/*
 * KnapSackItem.java
 *
 * Created on November 2, 2005, 5:26 PM
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package cz.pcland.knapsack;
import cz.pcland.gavisualization.Operations;
import java.awt.*;
import java.util.*;

/**
 *
 * @author petr
 */
public class KnapSackItem implements Comparable {
	double price;
	double capacity;
        
        private boolean isInSack = false;
        private boolean isInApproximate = false;
        
       
        
        public int compareTo(Object to) {
            return Double.compare( ((KnapSackItem)to).getPrice()/((KnapSackItem)to).getCapacity(), (price/capacity) );
        }
        
        public void addToSack() {isInSack=true;}
        public void removeFromSack() {isInSack=false;}
        public boolean isInSack(){return isInSack;}
        
        
        public void addToApproximate() {isInApproximate=true;}
        public void removeFromApproximate() {isInApproximate=false;}
        public boolean isInApproximate(){return isInApproximate;}
	
        /*public Color getColor() {
            return color;
        }*/
        
        

        
	public KnapSackItem(double price, double capacity) {
		this.price = price;
		this.capacity = capacity;
                Random rand = new Random();
		
	}
	
	public KnapSackItem(KnapSackItem ksi) {
		this.capacity = ksi.capacity;
		this.price = ksi.price;
                Random rand = new Random();
	}
        
        public String toString() {
            double rounded = (int)((this.price/this.capacity)*10);
            rounded = rounded/10;
            if(this.isInApproximate()) {
            return "<html>Capacity: <b>" + Operations.getColoredText(Color.red, String.valueOf(this.capacity)) + 
            "<b>,  Price: <b>" + Operations.getColoredText(Color.red, String.valueOf(this.price)) +"<b>, price/capacity rate: "+ String.valueOf( rounded ) + ", " + Operations.getColoredText(Color.green, "approximate") +" </html>";
            }else {
                return "<html>Capacity: <b>" + Operations.getColoredText(Color.red, String.valueOf(this.capacity)) + 
            "<b>,  Price: <b>" + Operations.getColoredText(Color.red, String.valueOf(this.price)) +"<b>, price/capacity rate: "+ String.valueOf( rounded ) +" </html>";
            }
        }
        
	public double getPrice() {return price;}
	public double getCapacity(){return capacity;}

}
