6 Pages

Test03-2004-03

Course: CS 101, Fall 2008
School: UVA
Rating:
 
 
 
 
 

Word Count: 725

Document Preview

2004 Fall - CS 101: Test 3 Name ______________________________________UVA Email ID _________ Page 1 _______ / 10 1. (Bonus 2 points) What is your section? 101 Page 4 _______ / 17 101E Page 5 _______ / 25 Page 6 _______ / 20 Page 2 _______ / 10 Page 3 _______ / 18 Total _______ /100 2. (5 points) What is the output of the following code segment? int i = 0; while ( i > 0 ) { ++i;...

Register Now

Unformatted Document Excerpt

Coursehero >> Virginia >> UVA >> CS 101

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
2004 Fall - CS 101: Test 3 Name ______________________________________UVA Email ID _________ Page 1 _______ / 10 1. (Bonus 2 points) What is your section? 101 Page 4 _______ / 17 101E Page 5 _______ / 25 Page 6 _______ / 20 Page 2 _______ / 10 Page 3 _______ / 18 Total _______ /100 2. (5 points) What is the output of the following code segment? int i = 0; while ( i > 0 ) { ++i; System.out.println("true"); } 3. (5 points) What is the output of the following code segment? for ( int i = 0; i < 2; ++i ) { for ( int j = 0; j < 2; ++j ) { break; } System.out.println ("outer"); } System.out.println ("finished"); Pledged Page 1 of 6 Pledged Fall 2004 - CS 101: Test 3 Name ______________________________________UVA Email ID _________ 4. (5 points) What is the output of the following code segment? int counter1 = 0; int counter2 = 0; for ( int i = 0; i < 5; ++i ) { for ( int j = 0; j < 10; ++j ) { ++counter1; } ++counter2; } System.out.println ("counter1 = " + counter1); System.out.println ("counter2 = " + counter2); 5. (5 points) Write a code segment using a while loop that performs a comparable task as the following code segment. Assume Scanner variable stdin has already been defined. int sum = 0; for ( int i = 0; i < 10; ++i ) { int number = stdin.nextInt(); sum = sum + number; } System.out.println(sum); Pledged Page 2 of 6 Pledged Fall 2004 - CS 101: Test 3 Name ______________________________________UVA Email ID _________ 6. (5 points) What is the compiler error in the following code segment. int[] array = { 8, 7, 6, 5, 4, 3 }; int sum = 0; for ( int i = 0; i < array.length; ++i ) { sum = sum + array[i]; } if ( i == sum ) { System.out.println("Same"); } else { System.out.println("Different"); } 7. (5 points) Suppose class Widget has an int instance variable myData. Suppose that x and y are separately initialized Widget variables. Is it necessarily the case that x.myData must always equal y.myData? Why? (Use no more than TWENTY words to explain why). 8. (5 points) Suppose class Widget has a static int member variable theCount. Suppose that x and y are separately initialized Widget variables. Is it necessarily the case that x.theCount must always equal y.theCount? Why? (Use no more than TWENTY words to explain why). 9. (3 points) Draw a memory diagram for the following definition. int[] array; Pledged Page 3 of 6 Pledged Fall 2004 - CS 101: Test 3 Name ______________________________________UVA Email ID _________ 10. (3 points) Draw memory a diagram for the following definition. int[] array = new int[2]; 11. (3 points) Draw a memory diagram for the following definition. int[] array = { 1, 2 }; 12. (3 points) Draw a memory diagram for the following definition. String[] array = new String[2]; 13. (3 points) Draw a memory diagram for the following definition. String[] array = { "A", "B" }; 14. (5 points) Why do our examples in lecture define Scanner variable stdin in the following way Scanner stdin = new Scanner(System.in); rather than this way Scanner stdin = Scanner.create(System.in); Pledged Page 4 of 6 Pledged Fall 2004 - CS 101: Test 3 Name ______________________________________UVA Email ID _________ For questions 1518 suppose class Coordinate has the following definition. public class Coordinate { int x; int y; public Coordinate(int a, int b) { this.x = a; this.y = b; } } 15. (5 points) Explain in TWENTY words or less why a Coordinate object has a toString() method. 16. (10 points) Define a public clone() member method with return type Object that returns a new Coordinate whose x and y values are the same as the x and y values of the this object. 17. (10 points) Define a boolean public method equals() that has a single Object parameter named v. The method should return false is v is not an instance of Coordinate. If v is a Coordinate then the method returns true if its x and y values match the x and y values of the this object; otherwise, the method returns false. Hint: if v is an instance of Coordinate then define a ...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

UVA - CS - 101
CS 101 Exam 1 Spring 200Email Id _ Name _This exam is open text book and closed notes. Different questions have different points associated with them with later occurring questions having more worth than the beginning questions. Because your goal
UVA - CS - 101
CS 101 / CS 101-Ehttp:/www.cs.virginia.edu/~cs101M/W 2:00-3:15 CHM 402 / MEC 205Instructors: CS 101 Aaron Bloomfield http:/www.cs.virginia.edu/~asbCS 101-E James Cohoon http:/www.cs.virginia.edu/~cohoonOffice: Olsson Hall, room 228D Office: O
UVA - CS - 101
Take care with floating-point valuesConsider double a = 1; double b = 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 double c = .9999999999999999; Two true expressions! c = b b != a Two false expressions! a = b b != c Problem lies with th
UVA - CS - 101
Testing and ExceptionsException Abnormal event occurring during program execution Examples Manipulate nonexistent files File file = new File(s); Scanner fileIn = new Scanner(file); Improper array subscripting int[] a = new int[3]; a
UVA - CS - 101
BooleanvaluesGatewaytodecisionmakingBackground Ourproblemsolvingsolutionssofarhavethestraightlineproperty TheyexecutethesamestatementsforeveryrunoftheprogrampublicclassDisplayForecast /main():applicationentrypoint publicstaticvoidmain(String[]a
UVA - CS - 101
Cir cleKeeps on r ol l i ng Pr oblem design a cir cle r epr esent at ionSome possi bl e questi ons to ask What ki nd of ci r cl e? Why not use an exi sti ng ci r cl e r epr esentati on? What pl ans do you have for the ci r cl e? What
UVA - CS - 101
ClassesPreparation Scenesofarhasbeenbackgroundmaterialandexperience Computingsystemsandproblemsolving Variables Types Inputandoutput Expressions Assignments Objects StandardclassesandmethodsReady ExperiencewhatJavaisreallyabout Designa
UVA - CS - 101
Review for exam 1CS 101 Aaron Bloomfield1Todays lectureAn overview of the review sections of chapters 1-3 Stop me if you want me to go over something in more detail!2Material you may not be comfortable withConstructorsI know there is a
UVA - CS - 101
Iteration 1Java loopingOptions while dowhile for Allow programs to control how many times a statement list is executed 2AveragingProblem Extract a list of positive numbers from standard input and produce their average Number
UVA - CS - 101
Programming with methods and classes 1MethodsInstance (or member) method Operates on a object (i.e., and instance of the class)String s = new String(&quot;Help every cow reach its &quot; + &quot;potential!&quot;); int n = s.length(); Instance method
UVA - CS - 101
Using ObjectsChapter 3 Spring 2005 CS 101 Aaron Bloomfield 1About the assignment statementAssign the value 5 to the variable x int x; x = 5; 5 = x; NOT VALID! This is not a mathematical equals It's a Java assignment The variable you wan
UVA - CS - 101
JavabasicsInclassquiz What aretherule for an ide s ntifie in Java? r In what m thod doe a programbe What is there e s gin? turn typeof that m thod? What e param te doe it re e r(s) s quire ? What is thee xpone ntiation ope rator in Java? How do w
UVA - CS - 101
CS 101Chapter 1: Background Spring 2005 Aaron Bloomfield1Let's beginGoalTeach you how to program effectivelySkills and information to be acquired Mental model of computer and network behavior Problem solving Object-oriented design Jav
UVA - CS - 101
StaplesareourstapleBuilding upon our solutionWhydidthisprogramworkpublicclassStaplerSimulation{ publicstaticvoidmain(String[]args){ StaplermyStapler=newStapler(); System.out.println(myStapler); myStapler.fill(); System.out.println(myStapler); my
UVA - CS - 101
Arrays 1BackgroundProgrammer often need the ability to represent a group of values as a list List may be onedimensional or multidimensional Java provides arrays and the collection classes The Vector class is an example of a collection cla
UVA - CS - 101
ArraysContinued 1Consideredint[] v = new int[10]; int i = 7; int j = 2; int k = 4; v[0] = 1; v[i] = 5; v[j] = v[i] + 3; v[j+1] = v[i] + v[0]; v[v[j] = 12; System.out.println(v[2]); v[k] = stdin.nextInt();v 1v[0]0v[1]8v[2]6v[3]3v
UVA - CS - 101
Decisions,decisions,decisionsChapter5 Spring2005 CS101 AaronBloomfield1BackgroundOurproblemsolvingsolutionssofarhavethestraightlineproperty TheyexecutethesamestatementsforeveryrunoftheprogrampublicclassDisplayForecast /main():applicatione
UVA - CS - 101
Page 2Question 2 No partial creditQuestion 3 No partial creditQuestion 4 No partial creditQuestion 5 No partial creditQuestion 6 -1 if float instead of doubleQuestion 7 -1 if the word 'swap' was mentioned -3 if there are no words
UVA - CS - 101
A B CD E FThis file has 38 characters.
UVA - CS - 101
ABCDEFThisfilehas30characters.
UVA - CS - 415
Fortran lectureFortran history Why do we care? o Was one of the most influential programming languages of all time o It's development mirrors PL evolution o Was the de facto programming languages for many years o Was the first high level language
UVA - CS - 101
Spring 2007 CS 101EMichele CoBoolean Expressions, Precedence, and If StatementsDescription: The following questions demonstrate key concepts related to evaluating Boolean expressions and evaluation precedence. Directions: Discuss your reasoning
UVA - CS - 101
CS 101 Spring 2006 Final ExamName: _Email ID: _This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Unlike the midterm exams, you have a full 3 hours to work on this exam. Please sign the honor pledge here:Pa
UVA - CS - 101
CS 101 Spring 2007 Midterm 1Name: _Email ID: _You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be s
UVA - CS - 101
CS 101 Spring 2006 Midterm 3Name: _Email ID: _This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sure to look over all the questions and plan your time accordingly
UVA - CS - 101
CS 101 Spring 2007 Midterm 2Name: _Email ID: _You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be s
UVA - CS - 101
CS 101 Fall 2006 Midterm 3Name: _Email ID: _You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sur
UVA - CS - 101
CS 101 Fall 2006 Final ExamName: _Email ID: _You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be su
UVA - CS - 101
CS 101 Fall 2006 Midterm 2Name: _Email ID: _You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sur
UVA - CS - 101
CS 101 &amp; 101-ESpring 2007 http:/www.cs.virginia.edu/~cs101 CS 101: M/W/F 3:00-3:50 in CHM 402 CS 101-E: M/W 2:00-3:15 in MEC 205Instructors: CS 101 Aaron Bloomfield http:/www.cs.virginia.edu/~asbCS 101-E Michele Co http:/www.cs.virginia.edu/~mc2z
UVA - CS - 101
Inheritance and PolymorphismChapter 11 Spring 2007 CS 101 Aaron Bloomfield 1This section is not required material!A note about inheritance. It's not normally covered in 101 It will be gone over in more detail in CS 201 Ask questions if yo
UVA - CS - 101
MethodsChapter 5 Spring 2007 CS 101 Aaron Bloomfield 1PreparationScene so far has been background material and experience Computing systems and problem solving Variables Types Input and output Expressions Assignments Using objects
UVA - CS - 101
Review for Midterm 3CS 101 Spring 2007 1Topic CoverageLoops Chapter 4 Methods Chapter 5 Classes Chapter 6, Designing and creating classes Chapter 9, Static fields and methods, wrapper classes Arrays Chapter 8 2ClassesCircl
UVA - CS - 101
ReviewforExam1Spring2007 CS101/CS101ETodaysclassAnoverviewofchapters13 Stop me if you want me to go over something in moredetail!2Chapter13IntroComputersthinkinbits(1or0)00101001=81Eightbitsperbyte 1024bytes=1Kb 1024
UVA - CS - 101
Course SummaryCourse Summary Spring 2007 CS 101 Aaron Bloomfield 1Course Reflection2Course goalsObjectives: Students who complete the course will: Understand fundamentals of programming such as variables, conditional and iterati
UVA - CS - 101
CS 101Chapter 1: Introduction Aaron Bloomfield Spring 2007 Let's beginGoalTeach you how to program effectivelySkills and information to be acquired What the heck all this means Problem solving Objectoriented design Java 2So,
UVA - CS - 101
CS 101 Exam 2 Spring 2005Email Id _ Name _This exam is open text book and closed notes. Different questions have different points associated with them. Because your goal is to maximize your number of points, we recommend that you do not spend too
UVA - CS - 101
CS 101 Final Exam Fall 2004Email Id _Name _This exam is open book. Each question is worth 3 points.Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 Total _ / 15 _ / 15 _ / 12 _ / 18 _ / 15 _ / 9 _ / 12 _ / 6 _ / 100 (maximum is 102)1. A
UVA - CS - 101
CS 101 Exam 1 Spring 200Email Id _ Name _This exam is open text book and closed notes. Different questions have different points associated with them with later occurring questions having more worth than the beginning questions. Because your goal
UVA - CS - 101
CS 101 (Fall 05) Exam 1 Grading Guidelines Question 1: 2 points All or nothing Question 2: 2 points 1 point for each column Questions 3-8: 3 points -2 for type error -1 for math error -2 for associativity error -1 for forgetting the .0 for a float/do
UVA - CS - 101
CS 101 Final Exam Grading GuidelinesQuestions 1 &amp; 2: all or nothing Question 3 -1 for wrong modifiers (static, public, etc.) per variable to a max of -3 -4 for no head/tail variables -3 for missing a variable (head, tail, etc) if resulting class doe
UVA - CS - 101
CS 101 Exam Regrade Request FormName: UVa e-mail ID: Exam: Question(s) to be regraded: Action (To be filled in by TA/Grader): a. No Change b. Revised grade:Reasons for Regrade Request: a. Incorrect total. b. Problem (or part thereof) was overlooke
UVA - CS - 101
CS 101 Fall 2005 Midterm 3Name: _Email ID: _This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sure to look over all the questions and plan your time accordingly.
UVA - CS - 101
CS 101 Fall 2005 Midterm 2Name: _Email ID: _This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts (in particular, the final two questions are worth substantially more than a
UVA - CS - 101
CS 101 Midterm 3 Grading GuidelinesQuestions 1 &amp; 2: All or nothing, as long as they entered a value Question 3 (top of page 2: there were two questions labeled as question 3): -2 for each missing i = 2 -2 for missing int[] c. Note that they don't ha
UVA - CS - 101
Course SummaryCourse Summary Fall 2005 CS 101 Aaron Bloomfield 1Course Reflection2Course goalsObjectives: Students who complete the course will: Understand fundamentals of programming such as variables, conditional and iterative
UVA - CS - 101
TheStackClassFinalReview Fall2005 CS101 AaronBloomfield1MotivationSameasforVectors Wewantaneasywaytostoreelementsinaobjectwithouthaving toworryaboutmanipulatingarrays2PropertiesofourStackclassItneedstohaveanarraytoholdthevalues T
UVA - CS - 101
Programmingwith methodsandclassesChapter7 Fall2005 CS101 AaronBloomfield1Static vs. non-static2MethodsInstance(ormember)method Operatesonaobject(i.e.,andinstanceoftheclass)Strings=newString(&quot;Helpeverycowreachits&quot; +&quot;potential!&quot;); intn
UVA - CS - 101
CS 101Daily AnnouncementsMonday, 29 August 2005 Everybody should register for a lab section My first screw-up: The final exam is on a Tuesday, 13 Dec TAs and office hours are on the website First homework will be out later this week My offi
UVA - CS - 101
IterationChapter 6 Fall 2005 CS 101 Aaron Bloomfield 1Java loopingOptions while dowhile for Allow programs to control how many times a statement list is executed 2Averaging values3AveragingProblem Extract a list of positi
UVA - CS - 101
Java basicsChapter 2 Spring 2005 CS 101 Aaron Bloomfield 1DisplayForecast.java/ Authors: J. P. Cohoon and J. W. Davidson / Purpose: display a quotation in a console window public class DisplayForecast {Three comments / method main(): app
UVA - CS - 202
Growth of FunctionsCS 202 Epp, section ? Aaron Bloomfield1How does one measure algorithms We can time how long it takes a computer What if the computer is doing other things? And what happens if you get a faster computer? A 3 Ghz Windows mac
UVA - CS - 201
CS201: SW Development Methods Analysis of Algorithms Reading: Chapter 5 of MSD text Except Section 5.5 on recursion (next unit)Goals for this Unit Begin a focus on data structures and algorithms Understand the nature of the performance of al
UVA - CS - 201
Lecture 7: A Tale of Two Graphs (and a tree)CS201J: Engineering Software University of Virginia Computer ScienceDavid Evanshttp:/www.cs.virginia.edu/evansGraph ADTpublic class Graph { / OVERVIEW: / A Graph is a mutable type that
UVA - CS - 201
Lecture 7: A Tale of Two GraphsCS201j: Engineering Software University of Virginia Computer ScienceDavid Evanshttp:/www.cs.virginia.edu/~evansGraph ADTpublic class Graph { / OVERVIEW: / A Graph is a mutable type that / re
UVA - P - 211
Senior Citizens in Households Below the Poverty LevelBase FeaturesStudy NeighborhoodCity-County Boundary CityRailroadsSelected Major RoadsPercent of Senior Citizens in Households Below the Poverty Level by Block Groups0% - 3% 4% - 9% 10% -
UVA - P - 211
3899500.000000173179159177198 189A184 188187 191204 243 242 240196199 202 208 212213 221 215 216 224 225 220 232 233 228 234 251 2541 18623 4 190 2032001811823899250.000000239235B258 257 273 278281259 26726026
UVA - P - 211
Mapping of Residents Whose Travel to Work is 30 Minutes or Less by Way of Public Transportation in the West Main St. AreaPercentage of Residents Traveling to Work Within 30 Mins. Compared to All Other Means and Overall TimePercentage of Residents T
UVA - P - 211
Mapping for All Residents Whose Travel Time to Work is 30 Minutes or Less in the West Main St. AreaPercentage of Residents Whose Travel to Work Was Within 30 Minutes in Block GroupsCity-Wide ComparisonBase FeaturesStudy Neighborhood CityRailro
UVA - P - 211
rosalyn te eng fofinal project portfolio1plan 211table of contentsproject 1 web design 3project 2 image capture4project 3 image processing5project 4 poster6project 5 3-d modeling7project 6 thematic mapping89, 10 project