25,6 → 25,7 |
|
import javax.swing.Timer; |
import java.awt.event.*; |
import java.math.*; |
|
/** |
* This class represents a tracked task. |
35,6 → 36,7 |
|
private String name = "Unnamed task"; |
private long consumption = 0L; |
private double price = 1; |
|
private Timer timer = null; |
/** |
42,6 → 44,11 |
*/ |
public static final int PERIOD = 10000; |
|
/** |
* time units per hour |
*/ |
public static final double UNITS_PER_HOUR = 3600000; |
|
private ActionListener listener = null; |
|
private static int nextId = 0; |
68,11 → 75,13 |
* @param id task identifier |
* @param name task name |
* @param consumption up to now time consumption |
* @param price price per hour |
*/ |
public Task(int id, String name, long consumption) { |
public Task(int id, String name, long consumption, double price) { |
this.id = id; |
this.name = name; |
this.consumption = consumption; |
this.price = price; |
|
if (id >= nextId) |
nextId = id + 1; |
127,6 → 136,31 |
} |
|
/** |
* Sets the price per hour [currency unit]. |
* Changing this parameter affects the current total price of the task. |
* @param price new price value |
*/ |
public void setPrice(double price) { |
this.price = price; |
} |
|
/** |
* Returns the current price per hour [currency unit]. |
* @return current price value |
*/ |
public double getPrice() { |
return price; |
} |
|
/** |
* Returns the total price of this task [currency unit]. |
* @return total price of this task |
*/ |
public double getTotalPrice() { |
return ((double) consumption) / UNITS_PER_HOUR * price; |
} |
|
/** |
* Converts the instance to the string representation. It contains |
* the task name and consumption. |
* @return string representation |