1 / 18

BIT 115: Introduction To Programming

BIT 115: Introduction To Programming. Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah) bkweusijana@cascadia.edu http://edutek.net/cascadia/bit115. Quiz 11. https://catalysttools.washington.edu/webq/survey/babaw/55000. 2. Review of Quiz 10 Results.

Download Presentation

BIT 115: Introduction To Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. BIT 115: Introduction To Programming • Professor: Dr. Baba Kofi Weusijana • (say Doc-tor Way-oo-see-jah-nah, • Doc-tor, or Bah-bah) • bkweusijana@cascadia.edu • http://edutek.net/cascadia/bit115

  2. Quiz 11 • https://catalysttools.washington.edu/webq/survey/babaw/55000 2

  3. Review of Quiz 10 Results 3

  4. Today • Finish polymorphism example • Predicate (Helper) methods • the return keyword • Nested while loops • Next class: • Non-robotic software • Modifiers (public, private, protected) • Debugging & unit testing • Programs stored in multiple files

  5. Homework Assignments & Journals • J#3 due today • J#4 & A03 due Mon 5/19

  6. Polymorphism benefit • Can refer to the superclass as the type of an object of an extended class • Change the type of joe in ICE_10_Demo_1.java from SpinningRobot to Robot but don’t change new SpinningRobot(...) • This will be very helpful when we start putting objects into other objects such as arrays and collections 6

  7. Nested Loops • Suppose we want to place Things in a row, we can do that with a while loop and a row integer variable • Notice : only 1 dimensional output • What if you wanted to also place Things across columns (2D output)? • inside the row while loop, have a column while loop • We call this nesting • you can nest loops, if statements, select cases, etc. 7

  8. ICE Part 2: Nested Loops • With Eclipse set breakpoint on line 12 of NestedWhile.java • Trace the code in the debugger and watch the changes • If we wanted to, we could nest 3 loops inside each other, etc 8

  9. Queries, Predicates, Integers in tests • A query method is a question asking method • Used to figure out something about the current state of the program • Queries SHOULDN'T have side effects: shouldn’t change the state of the object • for example, when a robots’ query method ends, the robot should be in the same situation it was when the method was called • Example: public int countThingsInBackpack() in the becker.robots.Robot class 9

  10. Predicates • Predicate methods are true/false (yes/no) queries • Return a boolean value (true or false) • Usually have “is” in their name • For example in becker.robots.Robot: • frontIsClear • isBesideThing 10

  11. Return • return can be used to indicate what answer the method wants to give • It will immediately stop the method from going any further, and instead return to whatever method called the current method • Example: • public boolean isTrue() • { • return true; • } 11

  12. Return • Normally, you'd combine return with some other logic to create a more useful bit of functionality: • public boolean isRobotOnAvenueFive() • { • if (this.getAvenue() == 5) • { • return true; • } • else • { • return false; • } • } 12

  13. Return • You can also directly return anything that will be true/false when the program is run: • public boolean isRobotOnAvenueFive() • { • return (this.getAvenue() == 5); • } • Return can also be used in void methods to indicate that you simply want to stop the method & return to the caller • public void doNothing() • { • return; • System.out.println(“Never say this.”); • } 13

  14. Using return just to stop a method • /** This will put down as many as five things, in a row. The method will stop if the robot doesn't have 5 Things to place */ • public void placeFiveThings() • { • int counter = 0; • while(counter < 5) • { • if(this.countThingsinBackPack() > 0) • { • this.putThing(); • } • else • { • // This will simply stop the current method from running • return; • } • } • } 14

  15. ICE Part 1, with the sample test code • FileName.java 15

  16. Integer tests • These queries return int numbers: • int getAvenue(); • int getStreet(); • Direction getDirection(); //one of Directions.NORTH, Directions.SOUTH, etc • int getSpeed(); • Note that these are all public methods • Integer tests are not very useful unless we can compare them to other things & do some simple math on them 16

  17. ICE Part 3: Variable Design • Discuss: • What are good answers? • TYPO: • Students DO NOT need to turn in a MS Word doc, but good quiz practice 17

  18. ICE Parts 4 & 5 • Note: You must fix class naming problem by making packages • Can turn in as late as by class on Monday 5/12 to the Java Code Critic 18

More Related