Presentation is loading. Please wait.

Presentation is loading. Please wait.

Homework 5 Due ( MT sections ) ( WTh sections ) at midnight Sun., 10/6 Mon., 10/7 Problems

Similar presentations


Presentation on theme: "Homework 5 Due ( MT sections ) ( WTh sections ) at midnight Sun., 10/6 Mon., 10/7 Problems"— Presentation transcript:

1 Homework 5 Due ( MT sections ) ( WTh sections ) at midnight Sun., 10/6 Mon., 10/7 Problems http://www.cs.hmc.edu/courses/2002/fall/cs5/ http://www.cs.hmc.edu/courses/2002/fall/cs5/week_05/homework.html CS 5 website email dodds@cs.hmc.edu or bthom@cs.hmc.edu Submission problems or other concerns?

2 Tutors available Academic Computing labs (Parsons) Linde Activities Center lab Friday Afternoons 1-4 pm ---------------------------------------- Chris Hwang this week (10/4): Parsons Don Lee this week (10/4): Parsons Daniel Chan this week (10/4): LAC Lab Zach Andree this week (10/4): LAC Lab Annie Chang this week (10/4): LAC Lab Saturday Afternoons 1-4pm ---------------------------------------- Chris Weisiger this week (10/5): Parsons Yu-Min Kim this week (10/5): Parsons Elizabeth Lee-Su this week (10/5): LAC Lab Aaron Homer this week (10/5): LAC Lab Sunday Afternoons 1-4pm ---------------------------------------- Gabriel Neer this week (10/6): Parsons Jeff Brenion this week (10/6): LAC Lab Rene Logan this week (10/6): LAC Lab

3 Tutors available Sunday evenings 7-12pm ---------------------------------------- Jenny Xu 6-9 this week (10/6): Parsons Eric Flynn 7-10 this week (10/6): Parsons Melissa Federowicz 7-10 this week (10/6): LAC Lab Max Yi 7-10 this week (10/6): LAC Lab Yu-Min Kim 9-12 this week (10/6): Parsons A. Klose 9-12 this week (10/6): Parsons Matt Beaumont-Gay 9-12 this week (10/6): LAC Lab Chris Hwang 9-12 this week (10/6): LAC Lab Monday Evenings 7-12pm ---------------------------------------- Adam Kangas 7-10 this week (10/7): Parsons Ryka Neher 7-10 this week (10/7): Parsons Max Yi 7-10 this week (10/7): LAC Lab Annie Chang 9-12 this week (10/7): Parsons Paul Scott 9-12 this week (10/7): Parsons John McCollough 9-12 this week (10/7): Parsons Alex Pipkin 9-12 this week (10/7): LAC Lab Chris Wottawa 9-12 this week (10/7): LAC Lab Alex Utter 9-12 this week (10/7): LAC Lab

4 Problem 2 -- Caesar Cipher Encryption strategy Choose an amount to shift your message. Move each letter that amount. message: eorrgb lqvwuxfwlrqv zklfk uhwxuq wr sodjxh wkhlu lqyhqwru shift amount: 3 encrypted message:

5 bloody instructions which return to plague their inventor Macbeth, Act I, Scene 7 ???

6 Problem 2 -- Caesar Cipher Decryption strategy Shift the encrypted message by every possible shift amount Pick out the English text... eorrgb lqvwuxfwlrqv zklfk uhwxuq wr sodjxh wkhlu lqyhqwru encrypted message: all possible shifts: eorrgb lqvwuxfwlrqv zklfk uhwxuq wr sodjxh wkhlu lqyhqwru fpsshc mrwxvygxmsrw almgl vixyvr xs tpekyi xlimv mrzirxsv gqttid nsxywzhyntsx bmnhm wjyzws yt uqflzj ymjnw nsajsytw hruuje otyzxaizouty cnoin xkzaxt zu vrgmak znkox otbktzux isvvkf puzaybjapvuz dopjo ylabyu av wshnbl aolpy pucluavy jtwwlg qvabzckbqwva epqkp zmbczv bw xtiocm bpmqz qvdmvbwz kuxxmh rwbcadlcrxwb fqrlq ancdaw cx yujpdn cqnra rwenwcxa lvyyni sxcdbemdsyxc grsmr bodebx dy zvkqeo drosb sxfoxdyb mwzzoj tydecfnetzyd hstns cpefcy ez awlrfp esptc tygpyezc nxaapk uzefdgofuaze ituot dqfgdz fa bxmsgq ftqud uzhqzfad xhkkzu ejopnqypekjo sdeyd napqnj pk lhwcqa pdaen ejrajpkn yillav fkpqorzqflkp tefze obqrok ql mixdrb qebfo fksbkqlo zjmmbw glqrpsargmlq ufgaf pcrspl rm njyesc rfcgp gltclrmp aknncx hmrsqtbshnmr vghbg qdstqm sn okzftd sgdhq hmudmsnq bloody instructions which return to plague their inventor cmppez jotusvdujpot xijdi sfuvso up qmbhvf uifjs jowfoups dnqqfa kpuvtwevkqpu yjkej tgvwtp vq rnciwg vjgkt kpxgpvqt

7 Resources Suppose we have a method that shifts a character c by n letters. char advanceChar(char c, int n) Assume these work... length() (tells the length of a String ) charAt(int n) (returns the n th char of a String ) advanceChar(‘h’, 4) is advanceChar(‘z’, 2) is String s = “more java”; s.length() is s.charAt(2) is s.charAt( ) is ‘v’

8 High-level plan We have char advanceChar(char c, int n) length() (tells the length of a String ) charAt(int n) (returns the n th char in a String, starting at 0) What to do ?

9 advanceChar Now we need to worry about making this piece work... public static char advanceChar(char c, int n)

10 Working with char s _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { } ~ 97 98 99122 123 char c = ‘y’; c = (char)(c - 2); c += 5; How do we get back?

11 Style note // be sure to comment each method you write! public static char advanceChar(char c, int n) // Name: advanceChar // Inputs: a char (c) and an int (n) // Output: the char that is n places // to the right of c, where the // alphabet wraps from ‘z’ to ‘a’.

12 public static void main(String[] args) { int x = H.in.nextInt(); int y = H.in.nextInt(); int z = confusing(x,y); H.out.println(“z is ” + z); } public static int confusing(int y, int x) { int a = 0; a = 10*y + x; return a; } A message from our sponsor

13 Problem 1 -- finding e x Please input a power (a double) and I will raise e to that power: 2.5 Enter the number of terms you'd like to use (an int >= 1): 10 The result is 12.179115120485767 Would you like to continue (yes/no)? no Inside main : This is e 2.5 computed using 10 terms of the series x0x0 0! x1x1 1! x2x2 2! x3x3 3! ++ + +… 4 terms

14 public static double exp(double x, int numTerms) exp What does exp do? What are x and numTerms referring to?

15 power public static double power(double base, int p) What does power do? What are base and p referring to?

16 factorial public static double factorial(int n) What does factorial do? What is n referring to?

17 Problem 1 -- finding e x Please input a power (a double) and I will raise e to that power: 2.5 Enter the number of terms you'd like to use (an int >= 1): 10 The result is 12.179115120485767 Would you like to continue (yes/no)? no Inside main :

18 This is e 2.5 computed using 10 terms of the series x0x0 0! x1x1 1! x2x2 2! x3x3 3! ++ + +… 4 terms

19 Homework 5 Due ( MT sections ) ( WTh sections ) at midnight Sun., 10/6 Mon., 10/7 Problems http://www.cs.hmc.edu/courses/2002/fall/cs5/ http://www.cs.hmc.edu/courses/2002/fall/cs5/week_05/homework.html CS 5 website email dodds@cs.hmc.edu or bthom@cs.hmc.edu Submission problems or other concerns?

20 Tutors available Academic Computing labs (Parsons) Linde Activities Center lab Friday Afternoons 1-4 pm ---------------------------------------- Chris Hwang this week (10/4): Parsons Don Lee this week (10/4): Parsons Daniel Chan this week (10/4): LAC Lab Zach Andree this week (10/4): LAC Lab Annie Chang this week (10/4): LAC Lab Saturday Afternoons 1-4pm ---------------------------------------- Chris Weisiger this week (10/5): Parsons Yu-Min Kim this week (10/5): Parsons Elizabeth Lee-Su this week (10/5): LAC Lab Aaron Homer this week (10/5): LAC Lab Sunday Afternoons 1-4pm ---------------------------------------- Gabriel Neer this week (10/6): Parsons Jeff Brenion this week (10/6): LAC Lab Rene Logan this week (10/6): LAC Lab

21 Tutors available Sunday evenings 7-12pm ---------------------------------------- Jenny Xu 6-9 this week (10/6): Parsons Eric Flynn 7-10 this week (10/6): Parsons Melissa Federowicz 7-10 this week (10/6): LAC Lab Max Yi 7-10 this week (10/6): LAC Lab Yu-Min Kim 9-12 this week (10/6): Parsons A. Klose 9-12 this week (10/6): Parsons Matt Beaumont-Gay 9-12 this week (10/6): LAC Lab Chris Hwang 9-12 this week (10/6): LAC Lab Monday Evenings 7-12pm ---------------------------------------- Adam Kangas 7-10 this week (10/7): Parsons Ryka Neher 7-10 this week (10/7): Parsons Max Yi 7-10 this week (10/7): LAC Lab Annie Chang 9-12 this week (10/7): Parsons Paul Scott 9-12 this week (10/7): Parsons John McCollough 9-12 this week (10/7): Parsons Alex Pipkin 9-12 this week (10/7): LAC Lab Chris Wottawa 9-12 this week (10/7): LAC Lab Alex Utter 9-12 this week (10/7): LAC Lab

