A201 (I201, A597) Introduction to Programming
description
Transcript of A201 (I201, A597) Introduction to Programming
![Page 1: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/1.jpg)
A201 (I201, A597) Introduction to Programming
Adrian German ([email protected])
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!
![Page 2: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/2.jpg)
The purpose of this class:
![Page 3: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/3.jpg)
The purpose of this class:
- to get to know each other better
![Page 4: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/4.jpg)
The purpose of this class:
- to get to know each other better
- to understand programming in Java
![Page 5: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/5.jpg)
The purpose of this class:
- to get to know each other better
- to understand programming in Java
- to improve our problem solving skills
![Page 6: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/6.jpg)
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:
![Page 7: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/7.jpg)
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.
![Page 8: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/8.jpg)
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!
![Page 9: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/9.jpg)
What is Programming?
![Page 10: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/10.jpg)
What is Programming?
What does it look like?
![Page 11: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/11.jpg)
What is Programming?
What does it look like?
Let’s work out some examples.
![Page 12: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/12.jpg)
First Problem
![Page 13: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/13.jpg)
First Problem
You are given two (different length) strings
![Page 14: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/14.jpg)
First Problem
You are given two (different length) strings that have the characteristic that they both take exactlyone hour to burn.
![Page 15: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/15.jpg)
First Problem
You are given two (different length) strings that have the characteristic that they both take exactlyone hour to burn. However, neither string burns at a constant rate.
![Page 16: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/16.jpg)
First Problem
You are given two (different length) strings that have the characteristic that they both take exactlyone hour to burn. However, neither string burns at a constant rate. Some sections of the strings burn very fast; other sections burn very slowly.
![Page 17: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/17.jpg)
First Problem
You are given two (different length) strings that have the characteristic that they both take exactlyone 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.
![Page 18: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/18.jpg)
First Problem
You are given two (different length) strings that have the characteristic that they both take exactlyone 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.
![Page 19: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/19.jpg)
Second Problem
![Page 20: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/20.jpg)
Second Problem
A farmer lent the mechanic next door a 40-pound weight.
![Page 21: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/21.jpg)
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.
![Page 22: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/22.jpg)
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.
![Page 23: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/23.jpg)
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.
![Page 24: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/24.jpg)
Third Problem
![Page 25: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/25.jpg)
Third Problem
A captive queen weighing 195 pounds,
![Page 26: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/26.jpg)
Third Problem
A captive queen weighing 195 pounds, her son weighing 90 pounds,
![Page 27: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/27.jpg)
Third Problem
A captive queen weighing 195 pounds, her son weighing 90 pounds, and her daughter weighing 165 pounds
![Page 28: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/28.jpg)
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.
![Page 29: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/29.jpg)
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.
![Page 30: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/30.jpg)
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
![Page 31: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/31.jpg)
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.
![Page 32: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/32.jpg)
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?
![Page 33: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/33.jpg)
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.
![Page 34: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/34.jpg)
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.
![Page 35: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/35.jpg)
A Story
![Page 36: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/36.jpg)
Shakey the Robot()
Based on a character created by Suzanne Menzel
![Page 37: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/37.jpg)
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!
![Page 38: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/38.jpg)
![Page 39: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/39.jpg)
are solid walls (nothing can go through)red lines
![Page 40: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/40.jpg)
(0,0)
![Page 41: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/41.jpg)
(0,1)(0,0)
![Page 42: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/42.jpg)
(0,1) (0,2)(0,0)
![Page 43: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/43.jpg)
(0,1)
(1,1)
(2,2)
(1,2)
(0,2)(0,0)
(2,1)(2,0)
(1,0)
![Page 44: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/44.jpg)
Robot shakey;
(0,1)
(1,1)
(2,2)
(1,2)
(0,2)(0,0)
(2,1)(2,0)
(1,0)
![Page 45: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/45.jpg)
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)
![Page 46: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/46.jpg)
Robot shakey;
shakey.placeAt(2, 1, “North”);
(0,1)
(1,1)
(2,2)
(1,2)
(0,2)
shakey = new Robot();
shakeyshakey
shakey = new Robot();
(0,0)
(2,1)(2,0)
(1,0)
![Page 47: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/47.jpg)
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()
![Page 48: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/48.jpg)
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)
![Page 49: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/49.jpg)
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();
![Page 50: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/50.jpg)
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()
![Page 51: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/51.jpg)
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)
![Page 52: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/52.jpg)
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)
![Page 53: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/53.jpg)
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.left();
(0,0)
shakey.left();shakey.forward();
(2,1)(2,0)
(1,0)
![Page 54: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/54.jpg)
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.left();shakey.forward();
(0,0)
shakey.left();shakey.forward();
(2,1)(2,0)
(1,0)
![Page 55: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/55.jpg)
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.left();shakey.forward();shakey.forward();
(0,0)
shakey.left();shakey.forward();
(2,1)(2,0)
(1,0)
![Page 56: A201 (I201, A597) Introduction to Programming](https://reader036.fdocuments.net/reader036/viewer/2022062409/56814e4a550346895dbbd1b9/html5/thumbnails/56.jpg)
Well done, Shakey, way to go!