Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * SEF Supermarket System
- * Student 1 : Michael Mansour s3509599
- * Student 2 :
- * Student 3 :
- * Student 4 : Zixi Zhang s3459799
- */
- package Manager;
- import java.io.*;
- import java.util.*;
- import Sales.*;
- import Utilities.*;
- /**
- * @author Student :
- *
- */
- public class Manager {
- private static PrintStream out = System.out;
- private BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
- private List<product> prod_info = new ArrayList<product>();
- private static final String username = "manager";
- private static final String password = "12345678";
- private static int reorder_quantity;
- public Manager() throws FileNotFoundException, ClassNotFoundException, IOException{
- if(Login.login(username, password)){
- loadItemInfo.loaditemInfo((ArrayList<product>) prod_info, "Product_info.tmp");
- managerMenu();
- }else
- out.println("\nusername or password incorrect!");
- saveItemInfo.saveiteminfo(prod_info, "Product_info.tmp");
- }
- /**
- * Manager Menu
- */
- private void managerMenu() throws IOException, ClassNotFoundException{
- int selection;
- do{
- out.println("1. Maintains unit-price, stock level, replenish-level");
- out.println("2. Supplier details for all products");
- out.println("3. Special discounts on products");
- out.println("4. Generate sales report");
- out.println("5. The most revenue product");
- out.println("6. Exit to main menu");
- out.println("Enter a number");
- selection = InputValidation.ValidateInt(bf.readLine());
- if (selection == 1){
- reorder_quantity = reorder_quant_imple();
- out.println("\nReorder quantity for all item is: " + reorder_quantity);
- out.println();
- Unit_Price_StockLevel();
- }
- else if (selection == 2){
- //Not implement yet
- }
- else if (selection == 3){
- ChangeDiscountStatus();
- }
- else if (selection == 4){
- //Bonus function will be implemented later
- PrintPNGReport();
- }
- else if (selection == 5){
- Mst_Revenue_Product();
- }
- }while(selection != 6);
- }
- /**
- * Specify reorder quantity for all items
- * This method is used the in first function
- * of the Menu
- */
- private int reorder_quant_imple() throws IOException{
- int re_quantity = 50;
- out.println("*** Do you want to change reorder quantity?(y/n)");
- String s = bf.readLine();
- if(s.charAt(0) == 'y' || s.charAt(0) == 'Y'){
- out.print("Please enter new quantity: ");
- return InputValidation.ValidateInt(bf.readLine());
- }
- return re_quantity;
- }
- /**
- * First Menu implementation
- */
- private void Unit_Price_StockLevel() throws IOException{
- PrintList();
- out.println("Please select a number to change info: ");
- int select = InputValidation.ValidateInt(bf.readLine()) -1;
- float unit_Price;
- int quantity;
- @SuppressWarnings("unused")
- int replenish_level;
- try{
- product po = prod_info.get(select);
- if(po.getStockLevel() <= reorder_quantity){
- out.println("StockLevel is too low, reorder item procedure is commencing");
- quantity = reorder_quantity;
- }
- out.println(" Item Info ");
- out.println("Name: " + po.getName() + " ID: " + po.getID() + " Unit-Price: " + po.getPrice()
- + " Quantity: " + po.getStockLevel());
- out.println("Enter new unit price: ");
- unit_Price = InputValidation.ValidateFloat(bf.readLine());
- out.println("Enter new StockLevel: ");
- quantity = InputValidation.ValidateInt(bf.readLine());
- if(quantity < reorder_quantity){
- quantity = reorder_quantity;
- out.println("StockLevel is low, set to reorder quantity");
- }
- out.println("Enter new Replenish Level: ");
- replenish_level = InputValidation.ValidateInt(bf.readLine());
- po = new product(po.getID(), po.getName(), unit_Price, po.getWeight(), quantity,
- po.getDiscount(), po.getminitemforDiscount());
- prod_info.set(select, po);
- }catch(IndexOutOfBoundsException ibe){
- out.println("No. invalid!");
- }
- }
- /**
- * Third Menu implementation
- */
- private void ChangeDiscountStatus() throws IOException {
- // TODO Auto-generated method stub
- int i = 1;
- for(product p : prod_info){
- out.println(i + " name : "+p.getName() + " ID: " + p.getID() + " discount: " + (int)(p.getDiscount()*100)+"%" +
- " Min items quantity for discount : " + p.getminitemforDiscount());
- i++;
- }
- out.println("Please select an item : ");
- int select = InputValidation.ValidateInt(bf.readLine()) - 1;
- try{
- product po = prod_info.get(select);
- out.println("Please specify discount amount(%) : ");
- float dis = InputValidation.ValidateFloat(bf.readLine());
- if(dis > 1f)
- dis = dis/100f;
- out.println("Discount : " + (int)(dis*100)+"%");
- out.println("Please specify quantity for discount item : ");
- int quan = InputValidation.ValidateInt(bf.readLine());
- po = new product(po.getID(), po.getName(), po.getPrice(), po.getWeight(), po.getStockLevel(),
- dis, quan);
- prod_info.set(select, po);
- }catch(IndexOutOfBoundsException ibe){
- out.println("No. invalid!");
- }
- Iterator<product> itr = prod_info.iterator();
- while(itr.hasNext()){
- product el = (product) itr.next();
- out.println("name : "+el.getName() + " ID: " + el.getID() + " discount: " + el.getDiscount() +
- " Min items quantity for discount : " + el.getminitemforDiscount());
- }
- }
- /**
- * Fifth Menu implementation
- */
- private void Mst_Revenue_Product() throws FileNotFoundException, ClassNotFoundException, IOException {
- // TODO Auto-generated method stub
- List<transaction_info> t_i = new ArrayList<transaction_info>();
- List<product> p_i = new ArrayList<product>();
- p_i = prod_info;
- ArrayList<Integer> tmp = new ArrayList<Integer>(Collections.nCopies(p_i.size(), 0));
- loadItemInfo.loadtransactionInfo((ArrayList<transaction_info>) t_i, "transaction_info.tmp");
- //Count All item Transaction quantity
- for(transaction_info t : t_i){
- for(Cart c : t.get_Cart()){
- int j = 0;
- for(product p : p_i){
- int amt_count = 0;
- if(p.getID().equals(c.getID()))
- amt_count += c.getQuantity();
- tmp.set(j, tmp.get(j) + amt_count);
- j++;
- }
- }
- }
- int index = FindMaxIndex(tmp);
- if(index == -1)
- throw new IOException();
- out.println("######### Revenue Status #########");
- out.println("*** Most revenue product : " + p_i.get(index).getName());
- out.println("*** Product ID : " + p_i.get(index).getID());
- out.println("*** Sales Amount : " + tmp.get(index));
- out.println("##################################");
- }
- /**
- * Generate PNG file using Java.awt and Javax.imageIO GUI in another class
- * @throws IOException
- * @throws ClassNotFoundException
- * @throws FileNotFoundException
- */
- private void PrintPNGReport() throws IOException, ClassNotFoundException {
- // TODO Auto-generated method stub
- List<String> report = new ArrayList<String>();
- ArrayList<transaction_info> trans_info = new ArrayList<transaction_info>();
- loadItemInfo.loadtransactionInfo(trans_info, "transaction_info.tmp");
- report.add(new String("###### Report ######"));
- //Add new line
- report.add(new String(""));
- int i = 1;
- for(transaction_info t_i : trans_info){
- report.add(new String("###### Transaction " + Integer.toString(i) + " ######"));
- report.add(new String("Customer ID : " + t_i.get_customerid()));
- report.add(new String("Card Number : " + t_i.get_CardNum()));
- report.add(new String(""));
- report.add(new String("###### Detail ######"));
- report.add(new String(""));
- for(Cart c : t_i.get_Cart()){
- report.add(new String("Item ID : " + c.getID()));
- report.add(new String("Quantity : " + c.getQuantity()));
- report.add(new String(""));
- }
- i++;
- }
- report.add(new String(""));
- report.add(new String("###### End of Report ######"));
- out.println("Generating PNG file......");
- GenPNGReport.PNG_gen((ArrayList<String>) report);
- out.println("Generation is finished\n");
- }
- /**
- * This method is used for find most revenue product in transaction list
- */
- private int FindMaxIndex(List<Integer> al){
- int index = -1;
- int Max = Collections.max(al);
- while(true){
- if(al.contains(Max)){
- index = al.indexOf(Max);
- break;
- }
- }
- return index;
- }
- private void PrintList(){
- int i = 1;
- for(product p : prod_info){
- System.out.println(i + " ID: " + p.getID() + " name: " + p.getName() + " price: " +
- p.getPrice() + " quantity: " + p.getStockLevel());
- i++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement