Đang chuẩn bị liên kết để tải về tài liệu:
Lecter Java: Program design - Chapter 7: Programming with methods and classes

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

This chapter explores Java mechanisms that support the manipulation and calculation of values through method invocations; the use of class and instance variables; and the implementation of constructors, accessors, mutators, and facilitators. The examination begins with the method invocation process. | Programming with methods and classes Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Methods Instance method Operates on a object (i.e., and instance of the class) String s = new String("Help every cow reach its " + "potential!"); int n = s.length(); Class method Service provided by a class and it is not associated with a particular object String t = String.valueOf(n); Instance method Class method Data fields Instance variable and instance constants Attribute of a particular object Usually a variable Point p = new Point(5, 5); int px = p.x; Class variable and constants Collective information that is not specific to individual objects of the class Usually a constant Color favoriteColor = Color.MAGENTA; double favoriteNumber = MATH.PI - MATH.E; Instance variable Class constants Task – Conversion.java Support conversion between English and metric values 1 gallon = 3.785411784 liters 1 mile = 1.609344 kilometers d degrees Fahrenheit = (d – . | Programming with methods and classes Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Methods Instance method Operates on a object (i.e., and instance of the class) String s = new String("Help every cow reach its " + "potential!"); int n = s.length(); Class method Service provided by a class and it is not associated with a particular object String t = String.valueOf(n); Instance method Class method Data fields Instance variable and instance constants Attribute of a particular object Usually a variable Point p = new Point(5, 5); int px = p.x; Class variable and constants Collective information that is not specific to individual objects of the class Usually a constant Color favoriteColor = Color.MAGENTA; double favoriteNumber = MATH.PI - MATH.E; Instance variable Class constants Task – Conversion.java Support conversion between English and metric values 1 gallon = 3.785411784 liters 1 mile = 1.609344 kilometers d degrees Fahrenheit = (d – 32)/1.8 degrees Celsius 1 ounce (avdp) = 28.349523125 grams 1 acre = 0.0015625 square miles = 0.40468564 hectares Conversion Implementation public class Conversion { // conversion equivalencies private static final double LITERS_PER_GALLON = 3.785411784; private static final double KILOMETERS_PER_MILE = 1.609344; private static final double GRAMS_PER_OUNCE = 28.349523125; private static final double HECTARES_PER_ACRE = 0.40468564; Conversion implementation Conversion Implementation // temperature conversions methods public static double fahrenheitToCelsius(double f) { return (f - 32) / 1.8; } public static double celsiusToFahrenheit(double c) { return 1.8 * c + 32; } // length conversions methods public static double kilometersToMiles(double km) { return km / KILOMETERS_PER_MILE; } Conversion Implementation // mass conversions methods public static double litersToGallons(double liters) { return liters / LITERS_PER_GALLON; } public static double gallonsToLiters(double gallons) { return .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.