Advertisement
Guest User

-___-

a guest
Jun 19th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.54 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.util.ArrayList;
  3. import java.util.Random;
  4. import java.util.Scanner;
  5.  
  6. public class freestyler {
  7.     public static void main(String[] args) {
  8.         Scanner input = new Scanner(System.in);
  9.         System.out.printf("Please enter your username: ");
  10.         String role = input.next();
  11.         if (role.equals("admin")) {
  12.             admin admin = new admin(role); //Object reference
  13.         } else {
  14.             user user = new user(role);
  15.         }
  16.     }
  17. }
  18.  
  19. class admin {
  20.     private String login = "admin"; ///   WHY THO??????!!!!
  21.     private String password = "password";
  22.     private String uLogin;
  23.     private Boolean authorized = false;
  24.     public admin(String objN) { // Constructor
  25.         this.uLogin = objN;
  26.         authorized = authorization.authorize(uLogin);
  27.         if (!authorized) {
  28.             System.exit(0);
  29.         }
  30.         selection();
  31.     }
  32.     private String last_access = System.getProperty("user.name");
  33.     static Scanner admin_input = new Scanner(System.in);
  34.     String last_admin() { // Accessor
  35.         return this.last_access;
  36.     } //Accessor
  37.     void approveOrder(String a) { // Mutator
  38.         this.last_access = a;
  39.         System.out.printf("Enter number of order for approval: ");
  40.         String number = "#" + admin_input.next();
  41.         order.setStatus(true, number);
  42.     }
  43.     void shipOrder(String a) {
  44.         this.last_access = a;
  45.         System.out.printf("Enter number of order for shipping: ");
  46.         String number = "#" + admin_input.next();
  47.         order.setStatus(false, number);
  48.     }
  49.     void newOrders(String a) {
  50.         this.last_access = a;
  51.         order.getOrders();
  52.     }
  53.     void selection () {
  54.         Object[] tasks = {"Approve", "Ship", "New orders", "Last admin" };
  55.         String last_user = System.getProperty("user.name");
  56.         int todo = JOptionPane.showOptionDialog(null, "What you want to do with orders?", "Select", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, tasks, tasks[0]);
  57.         switch (todo) { // Control structure
  58.             case 0:
  59.                 approveOrder(last_user);
  60.                 break;
  61.             case 1:
  62.                 shipOrder(last_user);
  63.                 break;
  64.             case 2:
  65.                 newOrders(last_user);
  66.                 break;
  67.             default:
  68.                 System.out.println("Last accessed by: " + last_admin());
  69.                 break;
  70.         }
  71.     }
  72. }
  73.  
  74. class user {
  75.     private String[] login = {"user1", "user2", "user3"}; ///   WHY THO??????!!!!
  76.     private String[] password = {"password1", "password2", "password3"};
  77.     private String uLogin;
  78.     private Boolean authorized = false;
  79.     public user(String objN) {
  80.         this.uLogin = objN;
  81.         authorized = authorization.authorize(uLogin);
  82.         if (!authorized) {
  83.             System.exit(0);
  84.         }
  85.         newOrder();
  86.     }
  87.     String[] selectItem() {return item.newItem();}
  88.     ArrayList<String[]> order() {
  89.         ArrayList<String[]> item = new ArrayList<>();
  90.         item.add(selectItem());
  91.         while (true) {
  92.             if (JOptionPane.showConfirmDialog(null,
  93.                     "Order more items?", "More items", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
  94.                 item.add(selectItem());
  95.             } else {
  96.                 break;
  97.             }
  98.         }
  99.         return item;
  100.     }
  101.     ArrayList<String[]> final_order () {
  102.         System.out.println("Start your order");
  103.         ArrayList<String[]> toReturn = order();
  104.         receipt.generateReceipt(toReturn);
  105.         return toReturn;
  106.     }
  107.     void payment_procedure() {
  108.         ArrayList<String[]> toProceed = final_order();
  109.         Boolean payment_succed = payment.calculate(toProceed);
  110.         if (payment_succed) {
  111.             order.createNew();
  112.         } else {
  113.             System.out.println("Order cancelled");
  114.             System.exit(0);
  115.         }
  116.     }
  117.     void newOrder() {
  118.         payment_procedure();
  119.     }
  120. }
  121.  
  122. class item {
  123.     static String[] newItem (){
  124.         double price = 10 + Math.random() * 140; // Math 1
  125.         String[] categories = { "Men", "Women", "Children" }; // Array
  126.         int category = JOptionPane.showOptionDialog(null,"Select category", "Category", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, categories, categories[0]);
  127.         String[] types = { "Top", "Pants", "Skirts", "Dress", "Others"};
  128.         int type = JOptionPane.showOptionDialog(null, "Select type", "Type", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, types, types[0]);
  129.         String[] colors = { "White", "Black", "Gray", "Blue", "Red", "Green", "Yellow"};
  130.         int color = JOptionPane.showOptionDialog(null, "Select color", "Color", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, colors, colors[0]);
  131.         String[] sizes = {"S", "M", "L", "XL"};
  132.         int size = JOptionPane.showOptionDialog(null, "Select size", "Size", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, sizes, sizes[0]);
  133.         String[] item = {categories[category], types[type], colors[color], sizes[size], Double.toString(Math.round(price*100.000)/100.000)}; // Math 2 + String 1
  134.         return item;
  135.     }
  136. }
  137.  
  138. class payment {
  139.     static Boolean calculate (ArrayList<String[]> toProceed) {
  140.         double total = 0;
  141.         float typecast = (float) total; // Typecasting
  142.         total = (double) typecast;
  143.         int i = 0;
  144.         for (String[] orderList: toProceed) {
  145.             i++;
  146.             double price = Double.parseDouble(orderList[orderList.length-1]);
  147.             total += price;
  148.         }
  149.         if (i >= 10) {
  150.             total = total / 100.000 * 90.000;
  151.         }
  152.         System.out.println("Total price: " + Math.round(total*100.000)/100.000);
  153.         return true;
  154.     }
  155. }
  156.  
  157. class receipt {
  158.     static Boolean generateReceipt(ArrayList<String[]> toReturn) {
  159.         System.out.println("You have ordered: ");
  160.         int i = 0;
  161.         for (String[] orderList: toReturn) {
  162.             i++;
  163.             System.out.printf("%d. ", i);
  164.             for (String orderItem : orderList) {
  165.                 System.out.printf("%s ", orderItem);
  166.             }
  167.             System.out.printf("\n");
  168.         }
  169.         if (i >= 10) {
  170.             System.out.println("Enjoy your 10% discount for bulk order");
  171.         }
  172.         if (JOptionPane.showConfirmDialog(null,
  173.                 "Proceed with payment?", "Payment", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
  174.             return true;
  175.         } else {
  176.             return false;
  177.         }
  178.     }
  179. }
  180.  
  181. class order {
  182.     static Random rand = new Random();
  183.     private static String orderStatus, orderID;
  184.     static void createNew() {
  185.         orderID = "#" + rand.nextInt(999999999) + 100000000;
  186.         System.out.println("Order " + orderID + " created and sent to approval");
  187.     }
  188.     static void setStatus(Boolean i, String orderIDN) {
  189.         orderID = orderIDN;
  190.         if (i) {
  191.             orderStatus = "APPROVED";
  192.             System.out.println("Order " + orderID  + " " + orderStatus);
  193.             System.out.println("Message sent to customer");
  194.         } else {
  195.             orderStatus = "SHIPPED";
  196.             System.out.println("Order " + orderID  + " " + orderStatus);
  197.             System.out.println("Message sent to customer");
  198.         }
  199.     }
  200.     static void getOrders() {
  201.         System.out.println("New orders");
  202.         for (int i = 0; i <= 15; i++) {
  203.             int number = rand.nextInt(999999999) + 100000000;
  204.             System.out.println("Order #" + number);
  205.         }
  206.     }
  207. }
  208.  
  209. class authorization {
  210.     static Scanner input = new Scanner(System.in);
  211.     static private String[] login = {"user1", "user2", "user3", "admin"}; // Single Array
  212.     static private String[] password = {"password1", "password2", "password3", "password"};
  213.     static Boolean authorize (String uLogin){
  214.         Boolean authorized = false;
  215.         System.out.printf("Please enter your password: ");
  216.         String secret = input.next();
  217.         for (int i = 0; i <= login.length-1; i++) {
  218.             if (uLogin.equals(login[i]) && secret.equals(password[i])) { //String 2
  219.                     authorized = true;
  220.             }
  221.         }
  222.         if (authorized) {
  223.             System.out.println("Authorization completed");
  224.         } else {
  225.             System.out.println("Authorization failed");
  226.             System.exit(0);
  227.         }
  228.         return authorized;
  229.     }
  230. }
  231.  
  232. /* README
  233.  
  234. Credentials:
  235.  
  236. admin:password
  237. user1:password1
  238. user2:password2
  239. user3:password3
  240.  
  241.  
  242.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement