Page 464 - Introduction to Programming with Java: A Problem Solving Approach
P. 464

                430 Chapter 10 Arrays and ArrayLists
table parameter returned array
Note:
• Yourmethodshouldnotchangethecontentofthepassed-intablearray.
• Yourmethodshouldworkwithanysizedtable,notjustthe3-row,4-columntableshowninthe
example.
• Useappropriateaccessmodifiers.Assumethatthemethodshouldbeaccessiblefromoutsideofits
class. In deciding whether the method should be a class method or an instance method, note that the method does not access any instance variables (it only accesses a parameter).
16. [after §10.10] Assume you have the following City class: public class City
 5
 􏰂2
 3
 1
 0
 14
 0
 6
 3
 6
 􏰂1
 4
 1
 0
 1
 1
 0
 1
 0
 1
 1
 1
 0
 1
  {
}
// end class City
private String name;
private double north;
private double west;
// north latitude in degrees
// west longitude in degrees
//**************************************************************
public City(String name, double latitude, double longitude)
        Apago PDF Enhancer
this.name = name;
this.north = latitude;
this.west = longitude;
// end constructor
//**************************************************************
{
}
public void display()
{
}
System.out.printf("%12s%6.1f%6.1f\n", name, north, west);
Write a code fragment that creates an array of City objects that contains the name, latitude, and longitude of the following four cities and displays the contents of those arrays like this:
New York 41.0 74.0
Miami 26.0 80.0
Chicago 42.0 88.0
Houston 30.0 96.0
17. [after §10.11] What does the ArrayList’s remove method do?
18. [after §10.12] Provide a single statement (an initialization statement) that declares an ArrayList named evenNumbers and assigns a newly instantiated ArrayList to it. The instantiated ArrayList should be able to store integers.
19. [after §10.12] Using the evenNumbers ArrayList created in the previous exercise, provide a code fragment that stores the first 10 even numbers in the evenNumbers ArrayList. In other words, put 0




































   462   463   464   465   466