Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package assignment;
- import java.util.ArrayList;
- import java.util.Scanner;
- import javax.swing.JOptionPane;
- public class core{
- private static Scanner input;
- private String account; //current logging account name
- private ArrayList<String> username = new ArrayList<>();
- private ArrayList<String> password = new ArrayList<>();
- private ArrayList<String> userOrder = new ArrayList<>(); //username that order
- private ArrayList<String> shipStatus = new ArrayList<>(); //current shipping status
- private ArrayList<String> orderStatus = new ArrayList<>(); //current order status
- private ArrayList<Top> top = new ArrayList<>(); //array for class Top, to makes iterating the order list easier
- private ArrayList<Pant> pant = new ArrayList<>(); //array for class Pant, to makes iterating the order list easier
- private ArrayList<Dress> dress = new ArrayList<>(); //array for class Dress, to makes iterating the order list easier
- private ArrayList<Skirt> skirt = new ArrayList<>(); //array for class Skirt, to makes iterating the order list easier
- private ArrayList<Integer> getUpdate = new ArrayList<>(); //array that in charge of notification
- Top classTop = new Top(); //temporary class, so that it is able add into ArrayList
- Pant classPant = new Pant(); //temporary class, so that it is able add into ArrayList
- Dress classDress = new Dress(); //temporary class, so that it is able add into ArrayList
- Skirt classSkirt = new Skirt(); //temporary class, so that it is able add into ArrayList
- boolean r = false;
- public static void main(String[] args) {
- int x = 0;
- Math.floor(x);
- core run = new core();
- input = new Scanner(System.in);
- do{
- run.r = false;
- switch (x) {
- case 0:
- x = run.mainMenu();
- break;
- case 1:
- x = run.admin();
- run.r = true;
- break;
- case 2:
- x = run.user();
- run.r = true;
- break;
- case 3:
- x = run.userLogin();
- run.r = true;
- break;
- case 4:
- x = run.userReg();
- run.r = true;
- break;
- case 5:
- x = run.userMenu();
- run.r = true;
- break;
- case 6:
- x = run.userShop();
- run.r = true;
- break;
- case 7:
- x = run.userStatus();
- run.r = true;
- break;
- case 8:
- x = run.adminMenu();
- run.r = true;
- break;
- case 9:
- x = run.adminNewOrder();
- run.r = true;
- break;
- case 10:
- x = run.adminAllOrder();
- run.r = true;
- break;
- }
- } while (run.r);
- }
- private int mainMenu(){
- int n;
- String choice[] = {
- "Admin",
- "User"
- };
- n = JOptionPane.showOptionDialog(null, "Welcome to FreeStyler Online Apparels\nLogin As:", "FreeStyler Online Apparels", JOptionPane.DEFAULT_OPTION , JOptionPane.PLAIN_MESSAGE , null, choice, -1);
- if (n == 0){
- r = true;
- return 1;
- }
- else if (n == 1){
- r = true;
- return 2;
- }
- return 0;
- }
- private int admin(){
- String x, y;
- do{
- x = JOptionPane.showInputDialog(null, "Username", "Admin", JOptionPane.DEFAULT_OPTION);
- if (x == null){
- return 0;
- }
- y = JOptionPane.showInputDialog(null, "Password", "Admin", JOptionPane.DEFAULT_OPTION);
- if (y == null){
- return 0;
- }
- if (x.equals("admin") && y.equals("admin")){
- JOptionPane.showMessageDialog(null, "Login Successfully");
- return 8;
- }
- else {
- JOptionPane.showMessageDialog(null, "Username or password incorrect");
- }
- }while(true);
- }
- private int user(){
- String choice[] = {
- "Login",
- "Register"
- };
- int x;
- x = JOptionPane.showOptionDialog(null, "", "FreeStyler Online Apparels", JOptionPane.DEFAULT_OPTION , JOptionPane.PLAIN_MESSAGE , null, choice, -1);
- if (x == 0){
- return 3;
- }
- else if (x == 1){
- return 4;
- }
- else if (x == -1){
- return 0;
- }
- return 0;
- }
- private int adminMenu(){
- int update = 0;
- int x;
- loadOrder();
- for (int i = 0; i < userOrder.size(); i++) {
- if (orderStatus.get(i).equals("Pending")){
- update++;
- }
- }
- String choice[] = {
- "View new orders [" + update +"]",
- "View all orders",
- "Log out"
- };
- if (update > 0 ){
- x = JOptionPane.showOptionDialog(null, update + " new order! Click View new orders to view new order", "FreeStyler Online Apparels", JOptionPane.DEFAULT_OPTION , JOptionPane.PLAIN_MESSAGE , null, choice, -1);
- }
- else {
- x = JOptionPane.showOptionDialog(null, "", "FreeStyler Online Apparels", JOptionPane.DEFAULT_OPTION , JOptionPane.PLAIN_MESSAGE , null, choice, -1);
- }
- if (x == -1){
- return 0;
- }
- else if (x == 0){
- return 9;
- }
- else if (x == 1){
- return 10;
- }
- else if (x == 2){
- return 0;
- }
- return 0;
- }
- private int adminNewOrder(){
- boolean bool, bool2 = true;
- String message, append;
- String choice[] = {
- "Previous",
- "Next",
- "Accept",
- "Back"
- };
- do{
- bool = false;
- loadOrder();
- int x = 1;
- for (int i = 0; i < userOrder.size(); i++) {
- if (orderStatus.get(i).equals("Pending")){
- bool = true;
- }
- }
- if (bool){
- while (bool2){
- if (x == 1){
- for (int i = 0; i < userOrder.size(); i++) {
- message = "Order #" + i + "\nUsername that order: " + userOrder.get(i) + "\n";
- if(top.get(i).amount > 0){
- append = top.get(i).group + " " + top.get(i).type + " " + top.get(i).color + " (" + top.get(i).size + ") @RM" + classTop.getPrice() + " each x " + top.get(i).amount + " = RM" + classTop.getPrice() * pant.get(i).amount + "\n";
- message = message + append;
- }
- if(pant.get(i).amount > 0){
- append = pant.get(i).group + " " + pant.get(i).type + " " + pant.get(i).color + " (" + pant.get(i).size + ") @RM" + classPant.getPrice() + " each x " + pant.get(i).amount + " = RM" + classPant.getPrice() * pant.get(i).amount + "\n";
- message = message + append;
- }
- if(dress.get(i).amount > 0){
- append = dress.get(i).group + " " + dress.get(i).type + " " + dress.get(i).color + " (" + dress.get(i).size + ") @RM" + classDress.getPrice() + " each x " + dress.get(i).amount + " = RM" + classDress.getPrice() * dress.get(i).amount + "\n";
- message = message + append;
- }
- if(skirt.get(i).amount > 0){
- append = skirt.get(i).group + " " + skirt.get(i).type + " " + skirt.get(i).color + " (" + skirt.get(i).size + ") @RM" + classSkirt.getPrice() + " each x " + skirt.get(i).amount + " = RM" + classSkirt.getPrice() * skirt.get(i).amount + "\n";
- message = message + append;
- }
- x = JOptionPane.showOptionDialog(null, message, "FreeStyler Online Apparels", JOptionPane.DEFAULT_OPTION , JOptionPane.PLAIN_MESSAGE , null, choice, -1);
- if (x == -1){
- return 8;
- }
- else if (x == 2){
- setStatus(i);
- JOptionPane.showMessageDialog(null, "Order " + i + " order and shipping accepted");
- bool2 = false;
- }
- else if (x == 3){
- return 8;
- }
- else if (x == 0){
- break;
- }
- }
- }
- else if (x == 0){
- for (int i = userOrder.size() - 1; i >= 0; i--) {
- message = "Order #" + i + "\nUsername that order: " + userOrder.get(i) + "\n";
- if(top.get(i).amount > 0){
- append = top.get(i).group + " " + top.get(i).type + " " + top.get(i).color + " (" + top.get(i).size + ") @RM" + classTop.getPrice() + " each x " + top.get(i).amount + " = RM" + classTop.getPrice() * pant.get(i).amount + "\n";
- message = message + append;
- }
- if(pant.get(i).amount > 0){
- append = pant.get(i).group + " " + pant.get(i).type + " " + pant.get(i).color + " (" + pant.get(i).size + ") @RM" + classPant.getPrice() + " each x " + pant.get(i).amount + " = RM" + classPant.getPrice() * pant.get(i).amount + "\n";
- message = message + append;
- }
- if(dress.get(i).amount > 0){
- append = dress.get(i).group + " " + dress.get(i).type + " " + dress.get(i).color + " (" + dress.get(i).size + ") @RM" + classDress.getPrice() + " each x " + dress.get(i).amount + " = RM" + classDress.getPrice() * dress.get(i).amount + "\n";
- message = message + append;
- }
- if(skirt.get(i).amount > 0){
- append = skirt.get(i).group + " " + skirt.get(i).type + " " + skirt.get(i).color + " (" + skirt.get(i).size + ") @RM" + classSkirt.getPrice() + " each x " + skirt.get(i).amount + " = RM" + classSkirt.getPrice() * skirt.get(i).amount + "\n";
- message = message + append;
- }
- x = JOptionPane.showOptionDialog(null, message, "FreeStyler Online Apparels", JOptionPane.DEFAULT_OPTION , JOptionPane.PLAIN_MESSAGE , null, choice, -1);
- if (x == -1){
- return 8;
- }
- else if (x == 2){
- setStatus(i);
- JOptionPane.showMessageDialog(null, "Order #" + i + " order and shipping accepted");
- bool2 = false;
- break;
- }
- else if (x == 3){
- return 8;
- }
- else if (x == 1){
- break;
- }
- }
- }
- }
- }
- else if (!bool){
- JOptionPane.showMessageDialog(null, "Empty");
- return 8;
- }
- }while(true);
- }
- private int adminAllOrder(){
- boolean bool = false, bool2 = true;
- String choice[] = {
- "Previous",
- "Next",
- "Back"
- };
- int x, sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
- float total;
- String message, append;
- loadOrder();
- x = 1;
- if (orderStatus.size() >= 0){
- bool = true;
- }
- if (bool){
- while (bool2){
- if (x == 1){
- for (int i = 0; i < userOrder.size(); i++) {
- message = "Order #" + i + "\nUsername that order: " + userOrder.get(i) + "\n";
- if(top.get(i).amount > 0){
- sum1 = classTop.getPrice() * top.get(i).amount;
- append = top.get(i).group + " " + top.get(i).type + " " + top.get(i).color + " (" + top.get(i).size + ") @RM" + classTop.getPrice() + " each x " + top.get(i).amount + " = RM" + sum1 + "\n";
- message = message + append;
- }
- if(pant.get(i).amount > 0){
- sum2 = classPant.getPrice() * pant.get(i).amount;
- append = pant.get(i).group + " " + pant.get(i).type + " " + pant.get(i).color + " (" + pant.get(i).size + ") @RM" + classPant.getPrice() + " each x " + pant.get(i).amount + " = RM" + sum2 + "\n";
- message = message + append;
- }
- if(dress.get(i).amount > 0){
- sum3 = classDress.getPrice() * dress.get(i).amount;
- append = dress.get(i).group + " " + dress.get(i).type + " " + dress.get(i).color + " (" + dress.get(i).size + ") @RM" + classDress.getPrice() + " each x " + dress.get(i).amount + " = RM" + sum3 + "\n";
- message = message + append;
- }
- if(skirt.get(i).amount > 0){
- sum4 = classSkirt.getPrice() * skirt.get(i).amount;
- append = skirt.get(i).group + " " + skirt.get(i).type + " " + skirt.get(i).color + " (" + skirt.get(i).size + ") @RM" + classSkirt.getPrice() + " each x " + skirt.get(i).amount + " = RM" + sum4 + "\n";
- message = message + append;
- }
- total = sum1 + sum2 + sum3 + sum4;
- append = "Discount: ";
- message = message + append;
- if (top.get(i).amount + pant.get(i).amount + dress.get(i).amount + skirt.get(i).amount >= 10){
- append = "10%\n";
- message = message + append;
- total = total * (float)0.9;
- append = "Total = RM" + total;
- message = message + append;
- }
- else if (top.get(i).amount + pant.get(i).amount + dress.get(i).amount + skirt.get(i).amount < 10){
- append = "0%\n";
- message = message + append;
- append = "Total = RM" + total;
- message = message + append;
- }
- x = JOptionPane.showOptionDialog(null, message, "FreeStyler Online Apparels", JOptionPane.DEFAULT_OPTION , JOptionPane.PLAIN_MESSAGE , null, choice, -1);
- if (x == -1){
- return 8;
- }
- else if (x == 2){
- return 8;
- }
- else if (x == 0){
- break;
- }
- }
- }
- else if (x == 0){
- for (int i = userOrder.size() - 1; i >= 0; i--) {
- message = "Order #" + i + "\nUsername that order: " + userOrder.get(i) + "\n";
- if(top.get(i).amount > 0){
- append = top.get(i).group + " " + top.get(i).type + " " + top.get(i).color + " (" + top.get(i).size + ") @RM" + classTop.getPrice() + " each x " + top.get(i).amount + " = RM" + (classTop.getPrice() * top.get(i).amount) + "\n";
- message = message + append;
- }
- if(pant.get(i).amount > 0){
- append = pant.get(i).group + " " + pant.get(i).type + " " + pant.get(i).color + " (" + pant.get(i).size + ") @RM" + classPant.getPrice() + " each x " + pant.get(i).amount + " = RM" + (classPant.getPrice() * pant.get(i).amount) + "\n";
- message = message + append;
- }
- if(dress.get(i).amount > 0){
- append = dress.get(i).group + " " + dress.get(i).type + " " + dress.get(i).color + " (" + dress.get(i).size + ") @RM" + classDress.getPrice() + " each x " + dress.get(i).amount + " = RM" + (classDress.getPrice() * dress.get(i).amount) + "\n";
- message = message + append;
- }
- if(skirt.get(i).amount > 0){
- append = skirt.get(i).group + " " + skirt.get(i).type + " " + skirt.get(i).color + " (" + skirt.get(i).size + ") @RM" + classSkirt.getPrice() + " each x " + skirt.get(i).amount + " = RM" + (classSkirt.getPrice() * skirt.get(i).amount) + "\n";
- message = message + append;
- }
- total = sum1 + sum2 + sum3 + sum4;
- append = "Discount: ";
- message = message + append;
- if (top.get(i).amount + pant.get(i).amount + dress.get(i).amount + skirt.get(i).amount >= 10){
- append = "10%\n";
- message = message + append;
- total = total * (float)0.9;
- append = "Total = RM" + total;
- message = message + append;
- }
- else if (top.get(i).amount + pant.get(i).amount + dress.get(i).amount + skirt.get(i).amount < 10){
- append = "0%\n";
- message = message + append;
- append = "Total = RM" + total;
- message = message + append;
- }
- x = JOptionPane.showOptionDialog(null, message, "FreeStyler Online Apparels", JOptionPane.DEFAULT_OPTION , JOptionPane.PLAIN_MESSAGE , null, choice, -1);
- if (x == -1){
- return 8;
- }
- else if (x == 2){
- return 8;
- }
- else if (x == 1){
- break;
- }
- }
- }
- }
- }
- else if (!bool){
- JOptionPane.showMessageDialog(null, "Empty");
- return 8;
- }
- return 0;
- }
- private int userLogin(){
- boolean bool = true;
- String user, pass = null;
- loadDat();
- do{
- System.out.println("-1 to back");
- System.out.print("Username: ");
- try {
- user = input.nextLine();
- } catch (Exception e){
- System.out.println("Error: " + e);
- continue;
- }
- if (backtrack(user)){
- bool = false;
- return 2;
- }
- System.out.print("Password: ");
- try{
- pass = input.nextLine();
- } catch (Exception e){
- System.out.println("Error: " + e);
- }
- if (backtrack(pass)){
- bool = false;
- return 2;
- }
- else {
- for (int i = 0; i < this.username.size(); i++) {
- if (user.equals(this.username.get(i)) && pass.equals(this.password.get(i))){
- System.out.println("Login Successfully");
- System.out.println();
- bool = false;
- account = this.username.get(i);
- return 5;
- }
- }
- System.out.println("Invalid username or password");
- System.out.println();
- }
- }while(bool);
- return 0;
- }
- private int userReg(){
- String user, pass;
- boolean bool = true;
- boolean bool2 = false;
- boolean taken;
- loadDat();
- System.out.println("-1 to back");
- System.out.println("Register as");
- do{
- taken = false;
- System.out.print("Username: ");
- user = input.nextLine();
- if (backtrack(user)){
- return 2;
- }
- for (int i = 0; i < this.username.size(); i++) {
- if (user.equals(this.username.get(i))){
- System.out.println("Username taken, please take different username");
- System.out.println();
- taken = true;
- continue;
- }
- }
- if (taken){
- continue;
- }
- else if(user.contains(" ")){
- System.out.println("Username or password cannot contain space");
- System.out.println();
- continue;
- }
- else {
- do {
- bool2 = false;
- System.out.print("Password: ");
- pass = input.nextLine();
- if (backtrack(pass)){
- return 2;
- }
- else if (pass.contains(" ")){
- System.out.println("Username or password cannot contain space");
- System.out.println();
- bool2 = true;
- continue;
- }
- else {
- addDat(user, pass);
- System.out.println("Account created successfully");
- System.out.println();
- bool = false;
- return 2;
- }
- }while(bool2);
- }
- }while(bool);
- return 0;
- }
- private int userMenu(){
- boolean bool = true;
- String x = null;
- System.out.println("Welcome back, " + account);
- loadOrder();
- for (int i = 0; i < userOrder.size(); i++) {
- if (userOrder.get(i).equals(account) && getUpdate.get(i) == 1){
- System.out.println("Your order #" + i + " has been accepted.");
- System.out.println("Enter 2 to view the order status");
- setUpdate(i);
- }
- }
- do{
- System.out.println("(1)Shop\n(2)Status\n(3)Log Out");
- try {
- x = input.nextLine();
- } catch (Exception e) {
- System.out.println("Invalid input, " + e);
- }
- if (x.equals("1")){
- bool = false;
- return 6;
- }
- else if (x.equals("2")){
- bool = false;
- return 7;
- }
- else if (x.equals("3")){
- bool = false;
- return 0;
- }
- else {
- System.out.println("Invalid input, please try again");
- }
- }while(bool);
- return 0;
- }
- private int userShop(){
- boolean bool, bool2, bool3, checkOut;
- int x, color, size = 0, amount, total;
- String in;
- String c, s, g, t;
- do {
- checkOut = false;
- System.out.println("-1 to back, clear cart");
- System.out.println("Men\tWomen\n(1)Top\t(3)Dress\n(2)Pant\t(4)Skirt\n(5)View cart\n(6)Checkout");
- try {
- in = input.nextLine();
- x = Integer.parseInt(in);
- }
- catch(Exception e){
- System.out.println("Invalid input, " + e);
- System.out.println();
- continue;
- }
- if (x >= 1 && x <= 4){
- do{
- bool = true;
- System.out.println("-1 to back");
- System.out.println("Choose a color:");
- System.out.println("(1)White\n(2)Black\n(3)Red\n(4)Green\n(5)Blue");
- try {
- in = input.nextLine();
- color = Integer.parseInt(in);
- }
- catch (Exception e){
- System.out.println("Invalid input, " + e);
- System.out.println();
- continue;
- }
- if (color >= 1 && color <= 5){
- do {
- bool2 = true;
- System.out.println("-1 to back");
- System.out.println("Choose a size:");
- System.out.println("(1)S\n(2)M\n(3)L");
- try {
- in = input.nextLine();
- size = Integer.parseInt(in);
- }
- catch (Exception e){
- System.out.println("Invalid input, " + e);
- System.out.println();
- continue;
- }
- if (size >= 1 && size <= 3){
- do {
- bool3 = true;
- System.out.println("-1 to back");
- System.out.println("Purchase total of 10 pieces will get 10% discount!");
- switch (x) {
- case 1:
- System.out.print("Amount @RM" + classTop.getPrice() +" each: ");
- break;
- case 2:
- System.out.print("Amount @RM" + classPant.getPrice() +" each: ");
- break;
- case 3:
- System.out.print("Amount @RM" + classDress.getPrice() +" each: ");
- break;
- case 4:
- System.out.print("Amount @RM" + classSkirt.getPrice() +" each: ");
- break;
- }
- try {
- in = input.nextLine();
- amount = Integer.parseInt(in);
- }
- catch (Exception e){
- System.out.println("Invalid input, " + e);
- System.out.println();
- continue;
- }
- if (backtrack(amount)){
- System.out.println();
- bool3 = false;
- break;
- }
- else if (amount < 1){
- System.out.println("Amount cannot less than 1");
- System.out.println();
- continue;
- }
- else {
- g = gGet(x);
- c = cGet(color);
- s = sGet(size);
- t = tGet(x);
- addCart(t, c, s, amount);
- System.out.println();
- System.out.printf("%s %s %s (%s) x %d added to cart\n", g, t, c, s, amount);
- System.out.println();
- bool = false;
- bool2 = false;
- bool3 = false;
- }
- } while (bool3);
- }
- else if(backtrack(size)){
- bool2 = false;
- break;
- }
- else {
- System.out.println("Invalid input, please try again");
- System.out.println();
- }
- }while(bool2);
- }
- else if (backtrack(color)){
- bool = false;
- break;
- }
- else {
- System.out.println("Invalid input, please try again");
- System.out.println();
- }
- }while(bool);
- }
- else if(x == 5){
- if (classTop.amount + classPant.amount + classDress.amount + classSkirt.amount > 0){
- if (classTop.amount >= 1){
- System.out.printf("%s %s %s (%s) @RM%d each x %d = RM%d\n", classTop.group, classTop.type, classTop.color, classTop.size, classTop.getPrice(), classTop.amount, (classTop.amount * classTop.getPrice()));
- }
- if (classPant.amount >= 1){
- System.out.printf("%s %s %s (%s) @RM%d each x %d = RM%d\n", classPant.group, classPant.type, classPant.color, classPant.size, classPant.getPrice(), classPant.amount, (classPant.amount * classPant.getPrice()));
- }
- if (classDress.amount >= 1){
- System.out.printf("%s %s %s (%s) @RM%d each x %d = RM%d\n", classDress.group, classDress.type, classDress.color, classDress.size, classDress.getPrice(), classDress.amount, (classDress.amount * classDress.getPrice()));
- }
- if (classSkirt.amount >= 1){
- System.out.printf("%s %s %s (%s) @RM%d each x %d = RM%d\n", classSkirt.group, classSkirt.type, classSkirt.color, classSkirt.size, classSkirt.getPrice(), classSkirt.amount, (classSkirt.amount * classSkirt.getPrice()));
- }
- total = (classTop.amount * classTop.getPrice()) + (classPant.amount * classPant.getPrice()) + (classDress.amount * classDress.getPrice()) + (classSkirt.amount * classSkirt.getPrice());
- Math.abs(total);
- System.out.print("Discount: ");
- if (classTop.amount + classPant.amount + classDress.amount + classSkirt.amount >= 10){
- System.out.println("10%");
- System.out.printf("Total = RM%.2f\n", total * 0.9);
- }
- else {
- System.out.println("0%");
- System.out.printf("Total = RM%d\n", total);
- }
- }
- else {
- System.out.println("No item in the cart");
- }
- System.out.println();
- System.out.println("Press Enter to continue");
- input.nextLine();
- }
- else if(x == 6){
- if (classTop.amount + classPant.amount + classDress.amount + classSkirt.amount > 0){
- addOrder(account);
- checkOut = true;
- loadOrder();
- total = (classTop.amount * classTop.getPrice()) + (classPant.amount * classPant.getPrice()) + (classDress.amount * classDress.getPrice()) + (classSkirt.amount * classSkirt.getPrice());
- System.out.println("The total is :" + total);
- System.out.println("Thanks\nYour order number is #" + (userOrder.size() - 1) + "\nPlease come again!\n");
- classTop.amount = 0;
- classPant.amount = 0;
- classDress.amount = 0;
- classSkirt.amount = 0;
- return 5;
- }
- else {
- System.out.println("Thanks, please come again\n");
- return 5;
- }
- }
- else if(backtrack(x)){
- classTop.amount = 0;
- classPant.amount = 0;
- classDress.amount = 0;
- classSkirt.amount = 0;
- return 5;
- }
- else {
- System.out.println("Invalid input, try again");
- }
- }while(!checkOut);
- return 0;
- }
- private int userStatus(){
- loadOrder();
- boolean order = false;
- int total;
- for (int i = 0; i < this.userOrder.size(); i++) {
- if (this.userOrder.get(i).equals(account)){
- System.out.println();
- order = true;
- System.out.println("Order #" + i);
- if(((Top)top.get(i)).amount > 0){
- System.out.printf("%s %s %s (%s) @RM%d each x %d = RM%d\n", ((Top)top.get(i)).group, ((Top)top.get(i)).type, ((Top)top.get(i)).color, ((Top)top.get(i)).size, classTop.getPrice(), ((Top)top.get(i)).amount, (classTop.getPrice() * ((Top)top.get(i)).amount));
- }
- if(((Pant)pant.get(i)).amount > 0){
- System.out.printf("%s %s %s (%s) @RM%d each x %d = RM%d\n", ((Pant)pant.get(i)).group, ((Pant)pant.get(i)).type, ((Pant)pant.get(i)).color, ((Pant)pant.get(i)).size, classPant.getPrice(), ((Pant)pant.get(i)).amount, (classPant.getPrice() * ((Pant)pant.get(i)).amount));
- }
- if(((Dress)dress.get(i)).amount > 0){
- System.out.printf("%s %s %s (%s) @RM%d each x %d = RM%d\n", ((Dress)dress.get(i)).group, ((Dress)dress.get(i)).type, ((Dress)dress.get(i)).color, ((Dress)dress.get(i)).size, classDress.getPrice(), ((Dress)dress.get(i)).amount, (classDress.getPrice() * ((Dress)dress.get(i)).amount));
- }
- if(((Skirt)skirt.get(i)).amount > 0){
- System.out.printf("%s %s %s (%s) @RM%d each x %d = RM%d\n", ((Skirt)skirt.get(i)).group, ((Skirt)skirt.get(i)).type, ((Skirt)skirt.get(i)).color, ((Skirt)skirt.get(i)).size, classSkirt.getPrice(), ((Skirt)skirt.get(i)).amount, (classSkirt.getPrice() * ((Skirt)skirt.get(i)).amount));
- }
- total = (((Top)top.get(i)).amount * classTop.getPrice()) + (((Pant)pant.get(i)).amount * classPant.getPrice()) + (((Dress)dress.get(i)).amount * classDress.getPrice()) + (((Skirt)skirt.get(i)).amount * classSkirt.getPrice());
- Math.abs(total);
- System.out.print("Discount: ");
- if (((Top)top.get(i)).amount + ((Pant)pant.get(i)).amount + ((Dress)dress.get(i)).amount + ((Skirt)skirt.get(i)).amount >= 10){
- System.out.println("10%");
- System.out.printf("Total = RM%.2f\n", total * 0.9);
- }
- else {
- System.out.println("0%");
- System.out.printf("Total = RM%d\n", total);
- }
- System.out.println("Order confirm: " + orderStatus.get(i));
- System.out.println("Shipping confirm: " + shipStatus.get(i));
- }
- }
- if (!order){
- System.out.println();
- System.out.println("Empty, you did not order anything in the past");
- }
- System.out.println("\nPress Enter to continue");
- input.nextLine();
- return 5;
- }
- private void loadDat(){ //load or refresh username and password data into memory
- readWrite read = new readWrite("login.txt");
- read.openRead("login.txt");
- read.readDat();
- username.clear();
- password.clear();
- for (int i = 0; i < read.user.size(); i++) { //pass data from readWrite class
- this.username.add(read.user.get(i));
- this.password.add(read.pass.get(i));
- }
- read.closeRead();
- }
- private void addDat(String user, String pass){ //add new username and password data into memory
- readWrite write = new readWrite("login.txt");
- write.openRead("login.txt");
- write.readDat();
- write.closeRead();
- write.user.add(user); //pass new username and password data to readWrite class
- write.pass.add(pass);
- write.writeDat();
- write.closeWrite();
- }
- private void loadOrder(){ //load or refresh orders data into memory
- readWrite readOrder = new readWrite("order.txt");
- readOrder.openRead("order.txt");
- readOrder.readOrder();
- userOrder.clear(); //clear all the existing data in the memory, to refresh
- orderStatus.clear();
- shipStatus.clear();
- top.clear();
- pant.clear();
- dress.clear();
- skirt.clear();
- getUpdate.clear();
- for (int i = 0; i < readOrder.userOrder.size(); i++) { //pass order data from readWrite class
- this.userOrder.add(readOrder.userOrder.get(i));
- this.orderStatus.add(readOrder.orderStatus.get(i));
- this.shipStatus.add(readOrder.shipStatus.get(i));
- this.top.add(readOrder.top.get(i));
- this.pant.add(readOrder.pant.get(i));
- this.dress.add(readOrder.dress.get(i));
- this.skirt.add(readOrder.skirt.get(i));
- this.getUpdate.add(readOrder.getUpdate.get(i));
- }
- readOrder.closeRead();
- }
- private void addOrder(String user){ //add new data to readWrite class
- readWrite write = new readWrite("order.txt");
- write.openRead("order.txt");
- write.readOrder();
- write.closeRead();
- write.userOrder.add(user); //pass new orders data to readWrite class
- write.orderStatus.add("Pending");
- write.shipStatus.add("Pending");
- write.top.add(classTop);
- write.pant.add(classPant);
- write.dress.add(classDress);
- write.skirt.add(classSkirt);
- write.getUpdate.add(0);
- write.writeOrder();
- write.closeWrite();
- }
- private void setStatus(int orderNumber){ //admin set order status and shipping status to "accepted"
- readWrite write = new readWrite("order.txt");
- write.openRead("order.txt");
- write.readOrder();
- write.closeRead();
- write.orderStatus.set(orderNumber, "Accepted");
- write.shipStatus.set(orderNumber, "Accepted");
- write.getUpdate.set(orderNumber, 1);
- write.writeOrder();
- write.closeWrite();
- }
- private void setUpdate(int orderNumber){ //admin tell user that his order has been confirmed
- readWrite write = new readWrite("order.txt");
- write.openRead("order.txt");
- write.readOrder();
- write.closeRead();
- write.getUpdate.set(orderNumber, 0);
- write.writeOrder();
- write.closeWrite();
- }
- private boolean backtrack(String back){ //check if input is -1, return to previous page
- if (back.equals("-1")){
- return true;
- }
- else {
- return false;
- }
- }
- private boolean backtrack(int back){ //check if input is -1, return to previous page
- if (back == -1){
- return true;
- }
- else {
- return false;
- }
- }
- private String gGet(int x){ //translate user input into string form
- switch (x) {
- case 1:
- case 2:
- return "Men";
- case 3:
- case 4:
- return "Women";
- default:
- return "Invalid";
- }
- }
- private String tGet(int x){ //translate user input into string form
- switch (x) {
- case 1:
- return "Top";
- case 2:
- return "Pant";
- case 3:
- return "Dress";
- case 4:
- return "Skirt";
- default:
- return "Invalid";
- }
- }
- private String cGet(int x){ //translate user input into string form
- switch (x) {
- case 1:
- return "White";
- case 2:
- return "Black";
- case 3:
- return "Red";
- case 4:
- return "Green";
- case 5:
- return "Blue";
- default:
- return "Invalid";
- }
- }
- private String sGet(int x){ //translate user input into string form
- switch (x) {
- case 1:
- return "S";
- case 2:
- return "M";
- case 3:
- return "L";
- default:
- return "Invalid";
- }
- }
- private void addCart(String t, String c, String s, int amount){ //add item into cart
- switch (t) {
- case "Top":
- classTop.amount = amount;
- classTop.color = c;
- classTop.size = s;
- classTop.group = "Men";
- break;
- case "Pant":
- classPant.amount = amount;
- classPant.color = c;
- classPant.size = s;
- classPant.group = "Men";
- break;
- case "Dress":
- classDress.amount = amount;
- classDress.color = c;
- classDress.size = s;
- classDress.group = "Women";
- break;
- case "Skirt":
- classSkirt.amount = amount;
- classSkirt.color = c;
- classSkirt.size = s;
- classSkirt.group = "Women";
- break;
- default:
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement