1 / 15

Introduction to MCP

Introduction to MCP. CPS 1 Summer 2002 Shannon Pollard. Algorithms. Algorithm: A detailed set of instructions for solving a problem that: Has a finite number of steps Takes a finite amount of time. Multiple-Choice Programming. Way to write out algorithms

apollo
Télécharger la présentation

Introduction to MCP

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. Introduction to MCP CPS 1 Summer 2002 Shannon Pollard

  2. Algorithms • Algorithm: A detailed set of instructions for solving a problem that: • Has a finite number of steps • Takes a finite amount of time

  3. Multiple-Choice Programming • Way to write out algorithms • Show the level of detail you need to use • Some things provided for you • Not learning Java • Focus on universal aspects of programming

  4. Lessons Learned from PB&J:Variables • Need a way to name things (bread slice 1) • Variables: Names assigned to things so they can be referred to later. int x = 4; • Remember Algebra? Kind of, but not quite…Thing on left gets CHANGED!! int y,z;y = 4; (“Y gets 4”)z = y;y = 6;z = z+1;

  5. Variables, Cont’d • Variables have Type- what kind of thing is it? • int, double • boolean – things that are either true or false • Strings – “Put anything in quotes!” • Objects – Anything!!! • You first must tell the type of a variable, then you can give it a value • Examples: int x = 4;String answer = “Here it is!”;boolean b = (x==3);

  6. Lessons Learned from PB&J:Subroutines • Allow a set of steps to be done over again with little change, without rewriting everything (Now repeat steps 3-15 with bread slice 2 and jelly) • Subroutines may or may not take input (parameters) or give an answer (return something). • Examples:int y = addTwo(42);String s = whatsMyLine();quit();

  7. Subroutine Specifics • Header – information at beginning of subroutine, including its name • Header has type of thing returned, or void keyword • Parameters – tell type of inputs and gives them local names • Must have return statement unless return type void • Can be used by name by other functions

  8. Lessons Learned from PB&J:Loops • Loops are used to do a sequence of steps some number of times, or only in certain situations (Repeat steps 3-10 5 times; Repeat step 4 until the jelly is spread, do step 5 only if there is more bread.) • Need to use booleans – things that are either true or false(x<=5)myString.equals(“Shannon)(obj!=null)

  9. Loops, Contd • If Statements if (BOOLEAN) { STATEMENTS } else { STATEMENTS }

  10. If Example int x = 4; x = x + 14; if (x < 18) { x = 0; } else { x = 1; } return x;

  11. Loops, Cont’d • While Loops while(BOOLEAN) { STATEMENTS }

  12. While Loops int x = 4; Initialization while (x < 10) Check { x = x+1; Update } return x;

  13. int x,y;x = 100;y = addThree(x); public int addThree(int number) { return number + 3; } public void writeOut(String line) { System.out.println(line); } String myName;myName = “Shannon”;writeOut(myName);

  14. public List listCPS1(List master) { List answer = new List(); List cps1 = getClassList(cps1); int last = master.length(); int index = 1; while (index <= last) { Student s = master.getMember(index); if (cps1.contains(s)) { answer.add(s); } index = index + 1; } return answer;}

  15. MCP Format • Most lines specified that you need to write • You must fill in the correct variables or statements • You make your own variables as needed • Things in CAPS are supposed to be substituted!! • Other things must be typed exactly • Order matters! • Cheat Sheet provided

More Related