Presentation is loading. Please wait.

Presentation is loading. Please wait.

A201 (I201, A597) Introduction to Programming Adrian German Office: Lindley Hall (LH) 201D Class home page containing ALL the details:

Similar presentations


Presentation on theme: "A201 (I201, A597) Introduction to Programming Adrian German Office: Lindley Hall (LH) 201D Class home page containing ALL the details:"— Presentation transcript:

1 A201 (I201, A597) Introduction to Programming Adrian German (dgerman@indiana.edu) Office: Lindley Hall (LH) 201D Class home page containing ALL the details: http://www.cs.indiana.edu/classes/a201 Please check the “What’s New” part of the web page every day!

2 The purpose of this class:

3 - to get to know each other better

4 The purpose of this class: - to get to know each other better - to understand programming in Java

5 The purpose of this class: - to get to know each other better - to understand programming in Java - to improve our problem solving skills

6 The purpose of this class: - to get to know each other better - to understand programming in Java - to improve our problem solving skills A reminder:

7 The purpose of this class: - to get to know each other better - to understand programming in Java - to improve our problem solving skills A reminder: Education is what remains after we forget what we learned in school.

8 The purpose of this class: - to get to know each other better - to understand programming in Java - to improve our problem solving skills A reminder: Education is what remains after we forget what we learned in school. But we have to learn it first!

9 What is Programming?

10 What does it look like?

11 What is Programming? What does it look like? Let’s work out some examples.

12 First Problem

13 You are given two (different length) strings

14 First Problem You are given two (different length) strings that have the characteristic that they both take exactly one hour to burn.

15 First Problem You are given two (different length) strings that have the characteristic that they both take exactly one hour to burn. However, neither string burns at a constant rate.

16 First Problem You are given two (different length) strings that have the characteristic that they both take exactly one hour to burn. However, neither string burns at a constant rate. Some sections of the strings burn very fast; other sections burn very slowly.

17 First Problem You are given two (different length) strings that have the characteristic that they both take exactly one hour to burn. However, neither string burns at a constant rate. Some sections of the strings burn very fast; other sections burn very slowly. All you have to work with is a box of matches and the two strings.

18 First Problem You are given two (different length) strings that have the characteristic that they both take exactly one hour to burn. However, neither string burns at a constant rate. Some sections of the strings burn very fast; other sections burn very slowly. All you have to work with is a box of matches and the two strings. Describe an algorithm that uses the strings and the matches to calculate when exactly 45 minutes have elapsed.

19 Second Problem

20 A farmer lent the mechanic next door a 40-pound weight.

21 Second Problem A farmer lent the mechanic next door a 40-pound weight. Unfortunately, the mechanic dropped the weight and it broke into four pieces.

22 Second Problem A farmer lent the mechanic next door a 40-pound weight. Unfortunately, the mechanic dropped the weight and it broke into four pieces. The good news is that, according to the mechanic, it is still possible to use the four pieces to weigh any quantity between one and 40 pounds on a balance scale.

23 Second Problem A farmer lent the mechanic next door a 40-pound weight. Unfortunately, the mechanic dropped the weight and it broke into four pieces. The good news is that, according to the mechanic, it is still possible to use the four pieces to weigh any quantity between one and 40 pounds on a balance scale. Note: you can weigh a 4-pound object on a balance by putting a 5-pound weight on one side and a 1-pound weight on the other.

24 Third Problem

25 A captive queen weighing 195 pounds,

26 Third Problem A captive queen weighing 195 pounds, her son weighing 90 pounds,

27 Third Problem A captive queen weighing 195 pounds, her son weighing 90 pounds, and her daughter weighing 165 pounds

28 Third Problem A captive queen weighing 195 pounds, her son weighing 90 pounds, and her daughter weighing 165 pounds, were trapped in a very high tower.

29 Third Problem A captive queen weighing 195 pounds, her son weighing 90 pounds, and her daughter weighing 165 pounds, were trapped in a very high tower. Outside their window was a pulley and rope with a basket fastened on each end.

30 Third Problem A captive queen weighing 195 pounds, her son weighing 90 pounds, and her daughter weighing 165 pounds, were trapped in a very high tower. Outside their window was a pulley and rope with a basket fastened on each end. They managed to escape

31 Third Problem A captive queen weighing 195 pounds, her son weighing 90 pounds, and her daughter weighing 165 pounds, were trapped in a very high tower. Outside their window was a pulley and rope with a basket fastened on each end. They managed to escape by using the baskets and a 75-pound weight they found in the tower.

32 Third Problem A captive queen weighing 195 pounds, her son weighing 90 pounds, and her daughter weighing 165 pounds, were trapped in a very high tower. Outside their window was a pulley and rope with a basket fastened on each end. They managed to escape by using the baskets and a 75-pound weight they found in the tower. How did they do it?

33 Third Problem A captive queen weighing 195 pounds, her son weighing 90 pounds, and her daughter weighing 165 pounds, were trapped in a very high tower. Outside their window was a pulley and rope with a basket fastened on each end. They managed to escape by using the baskets and a 75-pound weight they found in the tower. How did they do it? The problem is that anytime the difference in weight between the two baskets is more than 15 pounds, someone might get killed.

34 Third Problem A captive queen weighing 195 pounds, her son weighing 90 pounds, and her daughter weighing 165 pounds, were trapped in a very high tower. Outside their window was a pulley and rope with a basket fastened on each end. They managed to escape by using the baskets and a 75-pound weight they found in the tower. How did they do it? The problem is that anytime the difference in weight between the two baskets is more than 15 pounds, someone might get killed. Describe an algorithm that gets them down safely.

35 A Story

36 Shakey the Robot() Based on a character created by Suzanne Menzel

37 The place is here (RH100) the time is in the future. You are about to enter the sixth dimension… Hang in there! Hang in there!

38

39 are solid walls (nothing can go through)red lines

40 (0,0)

41 (0,1)(0,0)

42 (0,1)(0,2)(0,0)

43 (0,1) (1,1) (2,2) (1,2) (0,2)(0,0) (2,1)(2,0) (1,0)

44 Robot shakey; (0,1) (1,1) (2,2) (1,2) (0,2)(0,0) (2,1)(2,0) (1,0)

45 Robot shakey; (0,1) (1,1) (2,2) (1,2) (0,2) shakey = new Robot(); shakey new Robot(); shakey shakey = new Robot(); (0,0) (2,1)(2,0) (1,0)

46 Robot shakey; shakey.placeAt(2, 1, “North”); (0,1) (1,1) (2,2) (1,2) (0,2) shakey = new Robot(); shakey shakey = new Robot(); (0,0) (2,1)(2,0) (1,0)

47 Robot shakey; shakey.placeAt(2, 1, “North”); (0,1) (1,1) (2,2) (1,2) (0,2) shakey = new Robot(); (0,0) (2,1)(2,0) (1,0) a Robot (only) knows how to: turn left() move forward()

48 Robot shakey; shakey.placeAt(2, 1, “North”); (0,1) (1,1) (2,2) (1,2) (0,2) shakey = new Robot(); (0,0) shakey.left(); (2,1)(2,0) (1,0)

49 Robot shakey; shakey.placeAt(2, 1, “North”); (0,1) (1,1) (2,2) (1,2) (0,2) shakey = new Robot(); (0,0) shakey.forward(); (2,1)(2,0) (1,0) shakey.left();

50 Robot shakey; shakey.placeAt(2, 1, “North”); (0,1) (1,1) (2,2) (1,2) (0,2) shakey = new Robot(); (0,0) shakey.left(); shakey.forward(); (2,1)(2,0) (1,0) a Robot (only) knows how to: turn left() move forward()

51 shakey.left(); Robot shakey; shakey.placeAt(2, 1, “North”); (0,1) (1,1) (2,2) (1,2) (0,2) shakey = new Robot(); (0,0) shakey.left(); shakey.forward(); (2,1)(2,0) (1,0)

52 shakey.left(); Robot shakey; shakey.placeAt(2, 1, “North”); (0,1) (1,1) (2,2) (1,2) (0,2) shakey = new Robot(); shakey.left(); (0,0) shakey.left(); shakey.forward(); (2,1)(2,0) (1,0)

53 shakey.left(); Robot shakey; shakey.placeAt(2, 1, “North”); (0,1) (1,1) (2,2) (1,2) (0,2) shakey = new Robot(); shakey.left(); (0,0) shakey.left(); shakey.forward(); (2,1)(2,0) (1,0)

54 shakey.left(); Robot shakey; shakey.placeAt(2, 1, “North”); (0,1) (1,1) (2,2) (1,2) (0,2) shakey = new Robot(); shakey.left(); shakey.forward(); (0,0) shakey.left(); shakey.forward(); (2,1)(2,0) (1,0)

55 shakey.left(); Robot shakey; shakey.placeAt(2, 1, “North”); (0,1) (1,1) (2,2) (1,2) (0,2) shakey = new Robot(); shakey.left(); shakey.forward(); (0,0) shakey.left(); shakey.forward(); (2,1)(2,0) (1,0)

56 Well done, Shakey, way to go!


Download ppt "A201 (I201, A597) Introduction to Programming Adrian German Office: Lindley Hall (LH) 201D Class home page containing ALL the details:"

Similar presentations


Ads by Google