Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Nếu bạn xem xét rằng có khoảng 262 phân số khác nhau hai lần giữa o và 1, khả năng vươn tới bất kỳ một giá trị thực nghiệm có thể vượt quá tuổi thọ của một máy tính, hoặc thậm chí một trong thí nghiệm. Nó chỉ ra rằng 0,0 là bao gồm trong đầu ra của Math.random (). Hoặc, trong ngôn ngữ toán học, nó là 0,1). | Simpo PDF Merge and Split Unregistered Version - http www.simpopdf.com import net.mindview.util. public enum Course APPETIZER Food.Appetizer.class MAINCOURsE Food.MainCourse.class DESSERT Food.Dessert.class COFFEE Food.Coffee.class private Food values private Course Class extends Food kind values kind.getEnumConstants public Food randomSelection return Enums.random values Each of the above enums takes the corresponding Class object as a constructor argument from which it can extract and store all the enum instances using getEnumConstants . These instances are later used in randomSelection so now we can create a randomly generated meal by selecting one Food item from each Course enumerated menu Meal.java package enumerated.menu public class Meal public static void main String args for int i 0 i 5 i for Course course Course.values Food food course.randomSelection System.out.println food System.out.println --- . . Output Spring_rOlls VINDALOO FRUIT DECAF_COFFEE SOUP VINDALOO FRUIT TEA SALAD BURRITO FRUIT TEA SALAD BURRITO CREME_CARAMEL LATTE SOUP BURRITO TIRAMISU ESPRESSO Enumerated Types 735 Simpo PDF Merge and Split Unregistered Version - http www.simpopdf.com In this case the value of creating an enum of enums is to iterate through each Course. Later in the VendingMachine.java example you ll see another approach to categorization which is dictated by different constraints. Another more compact approach to the problem of categorization is to nest enums within enums like this enumerated SecurityCategory.java More succinct subcategorization of enums. import net.mindview.util. enum SecurityCategory STOCK Security.Stock.class BOND Security.Bond.class Security values SecurityCategory Class extends Security kind values kind.getEnumConstants interface Security enum Stock implements Security SHORT LONG MARGIN enum Bond implements Security MUNICIPAL JUNK public Security randomSelection return Enums.random values public static void main String args for int i 0 i 10 i .