sue.closeSavings(); System.out.println("Tom's combined balance: " + tom.getCombined()); System.out.println("Sue's combined balance: " + sue.getCombined()); System.out.println(); } } JAVA0604.JAVA Tom's combined balance: 15000.0 Sue's combined balance: 18000.0 Tom's combined balance: 11000.0 Sue's combined balance: 8000.0 Tom's combined balance: 0.0 Sue's combined balance: 0.0 6.4 Using the Random Class Generating random values is a surprisingly big deal in many ways. Billions of dollars are spent on advertising, which is largely based on the surveys of a population sample picked at random. Politicians are continuously "polling" their constituents, which requires a random survey sample . Video games have become big business and no video game can survive without a true random behavior of game events. So how do we make something random? Java does have a random method, which belongs to the class with limited capabilities. There is also a Math Random class with a variety of methods to satisfy many random needs. Program Java0605.java, in figure 6.11, introduces the Random class. I mentioned earlier that the actual Java language is not so large. However, Java is supported by a huge set of class libraries. Related methods and data form one class. Related classes are organized together in one location, called a package, and related packages are placed in even larger packages.
sue.closeSavings(); System.out.println("Tom's combined balance: " + tom.getCombined()); System.out.println("Sue's combined balance: " + sue.getCombined()); System.out.println(); } } JAVA0604.JAVA Tom's combined balance: 15000.0 Sue's combined balance: 18000.0 Tom's combined balance: 11000.0 Sue's combined balance: 8000.0 Tom's combined balance: 0.0 Sue's combined balance: 0.0 6.4 Using the Random Class Generating random values is a surprisingly big deal in many ways. Billions of dollars are spent on advertising, which is largely based on the surveys of a population sample picked at random. Politicians are continuously "polling" their constituents, which requires a random survey sample . Video games have become big business and no video game can survive without a true random behavior of game events. So how do we make something random? Java does have a random method, which belongs to the Math class with limited capabilities. There is also a Random class with a variety of methods to satisfy many random needs. Program Java0605.java, in figure 6.11, introduces the Random class. I mentioned earlier that the actual Java language is not so large. However, Java is supported by a huge set of class libraries. Related methods and data form one class. Related classes are organized together in one location, called a package, and related packages are placed in even larger packages.
Text06-UsingObjectMethods-1.docx