22 Problem 2 -- Caesar Cipher Encryption strategy Choose an amount to shift your message. Move each letter that amount. message: eorrgb lqvwuxfwlrqv zklfk uhwxuq wr sodjxh wkhlu lqyhqwru shift amount: 3 encrypted message:

23 Problem 2 -- Caesar Cipher Decryption strategy Shift the encrypted message by every possible shift amount Pick out the English text... eorrgb lqvwuxfwlrqv zklfk uhwxuq wr sodjxh wkhlu lqyhqwru encrypted message: all possible shifts: eorrgb lqvwuxfwlrqv zklfk uhwxuq wr sodjxh wkhlu lqyhqwru fpsshc mrwxvygxmsrw almgl vixyvr xs tpekyi xlimv mrzirxsv gqttid nsxywzhyntsx bmnhm wjyzws yt uqflzj ymjnw nsajsytw hruuje otyzxaizouty cnoin xkzaxt zu vrgmak znkox otbktzux isvvkf puzaybjapvuz dopjo ylabyu av wshnbl aolpy pucluavy jtwwlg qvabzckbqwva epqkp zmbczv bw xtiocm bpmqz qvdmvbwz kuxxmh rwbcadlcrxwb fqrlq ancdaw cx yujpdn cqnra rwenwcxa lvyyni sxcdbemdsyxc grsmr bodebx dy zvkqeo drosb sxfoxdyb mwzzoj tydecfnetzyd hstns cpefcy ez awlrfp esptc tygpyezc nxaapk uzefdgofuaze ituot dqfgdz fa bxmsgq ftqud uzhqzfad xhkkzu ejopnqypekjo sdeyd napqnj pk lhwcqa pdaen ejrajpkn yillav fkpqorzqflkp tefze obqrok ql mixdrb qebfo fksbkqlo zjmmbw glqrpsargmlq ufgaf pcrspl rm njyesc rfcgp gltclrmp aknncx hmrsqtbshnmr vghbg qdstqm sn okzftd sgdhq hmudmsnq bloody instructions which return to plague their inventor cmppez jotusvdujpot xijdi sfuvso up qmbhvf uifjs jowfoups dnqqfa kpuvtwevkqpu yjkej tgvwtp vq rnciwg vjgkt kpxgpvqt

24 Resources Suppose we have a method that shifts a character c by n letters. char advanceChar(char c, int n) Assume these work... length() (tells the length of a String ) charAt(int n) (returns the n th char of a String ) advanceChar(‘h’, 4) is advanceChar(‘z’, 2) is String s = “more java”; s.length() is s.charAt(2) is s.charAt( ) is ‘v’

25 High-level plan We have char advanceChar(char c, int n) length() (tells the length of a String ) charAt(int n) (returns the n th char in a String, starting at 0) What to do ?

26 advanceChar Now we need to worry about making this piece work... public static char advanceChar(char c, int n)

27 Working with char s _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { } ~ 97 98 99122 123 char c = ‘y’; c = (char)(c - 2); c += 5; How do we get back?

28 Style note // be sure to comment each method you write! public static char advanceChar(char c, int n) // Name: advanceChar // Inputs: a char (c) and an int (n) // Output: the char that is n places // to the right of c, where the // alphabet wraps from ‘z’ to ‘a’.

29 public static void main(String[] args) { int x = H.in.nextInt(); int y = H.in.nextInt(); int z = confusing(x,y); H.out.println(“z is ” + z); } public static int confusing(int y, int x) { int a = 0; a = 10*y + x; return a; } A message from our sponsor

30 Problem 1 -- finding e x Please input a power (a double) and I will raise e to that power: 2.5 Enter the number of terms you'd like to use (an int >= 1): 10 The result is 12.179115120485767 Would you like to continue (yes/no)? no Inside main : This is e 2.5 computed using 10 terms of the series x0x0 0! x1x1 1! x2x2 2! x3x3 3! ++ + +… 4 terms

31 public static double exp(double x, int numTerms) exp What does exp do? What are x and numTerms referring to?

32 power public static double power(double base, int p) What does power do? What are base and p referring to?

33 factorial public static double factorial(int n) What does factorial do? What is n referring to?


Download ppt "Homework 5 Due ( MT sections ) ( WTh sections ) at midnight Sun., 10/6 Mon., 10/7 Problems"

Similar presentations


Ads by Google