Key_for_6EExam2_Ch3__4_

Key_for_6EExam2_Ch3__4_ - else if (salesAmount <= 10000)...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Key for Exam2 Part I: Multiple Choice Questions. 1. c 2. d 3. e 4. b 5. c 6. e 7. b 8. a 9. c 10. a 11. b 12. c 13. d 14. b 15. e 16. c 17. b 18. d 19. b Part II. (1 pts) Correctly indent the following statement. if (i > 0) if (j > 0) x = 0; else if (k > 0) y = 0; else z = 0; Part III. (5 pts) Identify and fix errors in the following code: public class Test { public static void main(string[] args) // should be String { for (int i = 0; i < 10; i++); // should remove ; { if (j > i) then // should remove then // j not defined j++ // miss ; else j--; } } } Part IV. (5 pts) Show the printout of the following code: 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
1bb 1bb3bb 1bb3bb9bb 1bb3bb9bb27bb Part V: (a) import javax.swing.JOptionPane; public class Test { /**Main method*/ public static void main(String[] args) { // Prompt the user to enter sales amount String doubleString = JOptionPane.showInputDialog( "Enter sales amount:"); // Convert string to double double salesAmount = Integer.parseInt(doubleString); // Compute sales commission double salesCommission = 0; if (salesAmount <= 5000) salesCommission = salesAmount * 0.08;
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: else if (salesAmount <= 10000) salesCommission = 5000 * 0.08 + (salesAmount - 5000) * 0.1; else salesCommission = 5000 * 0.08 + 10000 * 0.1 + (salesAmount - 10000) * 0.12; // Display results System.out.println("Sales commission is " + salesCommission + " for sales amount of " + salesAmount); } } (b) import javax.swing.JOptionPane; public class Test { /**Main method*/ public static void main(String args) { double sum = 0; for (int i = 1; i <= 99; i++) sum += sum + (i * 1.0 / (i + 1)); // Display results System.out.println("Sum is " + sum); } } 2 (c) public class Test { /**Main method*/ public static void main(String args) { for (int row = 1; row <= 9; row++) { // Print spaces for (int column = 1; column < row; column++) System.out.print(" "); for (int column = row; column <= 9; column++) System.out.print(column); for (int column = 8; column >= row; column--) System.out.print(column); System.out.println(); } } } 3...
View Full Document

This note was uploaded on 01/17/2012 for the course GCIS 501 taught by Professor Liu during the Fall '09 term at Gannon.

Page1 / 3

Key_for_6EExam2_Ch3__4_ - else if (salesAmount <= 10000)...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online