Key_for_6EExam2_Ch3__4_

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

Info icon This 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
Image of page 1

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

View Full Document Right 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;
Image of page 2
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern