简体   繁体   中英

(JAVA) How do I get this method to work with an enumeration?

My expected output is "5 t-shirts, size medium: $50.00"

import java.util.*;

public class OrderApp {
    
    
    public enum Size {SMALL, MEDIUM, LARGE, XLARGE}
    public enum Item {TSHIRT, HOODIE, SHORTS}
    
    public static final int TSHIRT_COST = 10;
    public static final int HOODIE_COST = 30;
    public static final int SHORTS_COST = 15;
    public static final int XLARGE_SURCHARGE = 6;
    
    public static void main(String[] args) {
        
        System.out.println("\n5 t-shirts, size medium: $" + getCost(TSHIRT, MEDIUM, 5) + ".00");
    
    }
    
    public static int getCost(Item i, Size s, int number) { 
        
        Size sizeVal;
        Item itemVal;
        sizeVal = Size.MEDIUM;
        itemVal = Item.TSHIRT;
        int totalVal;
        if (s == Size.MEDIUM) {
            if (i == Item.TSHIRT) {
                totalVal = number * TSHIRT_COST;
                
            }    
             
        }
        return totalVal;
        
    }      
}

I keep receiving an error that states "OrderApp.java:16: error: cannot find symbol" for TSHIRT and MEDIUM. Can someone please give me some insight on what I am doing wrong.

使用getCost(Item.TSHIRT,Size.MEDIUM)代替,否则编译器不知道在哪里可以找到符号。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM