no7.e10a.2017.pdf - Computer Science E-10a Introduction to Computer Science Using Java I Handout#7 Part B Optional Reading Look over chapters 3 and 4 in

no7.e10a.2017.pdf - Computer Science E-10a Introduction to...

This preview shows page 1 - 5 out of 11 pages.

Computer Science E-10a: Introduction to Computer Science Using Java, I Handout #7 Part B Optional Reading Look over chapters 3 and 4 in the Reges textbook, particularly the material on “parameter passing.” In some of the examples below, what a user types while running a Java program has been underlined for clarity. ` Simple Exercises (15 points total) You need not submit Java programs for the following problems. Please create your text (.txt) files in your Cloud9 editor. Answers submitted in another file format such as .doc, .pages, .rtf, or .pdf will not be accepted. [1] 3 points (1 point for each) file Identifier.txt In a simple, clear English sentence, explain why each of the following would not work as the name of a Java identifier: (a) [email protected] (b) number-of-wins (c) for Dr. H. H. Leitner
Image of page 1
Computer Science E-10a: Introduction to Computer Science Using Java, I Page 2 [2] 4 points file Parameters.txt Precisely what will be printed by the following dreadful program? In solving this problem, you may find it useful to draw little boxes that clearly show how the values of all the different variables change as each instruction gets executed. You will need to carefully explain how parameters and other “local” variables get created and destroyed. In simple English sentences, describe what happens as each line of the main program gets executed. class Prob2 { static int foo (int a, int b) { return (a + b); } static int bar (int x) { x += 2; return (x * x); } public static void main (String [] args ) { int x = 2; System.out.println (“foo (x, 3) = " + foo (x, 3) ); System.out.println (“foo (x, 4) = " + foo (x, 4) ); System.out.println (“bar (-x) = " + bar (-x) ); System.out.println ("bar (foo (x+x, ++x) ) = " + bar (foo (x+x, ++x) ) ); System.out.println (“Final value of x = " + x ); } } Unit Two Problem Set, part B Dr. H. H. Leitner
Image of page 2
Computer Science E-10a: Introduction to Computer Science Using Java, I Page 3 [3] 4 points file Nested.txt The following nested pair of for loops for (int outer = 2; outer <= 6; outer++) { for (int inner = 1; inner <= 8; inner++) { System.out.print ( ??? ); } System.out.println(); } is supposed to produce the output 2 4 6 8 10 12 14 16 3 6 9 12 15 18 21 24 4 8 12 16 20 24 28 32 5 10 15 20 25 30 35 40 6 12 18 24 30 36 42 48 Precisely what should replace the ??? in the System.out.print statement to make this code work correctly? [4] 4 points (1 point for each) file Expressions.txt Suppose we declare the following variables: int n = 16; int m = 18; double x = 2.5; What is the value of each of the following independent Java expressions? (a) m / n + m % n (b) 5 * x - n / 5 (c) Math.sqrt (Math.sqrt (n)) (d) 1 - (1 - (1 - n) * x) Unit Two Problem Set, part B Dr. H. H. Leitner
Image of page 3
Computer Science E-10a: Introduction to Computer Science Using Java, I Page 4 Programming Problems (65 points total) [5] 15 points file Charity.java A certain charity designates donors who give $10,000.00 or more as Benefactors ; those who give $1,000.00 to $9,999.99 as Patrons ; those who give $500.00 to $999.99 as Supporters ; those who give $100.00 to $499.99 as Friends ; and those who give less than $100 as Cheapskates .
Image of page 4
Image of page 5

You've reached the end of your free preview.

Want to read all 11 pages?

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

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes