Untitled

 avatar
unknown
java
4 years ago
11 kB
4
Indexable
import java.util.Scanner;
 
enum Color //Define Color既 Code 俾下面print TEXT用
{
    //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 App
{
 
    public static class Item
    {
        String _name;
        Color _color; 
        int _price, _count, _total;
 
        Item(String name, Color color, int price)
        {
            _name = name;
            _color = color;
            _price = price;
        }
    }

    static void yoooo()
    {
        System.out.print(Color.RESET); //用黎方便我 就咁打 yoooo(); 就可以reset返 print野既色去返default
    }
 
    public static String _discount_code = "FUCK"; //string 個叫 _discount_code 入面串字係 FUCK
    public static void main(String[] args) throws Exception
    {
 
        Scanner input = new Scanner(System.in);
 
        Item g = new Item("綠色", Color.GREEN, 6);
        Item b = new Item("藍色", Color.BLUE, 8);
        Item p = new Item("紫色", Color.PURPLE, 10);
 
        Item[] items = new Item[3];
        items[0] = g;
        items[1] = b;
        items[2] = p;
 
        for (int i = 0; i < items.length; i++) //用LOOP PRINT 分別唔用3句既色籤
        {
            System.out.print(items[i]._color); //每當i+左一次之後 就用返上面defind左既色再set返隻色
            System.out.print("請輸入" + items[i]._name + "籤子的數目 : ");
            items[i]._count = input.nextInt(); // 將count記入籤子obj
        }
 
        yoooo(); //reset 隻色
 
        System.out.println("\n-------已點選清單-------");
 
        int total = 0; // 總價錢
        int total_count = 0;
 
        for (int i = 0; i < items.length; i++)
        {
            items[i]._total = items[i]._price * items[i]._count; // 計每樣籤子既總值 記入籤子 obj
            total += items[i]._total; // 計全部加埋既總值 (呢度每次加一樣籤子既總值, 直到for loop加哂3個)
            total_count += items[i]._count; // 計全部籤子加埋既數量 (都係一個個加 累積)
 
            System.out.print(items[i]._color);
            System.out.println(items[i]._name + "籤 ($" + items[i]._price + ") x " + items[i]._count + "枝,共$" + items[i]._total);
        }
 
        yoooo();
        System.out.println("------------------------\n");

        if (total_count >=6) // 如果佢3個色買既數量大過6 或者 = 6 就行下面既野
        {
 
            System.out.println(Color.WHITE_BOLD + "折扣前$: " + total + Color.RESET + "\n"); //Print 佢未折扣要用既$
    
            System.out.print(Color.YELLOW_BRIGHT + "請問你要輸入折扣碼嗎?[Y/N] ");
            System.out.print(Color.WHITE_BOLD); //直到RESET COLOR為止 D字都係白色
            String decision = input.next();
            yoooo(); //攞返上面個VOID入面放野既再放喺呢度
            
            while (true) //lOOP
            {
                if (decision.equals("Y")) //check佢打既字係咪 = Y
                {
                    System.out.print("\n請輸入你的優惠碼 : "); // 係Y 既話就PRINT呢句
                    String code = input.next(); //打DISCOUNT CODE
        
                    while (true)
                    {
                        if (code.equals(_discount_code)) //如果係 _discount_code string既野就行入面既野
                        { // use correct discount code
        
                            int x = -1; // 用作辨識結果是屬於哪一支 (items array內的id)
                            int y = Integer.MAX_VALUE; // int 的最大值
        
                            
                            if (total_count >= 6)// 所有籤子加埋既數量 > 6
                            {
                                for (int i = 0; i < items.length; i++)// 搵出最低總價既籤
                                {
                                    if (items[i]._total > 0 && items[i]._total < y)// 只搵 總值 > 0 同埋 總值 < y 既籤子
                                    {
                                        x = i; // 記低呢支野既array id
                                        y = items[i]._total; // 記得呢支野既總值
                                    } 
                                }
                            }
        
                            int discount = 0;
        
                            if (x != -1)// CHECK下係咪真係搵到最低總價既籤 (其實可能唔洗check)
                            { 
                                discount = items[x]._price; // 籤既原價
                                discount *= total_count / 6; // 再乘返 全部籤既數量 / 6
                            }
        
                            if (discount > 0)
                            {
                                System.out.println(Color.GREEN + "[+] 已享用折扣: 買滿6串免1串收費, 減 $" + discount + Color.RESET);
                                total -= discount;
                                System.out.println(Color.WHITE_BOLD +"拆扣後: $" + total + Color.RESET);
                            }
        
                            break;
                        } 
                        
                        else //打錯discount code既話行入面呢句
                        {
                            System.out.print(Color.RED + "[!] 優惠碼無效,請再次輸入 : " +Color.RESET);
                            code = input.next();
                        }
                    }
    
                    break; //出loop
                }

                else if (decision.equals("N")) // 問佢要唔要用discount code 佢打 N 既話就行入面既野
                {
                    System.out.print(Color.GREEN + "\n[Disabled] 你已選擇不使用優惠碼。" +Color.RESET);
                    break;
                } 

                else // 如果 唔係 Y OR N 就行入面呢句
                {
                    System.out.print(Color.RED + "[!] 𡃁仔你新黎架? 叫你打Y/N 你打左乜春? 再打多次啦屌你 " + Color.RESET);
                    decision = input.next();
                }
            }
        }

        else // 佢買唔夠6枝就行入面既野
        {
            System.out.print(Color.GREEN + "[提示] 你淨係買左 " + "\"" + total_count +"枝\",所以你未夠資格用優惠碼。" + Color.RESET+"\n");
            System.out.println(Color.WHITE_BOLD + "\n你需要俾 $" + total + Color.RESET + "\n");
        }
        
 
        for(int i = 0; i<1;i++) // 分隔用
            System.out.println("----------------");
 
        System.out.print(Color.WHITE_BOLD + "\n請輸入食客給予的銀碼($): "); //俾錢
        double money = input.nextDouble(); //用DOUBLE 因為有機會係俾毫子
        yoooo(); // reset 返color
 
        while(true) // loop
        {
            if (money < total) //check佢俾既錢係咪細過 佢要俾既金額
            {
                System.out.print("你俾唔夠錢 係咪玩野? 你唔夠錢俾唔撚好走 打多次個數俾我 ");
                money = input.nextDouble(); //再俾多次錢
            }

            else if (money >=total) //check佢 要俾既錢係咪大過 或者 = 佢要俾既錢既總數
            {
                System.out.println(Color.GREEN + "\n[+] 款待成功" + Color.RESET);
                System.out.println(Color.GREEN + "\n收: "+ money + "\t" + "找: " + (money - total) +Color.RESET);
                break;
            }
        }
 
        input.close(); //閂左個input
 
    }
}
Editor is loading...