-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOneTimeOrders.java
107 lines (97 loc) · 2.89 KB
/
OneTimeOrders.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* @author Bradley Estacio and Patrick Inosanto
* 12/6/19
*
* This class is used to make one time orders for Order Manager
* Uses date class and .split method - used for organizing in OrderManager.
* Has get/set methods for customerID, productID, date and amount
* and has toString method.
* Has methods that @throws OneTimeOrdersException
* @implements Comparable <OneTimeOrders>
* Comparable interface compares two OneTimeOrder objects.
* This will be used in OrderManager for inventoryReport
*/
import java.util.*;
public class OneTimeOrders implements Comparable<OneTimeOrders>
{
private String customerID;
private String productID;
private Date date;
private int amount;
public OneTimeOrders(String customerID, String productID, String date, int amount)
{
this.customerID = customerID;
this.productID = productID;
try
{
setDate(date);
}
catch(OneTimeOrdersException e)
{
System.out.println(e.getMessage());
}
this.amount = amount;
}
//getters
public String getCustomerID()
{
return customerID;
}
public String getProductID()
{
return productID;
}
public Date getDate()
{
return date;
}
public int getAmount()
{
return amount;
}
//setters
public void setCustomerID(String customerID)
{
this.customerID = customerID;
}
public void setProductID(String productID)
{
this.productID = productID;
}
public void setDate(String date) throws OneTimeOrdersException
{
String[] splitDate = date.split("/"); //splits string of date into string for date class
if((Integer.parseInt(splitDate[0]) > 12) || (Integer.parseInt(splitDate[0]) < 0) || (Integer.parseInt(splitDate[1]) > 31) || ((Integer.parseInt(splitDate[1]) < 0))
|| (Integer.parseInt(splitDate[2]) < 0) || (Integer.parseInt(splitDate[2]) > 2019)) //makes sure mm/dd/yyyy is valid
{
throw new OneTimeOrdersException("Sorry you entered an invalid date. Please try again.");
}
Date makeDate = new Date(Integer.parseInt(splitDate[2]), Integer.parseInt(splitDate[0]) - 1, Integer.parseInt(splitDate[1])); //month is minus one due to how date class works
this.date = makeDate;
}
public void setAmount(int amount)
{
this.amount = amount;
}
//compares two OneTimeOrderObject objects when sorting for inventory report
//order of comparing: year -> month -> productID
//Used for Collections.sort(orders); @see OrderManager - inventoryReport
public int compareTo(OneTimeOrders compared)
{
int comparing;
comparing = this.date.getYear() - compared.getDate().getYear();
if(comparing == 0)
{
comparing = this.date.getMonth() - compared.getDate().getMonth();
}
if(comparing == 0)
{
comparing = this.productID.compareToIgnoreCase(compared.getProductID());
}
return comparing;
}
public String toString()
{
return "Customer ID: " + getCustomerID() + ", Product ID: " + getProductID() + ", Date ordered: " + this.date.toString() + ", Amount: " + getAmount();
}
}