So I'm learning how to deal with Java, and here I have a question; My goal is to make Order class, which will store the order data: order value, date and login of the person placing the order. Next, create a Shop class that will hold a collection of unique orders.
The newly created class should have the following functionalities:
adding a new order, returning a list of orders within a range of two dates, picking orders based on the transferred scope (lowest and highest order value), return the number of orders, adding up the value of all orders.
Here's what I've got so far;
public class Order {
private double orderValue;
private double date;
private String customerLogin;
public Order(double orderValue, double date, String customerLogin) {
this.orderValue = orderValue;
this.date = date;
this.customerLogin = customerLogin;
}
public double getOrderValue() {
return orderValue;
}
public double getDate() {
return date;
}
public String getCustomerLogin() {
return customerLogin;
}
@Override
public String toString() {
return "Order{" +
"orderValue=" + orderValue +
", date=" + date +
", customerLogin='" + customerLogin + '\'' +
'}';
}
}
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
public class Shop {
LocalDate current = LocalDate.now();
LocalDate twoYearsAgo = current.minusYears(2);
int max = 0;
int min = 30;
private List<Order> orders = new ArrayList<>();
public void addOrder(Order order) {
this.orders.add(order);
}
public void between(LocalDate current, LocalDate twoYearsAgo) {
if (current.isBefore(twoYearsAgo)) {
return;
}
}
public void getMaxMinValue () {
int a = 0;
if (a < min) {
a = min;
} else if (a > max) {
a = max;
}
}
public int getSize() {
return this.orders.size();
}
public double getTotalValue() {
int sum=0;
for(int i=0; i<orders.size(); i++) {
sum+=orders.get(i);
}
return sum;
}
}
As you can see, I'm missing the method that would return total value of all orders, I would really use some help with that, thanks!
getOrderValue()of Order when summing likesum+=orders.get(i).getOrderValue();