Summary and Exam COMP 102 2019 T 1

  • Slides: 20
Download presentation
Summary and Exam COMP 102 2019 T 1 Peter Andreae Computer Science Victoria University

Summary and Exam COMP 102 2019 T 1 Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington

Menu COMP 102 Summary: 2 • Where have we been? • ie, what could

Menu COMP 102 Summary: 2 • Where have we been? • ie, what could the exam cover? • Exam Structure • Other courses © Peter Andreae

Where have we been? COMP 102 Summary: 3 • Defining methods • • statements,

Where have we been? COMP 102 Summary: 3 • Defining methods • • statements, expressions, local variables, calling methods on objects creating new objects methods with parameters returning values • Calling static methods, main, Math, … • Text based User interfaces • using UI for print…, ask…, next…. • Graphical output • coordinates • rectangles, ovals, lines, • colors © Peter Andreae

Where have we been? COMP 102 Summary: 4 • If statements, • single if,

Where have we been? COMP 102 Summary: 4 • If statements, • single if, with no else • multiway (nested) if … else if …else … • nested if (…) { if (…) … else … } else {…} • boolean expressions and boolean variables • Data types: • int, double, (& long, float ) • boolean • char • String • Object types (predefined, user defined) © Peter Andreae

Where have we been? COMP 102 Summary: 5 • For Each loops • works

