📄 solveeven.txt
字号:
f. Math.floor(43.99); g. Math.ceil(3.01);
38. 2*Math.PI*r
44. a. BigInteger a = new BigInteger("34");
b. BigInteger b = new BigInteger("-562");
c. BigInteger c = new BigInteger("1111122222333334444455555");
d. BigInteger d = new BigInteger("987654321");
46. Supposing that the BigIntegers in problem 44 were named a, b, c, and d
referring to the BigInteger defined in each part, the product is
d.multiply(c.multiply(b.multiply(a)))
Chapter 5
2. a. false b. false c. true d. true e. true
4. Name me = new Name("Arthur", 'P', "Gittleman");
6. String i = "123-45-6789";
Name n = new Name("Peter", "Pan");
Address a = new Address("1512 Harbor Blvd.", "Long Beach", "CA", "99919");
Person p = new Person(i,n,a);
8. SavingsAccount s = new SavingsAccount(50.00,3.5);
10. a. no output b. horse c. Abraham Lincoln
12. c will generate a compiler error
14. The compiler does not allow this change.
16. The most significant difference is that all methods in an interface are abstract,
whereas an abstract class may have none, some, or all its methods abstract.
18. class Circle extends Shape implements Scaleable {
int radius;
public Circle(Point p, int r) {
super(p);
radius = r;
}
public void scale(int factor) {
radius *= factor;
}
}
20. import stuff.GoodStuff;
22. stuff
24. d2 is accessible in the package visibility (classes A, B, and C).
d3 is accessible in the package visibility (classes A, B, and C) and in class D which
is a subclass of A.
26. d5 is part of class B. Since B is visible only within the package visibility, the same
restriction applies to variables such as d5 which is declared within B.
28. The user asks the teller to accept an ATM card.
The teller asks the user to enter a PIN.
The user asks the teller to accept a PIN.
The teller asks the user to select a transaction type.
The user asks the teller to accept a cancellation.
30. The user asks the teller to accept an ATM card.
The teller asks the user to enter a PIN.
The user asks the teller to accept a PIN.
The teller asks the user to select a transaction type.
The user asks the teller to accept a get balance transaction.
The teller asks the user to select an account type.
The user asks the teller to accept a savings account type.
The teller asks the bank to find the account of the chosen
type for the user with the specified PIN.
The bank gives the teller a reference to the account.
The teller specifies the balance.
The teller asks the user to select another transaction, ...
Chapter 6
2. double[] x = {-4.3,6.8,32.12,-11.4,16.88};
x[0] = x[3];
4. int sum = 0;
for(int i=0; i<intArray.length, i++)
sum += intArray[i];
12. myArray = readIntArray();
16. The array would have 19 elements. The first three would be unused.
18. double[][] batting = {{.245,.265,.275}, {.289,.276,.302}, {.256, .259, .249},
{.324, .312, .345}, {.267, .285, .279}}
20. 52 38 6 97 3 41 67 44 15
38 52 6 97 3 41 67 44 15
6 38 52 97 3 41 67 44 15
6 38 52 97 3 41 67 44 15
3 6 38 52 97 41 67 44 15
3 6 38 41 52 97 67 44 15
3 6 38 41 52 67 97 44 15
3 6 38 41 44 52 67 97 15
3 6 15 38 41 44 52 67 97
24. The time doubles as the size doubles.
public class RepeatReverse1 {
public static void reverse(int [] anArray) {
int temp; // used to store a value during a swap
int left = 0; // index of the left element to swap
int right = anArray.length -1; // index of the right element to swap
while (left < right) {
temp = anArray[left];
anArray[left] = anArray[right];
anArray[right] = temp;
right--;
left++;
}
}
public static void main(String [] args) {
char repeat; // 'Y' to repeat, 'N' to quit
do {
int size = Io.readInt("Enter the number of data items");
int[] theArray = new int[size];
for (int i=0; i<size; i++)
theArray[i] = (int)(100*Math.random());
long starttime = System.currentTimeMillis();
reverse(theArray);
long stoptime = System.currentTimeMillis();
System.out.println("The time used in milliseconds is "
+ (stoptime-starttime));
repeat = Io.readChar("Enter 'Y' to repeat, 'N' to quit");
} while (repeat == 'Y' || repeat == 'y');
}
}
Chapter 7
2. a. http b. developer.javasoft.com c. developer/readAboutJava/jpg/ball.html
4. Code specifies the applet's class file.
Width specifies the applet's width in pixels.
Height specifies the applet's height in pixels.
6. h2
8. Applet, Panel, Container, Component, Object
10. Graphics is an abstract class which defines an interface,
specifying methods for drawing figures and other graphics operations. The user works
with the interface while each implementation provides a concrete subclass which
implements the abstract methods suitably for that platform.
12. Resizing the applet. Minimizing or maximizing the applet. Uncovering the applet
which had been hidden at least in part by another window.
14. g.drawRect(10,10,90,190);
16. g.drawOval(100,50,200,100);
18. int[] x = {0,200,100};
int[] y = {0,50,100};
Polygon p = new Polygon(x,y,3);
20. Font f = new Font("SansSerif",Font.BOLD+Font.ITALIC,12);
22. g.drawString(s,90,100);
24. Color blue = new Color(0.0f,0.0f,1.0f);
26. 255, 255, and 255.
Chapter 8
2. The classes Component and Container are abstract. The others can be instantiated.
4. The applet registers with the Print button as an action listener.
The applet registers with the Clear button as an action listener.
The user presses the Print button.
The Print button sends an action event as an argument to the
applet's actionPerformed method.
The applet's actionPerformed method displays a message Hi there.
The user presses the Clear button.
The Clear button sends an action event as an argument to the
applet's actionPerformed method.
The applet's actionPerformed method erases the message.
6. The applet registers with the text field as an action listener.
The applet registers with the Average button as an action listener.
The user enters a value in the text field and presses the Enter key.
The text field sends an action event as an argument to the
applet's actionPerformed method.
The applet's actionPerformed method adds the value to the sum.
The user enters a value in the text field and presses the Enter key.
The text field sends an action event as an argument to the
applet's actionPerformed method.
The applet's actionPerformed method adds the value to the sum.
The uses presses the Average button.
The Average button sends an action event as an argument to the
applet's actionPerformed method.
The applet's actionPerformed method computes and displays the average of the two values
inputted by the user.
8. The canvas registers with the checkbox, square, as an item listener.
The user selects the square shape.
The checkbox sends an item event describing this selection to
the canvas' itemStateChanged method.
The canvas' itemStateChanged method asks Java to schedule
a call to the paint method to redraw the canvas.
Java calls the canvas' paint method (via update).
The paint method draws the square in the currently selected color.
10. North,South -- width. East,West -- height. Center -- both
12. Add each button to a Panel and add the panel to the grid cell.
Chapter 9
2. MOUSE_PRESSED, MOUSE_RELEASED, MOUSE_CLICKED
4. KEY_PRESSED (the G key)
KEY_TYPED (g)
KEY_RELEASED (the G key)
6. Pressing keys will have no effect and the applet will not work as intended.
8.a. The frame is not visible and the applet does not work as intended.
b. The applet works as it does in the original version with f.show().
12. The triangle will get smaller and smaller as you continue to rotate it.
14. From left to right the hull is made up of the parallelogram, a small triangle, the
square, the other small triangle, and the medium triange. The big triangle are used for
the sails.
Chapter 10
2. The program aborts when it encounters the bad interger value, 45.2, and no further
statements of the program are executed.
4. b
8. The program displays the first 10 lines of the file ReadFileLines.java
12. binarySearch(data,8,0,12) middle = (0+12)/2 = 6, data[6] = 56 > 8, right = 5
binarySearch(data,8,0,5) middle = (0+5)/2 = 2, data[2] = 7 < 8, left = 3
binarySearch(data,8,3,5) middle = (3+5)/2 = 4, data[4] = 23 > 8, right = 3
binarySearch(data,8,3,3) middle = (3+3)/2 = 3, data[3] = 12 > 8, right = 2
binarySearch(data,8,3,2) quit left > right, value 8 not found
16. 15 19
top
18. a. 18 b. -63 c. -11
Chapter 11
2. main 1, Bonnie 1, Clyde 1, main 2, main 3, main 4, Clyde 2, main 5, Bonnie 2, Clyde 3,
Bonnie 3, Clyde 4, Clyde 5, Bonnie 4, Bonnie 5
4. No
6. To make it easier to change the sleep time we could pass it as a program argument.
10. Whistle.au should be in the same directory as PlayBall.html, while boom.au should be
in the same directory as PlayBall.class.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -