Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
6.5 kB
2
Indexable
Never
import java.util.Scanner;

enum Color {
    //Color end string, color reset
    RESET("\033[0m"),

    // Regular Colors. Normal color, no bold, background color etc.
    BLACK("\033[0;30m"),    // BLACK
    RED("\033[0;31m"),      // RED
    GREEN("\033[0;32m"),    // GREEN
    YELLOW("\033[0;33m"),   // YELLOW
    BLUE("\033[0;34m"),     // BLUE
    MAGENTA("\033[0;35m"),  // MAGENTA
    CYAN("\033[0;36m"),     // CYAN
    WHITE("\033[0;37m"),    // WHITE
    PURPLE("\033[1;35m"), //PURPLE

    // Bold
    BLACK_BOLD("\033[1;30m"),   // BLACK
    RED_BOLD("\033[1;31m"),     // RED
    GREEN_BOLD("\033[1;32m"),   // GREEN
    YELLOW_BOLD("\033[1;33m"),  // YELLOW
    BLUE_BOLD("\033[1;34m"),    // BLUE
    MAGENTA_BOLD("\033[1;35m"), // MAGENTA
    CYAN_BOLD("\033[1;36m"),    // CYAN
    WHITE_BOLD("\033[1;37m"),   // WHITE

    // Underline
    BLACK_UNDERLINED("\033[4;30m"),     // BLACK
    RED_UNDERLINED("\033[4;31m"),       // RED
    GREEN_UNDERLINED("\033[4;32m"),     // GREEN
    YELLOW_UNDERLINED("\033[4;33m"),    // YELLOW
    BLUE_UNDERLINED("\033[4;34m"),      // BLUE
    MAGENTA_UNDERLINED("\033[4;35m"),   // MAGENTA
    CYAN_UNDERLINED("\033[4;36m"),      // CYAN
    WHITE_UNDERLINED("\033[4;37m"),     // WHITE

    // Background
    BLACK_BACKGROUND("\033[40m"),   // BLACK
    RED_BACKGROUND("\033[41m"),     // RED
    GREEN_BACKGROUND("\033[42m"),   // GREEN
    YELLOW_BACKGROUND("\033[43m"),  // YELLOW
    BLUE_BACKGROUND("\033[44m"),    // BLUE
    MAGENTA_BACKGROUND("\033[45m"), // MAGENTA
    CYAN_BACKGROUND("\033[46m"),    // CYAN
    WHITE_BACKGROUND("\033[47m"),   // WHITE

    // High Intensity
    BLACK_BRIGHT("\033[0;90m"),     // BLACK
    RED_BRIGHT("\033[0;91m"),       // RED
    GREEN_BRIGHT("\033[0;92m"),     // GREEN
    YELLOW_BRIGHT("\033[0;93m"),    // YELLOW
    BLUE_BRIGHT("\033[0;94m"),      // BLUE
    MAGENTA_BRIGHT("\033[0;95m"),   // MAGENTA
    CYAN_BRIGHT("\033[0;96m"),      // CYAN
    WHITE_BRIGHT("\033[0;97m"),     // WHITE

    // Bold High Intensity
    BLACK_BOLD_BRIGHT("\033[1;90m"),    // BLACK
    RED_BOLD_BRIGHT("\033[1;91m"),      // RED
    GREEN_BOLD_BRIGHT("\033[1;92m"),    // GREEN
    YELLOW_BOLD_BRIGHT("\033[1;93m"),   // YELLOW
    BLUE_BOLD_BRIGHT("\033[1;94m"),     // BLUE
    MAGENTA_BOLD_BRIGHT("\033[1;95m"),  // MAGENTA
    CYAN_BOLD_BRIGHT("\033[1;96m"),     // CYAN
    WHITE_BOLD_BRIGHT("\033[1;97m"),    // WHITE

    // High Intensity backgrounds
    BLACK_BACKGROUND_BRIGHT("\033[0;100m"),     // BLACK
    RED_BACKGROUND_BRIGHT("\033[0;101m"),       // RED
    GREEN_BACKGROUND_BRIGHT("\033[0;102m"),     // GREEN
    YELLOW_BACKGROUND_BRIGHT("\033[0;103m"),    // YELLOW
    BLUE_BACKGROUND_BRIGHT("\033[0;104m"),      // BLUE
    MAGENTA_BACKGROUND_BRIGHT("\033[0;105m"),   // MAGENTA
    CYAN_BACKGROUND_BRIGHT("\033[0;106m"),      // CYAN
    WHITE_BACKGROUND_BRIGHT("\033[0;107m");     // WHITE

    private final String code;

    Color(String code) {
        this.code = code;
    }

    @Override
    public String toString() {
        return code;
    }
}

public class ha {
    public static void main(String[] args) 
    {
        Scanner input = new Scanner(System.in);
        int g_price = 6;
        int b_price = 8;
        int p_price = 10;
    
        int g, b, p;

        System.out.print(Color.GREEN + "請輸入綠色籤子的數目 :");
        g = input.nextInt();
        System.out.print(Color.RESET);

        System.out.print(Color.BLUE + "請輸入藍色籤子的數目 :");
        b = input.nextInt();
        System.out.print(Color.RESET);

        System.out.print(Color.PURPLE + "請輸入紫色籤子的數目 :");
        p = input.nextInt();
        System.out.print(Color.RESET);

        System.out.println("\n-----已點選清單-----");

        System.out.println("綠色籤: ($" + g_price +")" + g + "枝,共$" +g_price *g);
        System.out.println("藍色籤: ($" + b_price +")" + b + "枝,共$" +b_price*b);
        System.out.println("紫色籤: ($" + p_price +")" + p +"枝,共$" + p_price*p);
        System.out.println("----------------\n");

        int total = g_price * g + b_price * b + p_price * p;

        System.out.println("折扣前: $" + total);

        String discountcode;
        String decision;
        boolean yn_check;

        System.out.print("請問你要輸入折扣碼嗎?[Y/N]");
        decision = input.next();
        while(true)
        {
            if(decision.equals("Y"))
            {
                System.out.print("請輸入你的優惠碼 :");
                discountcode = input.next();
                if(discountcode.equals("USETHISCODE"))
                {
                    System.out.print(Color.GREEN + "[+] 成功使用優惠碼 !\n" + Color.RESET);
                    yn_check = false;
                    break;
                }
                else
                {       
                    System.out.print(Color.RED + "[!] 優惠碼無效,請再次輸入 " +Color.RESET +"\n");
                    yn_check = true;
                }
            }

            else if (decision.equals("N"))
            {
                System.out.println("唔撚用Discount Code");
                yn_check = false;
                break;
            }

            else
            {
                System.out.print("只能輸入 [Y/N] : ");
                discountcode = input.next();
                yn_check = true;
            }
        }

    
        int discount = 0;
        if (g + b + p >= 6)
        {
            if (g > 0) discount = g_price;
            else if (b > 0) discount = b_price;
            else if (p > 0) discount = p_price;
    
            if (total % discount == 0)
                discount *= (g + b + p) / 6;
            else
                discount = 0;
        }

        if (discount > 0)
        {
            System.out.print("已享用折扣: 買滿6串免1串收費, 減 $" +discount);
            System.out.print("\n拆扣後: $" + (total - discount));
        }
    
        total -= discount;
    
        System.out.print("\n--------------------\n");
    
        double money;
        System.out.print("請輸入食客給予的錢碼($):");
        money = input.nextDouble();
    
        if (money >= total)
        {
            System.out.print("收: $" + money + "\t找:$"+(money-total));
        }
        else
        {
            System.out.print("唔夠錢");
        }

        input.close();
    }
}