Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.util.ArrayList;
- import java.util.Random;
- import java.util.Scanner;
- public class freestyler {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.printf("Please enter your username: ");
- String role = input.next();
- if (role.equals("admin")) {
- admin admin = new admin(role); //Object reference
- } else {
- user user = new user(role);
- }
- }
- }
- class admin {
- private String login = "admin"; /// WHY THO??????!!!!
- private String password = "password";
- private String uLogin;
- private Boolean authorized = false;
- public admin(String objN) { // Constructor
- this.uLogin = objN;
- authorized = authorization.authorize(uLogin);
- if (!authorized) {
- System.exit(0);
- }
- selection();
- }
- private String last_access = System.getProperty("user.name");
- static Scanner admin_input = new Scanner(System.in);
- String last_admin() { // Accessor
- return this.last_access;
- } //Accessor
- void approveOrder(String a) { // Mutator
- this.last_access = a;
- System.out.printf("Enter number of order for approval: ");
- String number = "#" + admin_input.next();
- order.setStatus(true, number);
- }
- void shipOrder(String a) {
- this.last_access = a;
- System.out.printf("Enter number of order for shipping: ");
- String number = "#" + admin_input.next();
- order.setStatus(false, number);
- }
- void newOrders(String a) {
- this.last_access = a;
- order.getOrders();
- }
- void selection () {
- Object[] tasks = {"Approve", "Ship", "New orders", "Last admin" };
- String last_user = System.getProperty("user.name");
- int todo = JOptionPane.showOptionDialog(null, "What you want to do with orders?", "Select", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, tasks, tasks[0]);
- switch (todo) { // Control structure
- case 0:
- approveOrder(last_user);
- break;
- case 1:
- shipOrder(last_user);
- break;
- case 2:
- newOrders(last_user);
- break;
- default:
- System.out.println("Last accessed by: " + last_admin());
- break;
- }
- }
- }
- class user {
- private String[] login = {"user1", "user2", "user3"}; /// WHY THO??????!!!!
- private String[] password = {"password1", "password2", "password3"};
- private String uLogin;
- private Boolean authorized = false;
- public user(String objN) {
- this.uLogin = objN;
- authorized = authorization.authorize(uLogin);
- if (!authorized) {
- System.exit(0);
- }
- newOrder();
- }
- String[] selectItem() {return item.newItem();}
- ArrayList<String[]> order() {
- ArrayList<String[]> item = new ArrayList<>();
- item.add(selectItem());
- while (true) {
- if (JOptionPane.showConfirmDialog(null,
- "Order more items?", "More items", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
- item.add(selectItem());
- } else {
- break;
- }
- }
- return item;
- }
- ArrayList<String[]> final_order () {
- System.out.println("Start your order");
- ArrayList<String[]> toReturn = order();
- receipt.generateReceipt(toReturn);
- return toReturn;
- }
- void payment_procedure() {
- ArrayList<String[]> toProceed = final_order();
- Boolean payment_succed = payment.calculate(toProceed);
- if (payment_succed) {
- order.createNew();
- } else {
- System.out.println("Order cancelled");
- System.exit(0);
- }
- }
- void newOrder() {
- payment_procedure();
- }
- }
- class item {
- static String[] newItem (){
- double price = 10 + Math.random() * 140; // Math 1
- String[] categories = { "Men", "Women", "Children" }; // Array
- int category = JOptionPane.showOptionDialog(null,"Select category", "Category", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, categories, categories[0]);
- String[] types = { "Top", "Pants", "Skirts", "Dress", "Others"};
- int type = JOptionPane.showOptionDialog(null, "Select type", "Type", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, types, types[0]);
- String[] colors = { "White", "Black", "Gray", "Blue", "Red", "Green", "Yellow"};
- int color = JOptionPane.showOptionDialog(null, "Select color", "Color", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, colors, colors[0]);
- String[] sizes = {"S", "M", "L", "XL"};
- int size = JOptionPane.showOptionDialog(null, "Select size", "Size", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, sizes, sizes[0]);
- String[] item = {categories[category], types[type], colors[color], sizes[size], Double.toString(Math.round(price*100.000)/100.000)}; // Math 2 + String 1
- return item;
- }
- }
- class payment {
- static Boolean calculate (ArrayList<String[]> toProceed) {
- double total = 0;
- float typecast = (float) total; // Typecasting
- total = (double) typecast;
- int i = 0;
- for (String[] orderList: toProceed) {
- i++;
- double price = Double.parseDouble(orderList[orderList.length-1]);
- total += price;
- }
- if (i >= 10) {
- total = total / 100.000 * 90.000;
- }
- System.out.println("Total price: " + Math.round(total*100.000)/100.000);
- return true;
- }
- }
- class receipt {
- static Boolean generateReceipt(ArrayList<String[]> toReturn) {
- System.out.println("You have ordered: ");
- int i = 0;
- for (String[] orderList: toReturn) {
- i++;
- System.out.printf("%d. ", i);
- for (String orderItem : orderList) {
- System.out.printf("%s ", orderItem);
- }
- System.out.printf("\n");
- }
- if (i >= 10) {
- System.out.println("Enjoy your 10% discount for bulk order");
- }
- if (JOptionPane.showConfirmDialog(null,
- "Proceed with payment?", "Payment", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
- return true;
- } else {
- return false;
- }
- }
- }
- class order {
- static Random rand = new Random();
- private static String orderStatus, orderID;
- static void createNew() {
- orderID = "#" + rand.nextInt(999999999) + 100000000;
- System.out.println("Order " + orderID + " created and sent to approval");
- }
- static void setStatus(Boolean i, String orderIDN) {
- orderID = orderIDN;
- if (i) {
- orderStatus = "APPROVED";
- System.out.println("Order " + orderID + " " + orderStatus);
- System.out.println("Message sent to customer");
- } else {
- orderStatus = "SHIPPED";
- System.out.println("Order " + orderID + " " + orderStatus);
- System.out.println("Message sent to customer");
- }
- }
- static void getOrders() {
- System.out.println("New orders");
- for (int i = 0; i <= 15; i++) {
- int number = rand.nextInt(999999999) + 100000000;
- System.out.println("Order #" + number);
- }
- }
- }
- class authorization {
- static Scanner input = new Scanner(System.in);
- static private String[] login = {"user1", "user2", "user3", "admin"}; // Single Array
- static private String[] password = {"password1", "password2", "password3", "password"};
- static Boolean authorize (String uLogin){
- Boolean authorized = false;
- System.out.printf("Please enter your password: ");
- String secret = input.next();
- for (int i = 0; i <= login.length-1; i++) {
- if (uLogin.equals(login[i]) && secret.equals(password[i])) { //String 2
- authorized = true;
- }
- }
- if (authorized) {
- System.out.println("Authorization completed");
- } else {
- System.out.println("Authorization failed");
- System.exit(0);
- }
- return authorized;
- }
- }
- /* README
- Credentials:
- admin:password
- user1:password1
- user2:password2
- user3:password3
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement