Skip to content

Instantly share code, notes, and snippets.

@AnnaBoro
Created January 11, 2016 21:39
Show Gist options
  • Save AnnaBoro/a96cb3ac16df7de853aa to your computer and use it in GitHub Desktop.
Save AnnaBoro/a96cb3ac16df7de853aa to your computer and use it in GitHub Desktop.
package lesson5_8.shop;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
public class Report2 {
Store2 store;
public Report2 (Store2 store) {
this.store = store;
}
public ArrayList<String> getPrice () {
ArrayList<String> priceList = new ArrayList<String>();
for (Bird b : store.getBirds()) {
if (b != null) {
priceList.add(b.getName() + " " + b.getPrice());
}
}
return priceList;
}
public ArrayList<String> getBirdsOnStock () {
ArrayList<String> birdsOnStock = new ArrayList<String>();
for (Bird b : store.getBirds()) {
birdsOnStock.add(b.getName() + ": " + b.getQuantity());
}
return birdsOnStock;
}
// public int[] getPurchasesInLast7Days() {
//
//
// }
public void printListTodayPurchases() {
List<Purchase2> purchases = store.getPurchases();
long today = getToday();
int numPurchase = 0;
int todayProfit = 0;
int numSoldBirds = 0;
System.out.println("__________Today Purchases:");
System.out.println("№ Buyer Birds Price Number");
for (Purchase2 p : purchases) {
if (p.getDate().getTime().getTime() > today) {
numSoldBirds += numSoldBirds + p.getNumber();
todayProfit += todayProfit + p.getNumber() * p.getBird().getPrice();
numPurchase++;
System.out.println(numPurchase + " " + p.getBuyer().getName() + " " + p.getBird().getName() + " " +
p.getBird().getPrice() + " " + p.getNumber());
}
}
System.out.println("In total " + numPurchase + " purchases " + todayProfit + " " + numSoldBirds);
}
public Long getToday() {
Date dt1 = new Date();
SimpleDateFormat c = new SimpleDateFormat("dd MMM yyyy", Locale.ENGLISH);
String d1 = c.format(dt1);
Date today = null;
try {
today = c.parse(d1);
} catch (ParseException e) {
e.printStackTrace();
}
long todayWithoutHours = today.getTime();
return todayWithoutHours;
}
public void printCatalogByCategory(Category category) {
System.out.println("__________Catalog by Category: " + category.toString());
System.out.println("Bird Price Number");
for (Bird b : store.getBirds()) {
if (category != null && b.getCategory().toString().equalsIgnoreCase(category.toString())) {
System.out.println(b.getName() + ": " + b.getPrice() + " " + b.getQuantity());
}
}
}
public Store2 getStore() {
return store;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment