{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Exam 2 Sample - CS 1050 Dr Tucker Sample Exam#2 p l of 2...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: : CS 1050, Dr. Tucker Sample Exam #2, p. l of 2 Spring 2010 Total: 150 pts. In questions 1 - 6 use the code to fill in the values —— use a ? \ & if the value is not determined by the code; if a character is ' ‘] stored use ‘ '5 about the character value. Total: 90 pts. 1. public static finalVg = 2; . int a = 5; double s = 4.0; {5 s = a/c; a —= c; a .3 s 2.0 C «.22~ 2. int a =F1, b = 0, c = 3; if ((c == 4) && (a++, a == 2)) b = 5; else b = 8; a ‘ b g c 3 EVA. fawn, '_—_' '—"’ '___' 3. int a = 1, 3,3ko, c = 3; if ((c != 0) || (a++, a == 2)) Eb :3 b = 5; else b = 8; a \ b c tux -®lm __‘— ““ ~‘"‘ 4. int h = o, n = o, s = o, y = 0; char ch;g;%,g switch (ch) { case 'k' : ++h; break; [/Wflav case 'p' : ++n; case '5' : ++s; default : ++y; }; /* in each part below, start with the initializations */ if value of ch is 'k' h E n O s O y S} if value of ch is 'p' h g! n S s _J__ y _l__ if value of ch is 's' h S} n D s l y I if value of ch is 'h' h Q} n O 5 £2 y I 5. int d = {6, 8, 4}; d[0] (2 d[1] 8 d[2] 4 d[3] ? d[4] ? 6. char t = {‘H’, ‘e’, ‘n'}; t[0] ‘Xi’ t[l] "€,l t[2]‘ fl; t[3] Z t[4] ? 7. 8 pts. Write Java code for a method in the class Nums below which will return the real average of the instance variables. public class Nums ( private int numl, num2; } IN PROBLEMS 8-13 INCLUDE WORK WHICH SHOWS A TRACE TABLE,8 pts each 8. int a = 4, d = 3; do { a *= 2; d--; ' while (d > 3); V a g d 5Q CS 1050, Dr. Tucker Sample Exam #2, p. 2 of 2 Spring 2010 9. int a = 10, b = 1; for (; b < 10' ) b += 4; a -= 2; a 5 b ‘25 10. int a = 3, b = O, c for (c = 4; c < 10; c = 2, b+=a); a3 b (fag CH2 11. int c = 8, d = 7; while (d > 3) {--d;c+=2;} c \(2 di 12. int a = O, b = 8, s = 1; H H ‘. for (b = 0, a = 5; a > 1; --a) { if (a == 3) break; f. fl 5 = a; b++; } a i: b 9*” 5 AF 13. int a = 0, b = 8, s = 1; for (b =0, a = 5; a > 1; —-a) ‘ { if (a := 3) continue; ' ‘ “3+ . K s = a; b++\\& *’ '“*i” a \ b :3 s :1 $3»; we M \~\ A 14. 8 pts. Write a Java method with one character parameter that will return the parameter shifted one letter to the right ('A' becomes 'B', 'B' becomes 'C', etc.) if it is a capital letter and otherwise will do nothing. 15. 10 pts. Write a Java method that has a single parameter for an array of doubles and returns another array of doubles with the same length and has each element divided by 2.0. 16. 16 pts. Write a Java method that will search the array D for the value in the variable T. Use D and T as parameters. If the value of T is not found, the method should return —1. If the value of T is found, the method should return the first value of Sub such that D[Sub] has the same value as T. char D; int Sub; char T; 17. 30 pts. Write Java code to do the following:(%figdUfll?> The first data line contains the number of values to process. Use a for loop to process the data. After the first line of data, a line contains a real number representing the number of miles. To determine the amount corresponding to the number of miles use a if/else if statement and the following: up to 500 miles 15 cents per mile 500 to 1000 miles 75.00 plus 12 cents for each mile over 500 1000 to 2000 miles 135.00 plus 10 cents for each mile over 1000 over 2000 miles 235.00 plus 8 cents for each mile over 2000. Print the number of miles and the amount in a table with a heading. If the number of miles is <= 0, print the number of miles and **** in place of the amount. At the end of the table, print, with appropriate messages, the number of values processed that are >= 0 and the total of the amounts. Formatting the output is not necessary. Declare your storage. Do not use arrays. Assume input is from the keyboard —- include code to create a console of type Scanner Scanner and use console.nextInt() and console.nextDouble(). Assume output is to the screen. ...
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