Where have we been? COMP 102 Summary: 5 • For Each loops • works on arrays and Array. Lists • for (Thing th : my. Things){… • Mustn't change the array or Array. List. • Counted For Loops • Standard pattern for stepping through a sequence of numbers • for (int i = 0; i<…; i++){… and for (int i = ? ? ; i>=0; i--){ … • While Loops: • • General purpose Structure with four parts: initialisation, condition, body, increment break and return Nested loops © Peter Andreae

Where have we been? COMP 102 Summary: 6 • Files: Input and Output •

Where have we been? COMP 102 Summary: 6 • Files: Input and Output • • Output using Print. Stream (print, println, printf) Opening files, using name of file and UIFile. Chooser. open, UIFile. Chooser. save Input using Scanner (next, next. Line, next. Int, next. Double, has. Next, has. Next…) try … catch to deal with exceptions. • Classes and objects • • • constants fields, constructors, methods: visibility specifiers (public vs private) initialising fields, © Peter Andreae

Where have we been? COMP 102 Summary: 7 • GUIs • • • main

Where have we been? COMP 102 Summary: 7 • GUIs • • • main method to create object and set up interface Buttons, Text. Fields, Sliders, mouse actions Defining methods to respond to the buttons, mouse, etc Using fields to store values between events. © Peter Andreae

Where have we been? COMP 102 Summary: 8 • Array. Lists • for collections

Where have we been? COMP 102 Summary: 8 • Array. Lists • for collections where the size changes. • Declaring and creating new Array. Lists Array. List<item. Type> items = new Array. List<item. Type> (); • adding items items. add(item ) • accessing items. get(index ) • Iterating through for (item. Type itm : items ) {…. . itm…. } for (int i=0; i<items. size(); i++){ …. items. get(i)…. } • items. set(index, item) • items. add(index, item) • items. remove(index) © Peter Andreae

Where have we been? COMP 102 Summary: 9 • Arrays • • • collections

Where have we been? COMP 102 Summary: 9 • Arrays • • • collections where the size is fixed constructing new arrays of primitive types (initially 0 or false) arrays of objects (initially null) accessing elements of arrays array[index ] loops with arrays for (int i=0; i<ar. length; i++){ …. ar[ i ]…. } for (item. Type itm : ar ) {…. . itm…. } • initialising arrays with = new int[ ]{val, … } • arrays that can contain nulls • 2 D arrays and nested loops for (int row=0; row<arr. length; row++){ for (int col=0; col<arr[row]. length; col++){ …. arr[row][col] …. © Peter Andreae

Standard Patterns You Must Know COMP 102 Summary: 10 • Structure of a for

Standard Patterns You Must Know COMP 102 Summary: 10 • Structure of a for loop: for ( type variable : list or array ) { body } for ( initialisation ; do again condition ; increment ) { body } • Structure of a while loop: initialisation while ( do again condition ) { body increment } © Peter Andreae

Standard Patterns You Must Know COMP 102 Summary: 11 • Reading from a file:

Standard Patterns You Must Know COMP 102 Summary: 11 • Reading from a file: try { Scanner scan = new Scanner(new File( filename )); while ( scan. has. Next() ) { scan. next() or scan. next. Int() or scan. next. Double() or scan. next. Line() } scan. close(); catch (IOException e) { UI. println("File failed " + e); } • Getting values from a Scanner: Scanner sc = new Scanner(line); String token = sc. next(); int count = sc. next. Int(); while ( sc. has. Next() ) { sum = sum + sc. next. Double(); } © Peter Andreae

Standard Patterns You Must Know COMP 102 Summary: 12 • Class describing an object

Standard Patterns You Must Know COMP 102 Summary: 12 • Class describing an object with state: public classname { // Fields type fieldname = initial. Value ; ⋮ // Constructor public classname ( arguments ){ actions to set up the object } // Methods eg: set and get field values perform actions on object computations involving object © Peter Andreae

Standard Patterns You Must Know COMP 102 Summary: 13 • Arrays: • do something

Standard Patterns You Must Know COMP 102 Summary: 13 • Arrays: • do something with each element (using or changing) for ( int i = 0 ; i < data. length ; i++ ) { …. data[ i ]…. } • do something with each element, but not changing array for ( Element. Type elem : data) { …. elem…. } © Peter Andreae

Standard Patterns You Must Know COMP 102 Summary: 14 • Arrays which might contain

Standard Patterns You Must Know COMP 102 Summary: 14 • Arrays which might contain nulls • do something with each element (using or changing) for ( int i = 0 ; i < data. length ; i++ ) { if (data[ i ] != null) { …. data[ i ]…. } • do something with each element, but not changing array for ( Element. Type elem : data) { if (elem != null) { …. elem…. } } © Peter Andreae

Standard Patterns You Must Know COMP 102 Summary: 15 • Collection in an Array.

Standard Patterns You Must Know COMP 102 Summary: 15 • Collection in an Array. List<Element. Type > data = new Array. List<Element. Type >(); • do something with each element (using or changing) for ( Element. Type item : data ) { …. item…. } for ( int i = 0 ; i < data. size() ; i++ ) { …. data. get( i )…. } • • • data. get(index) data. set(index, item) data. add(index, item) data. remove(index) © Peter Andreae

Standard Patterns You Must Know COMP 102 Summary: 16 • 2 D array •

Standard Patterns You Must Know COMP 102 Summary: 16 • 2 D array • do something with each element (using or changing) for ( int row = 0 ; row < data. length ; row++ ) { for ( int col = 0 ; col < data[row]. length ; col++ ) { …. data[row][col]…. } } © Peter Andreae

COMP 102 Summary: 17 Exam • Exam: 24 Jun, 9: 30 am • Run

COMP 102 Summary: 17 Exam • Exam: 24 Jun, 9: 30 am • Run by science faculty office (ph 463 5983 in an emergency) • COMP 102 and 112 are the same exam • 2 hours, 120 marks • (1 mark ∼ 1 minute) More time than in tests to go back. • Exam Questions : • Topics: all the things we have covered. • Compared to previous years: • doesn’t include “interface classes” • 2015 -18: similar, but may be different choice of topics • 2014 or before: 2019 is shorter => can’t cover as many topics. © Peter Andreae

Studying for the Exam COMP 102 Summary: 18 • Previous exams • Exams before

Studying for the Exam COMP 102 Summary: 18 • Previous exams • Exams before 2006 may be useful practice, but used lots of different stuff, and emphasised Strings and chars • Exams 2007 -2010 more useful, but used System. out and System. in and had more complicated GUIs • Exams before 2013 didn’t use Array. List (they used arrays in a more complicated way) • Previous exams had more complicated GUI code • Checking your answers: • Model solutions • Study with other students • Use Blue. J to check your answers (Sometimes, you will have to write extra code to set things up the way the question assumed. ) © Peter Andreae

Hints for the exam COMP 102 Summary: 19 • We are looking for evidence

Hints for the exam COMP 102 Summary: 19 • We are looking for evidence you know stuff, • not trying to trip you up (except at the hardest questions ). • we do give partial marks • Learn the syntax rules for java constructs • (note that the exam itself will have models for you) • Use documentation if you forget method names • We don’t expect you to remember every method and class; the documentation is to prompt you. • Check your code by stepping through it on paper. • Put your working down • it might help us give you marks © Peter Andreae

What if I fail? COMP 102 Summary: 20 If you are not a COMP/CGRA

What if I fail? COMP 102 Summary: 20 If you are not a COMP/CGRA major or a BE student, • don’t worry- get on with the courses that matter for your major • If you want some more programming, take COMP 132 in Tri 2 If you are a COMP/CGRA major or BE student • Can’t do COMP 103 or ENGR 110 or CRA 151 next trimester • We will be offering a limited entry, repeat COMP 102 next trimester • Need to deal with and overcome things that were stopping you from passing this time round (eg, study habits, time management, exam skills, computer games, …. . ) • Maybe pick up COMP 132 to get an alternative introduction to programming © Peter Andreae