AP Computer Science Summer Assignment Dr. Rabadi-Room 1315 New Rochelle High School nrabadi@nredlearn.org One great resource for any course is YouTube. Please watch videos to help you with any of the summer homework. Please try all of the TRY THIS problems throughout this document. When done, do the following: Watch the Youtube video Java tutorial 1: hello Java! Getting started with eclipse by Maxwell Sanchez Download the program eclipse. You should look for the following icon: Run the program "Hello World" You can go to the video and type it. Go to File New Java Project Name the project, then return to; go to File New Class. Type in the program below: public class Intro { } public static void main(string[] args) { System.out.println("Hello World"); } Hit the play (run) button when done. Experiment by changing Hello World to any phrase you want. Finally, read chapter 1 from the link below. These are the basics about computers. http://math.hws.edu/eck/cs124/downloads/javanotes5-linked.pdf Answer the questions at the end of the chapter named quiz on chapter 1. This is found on page 17 of the chapter but page 31 on the pdf document. Please send me an email to rrabadi@nredlearn.org if you need clarification or assistance with anything. Have a great summer.
Decimal base 10 Binary base 2 Hexadecimal base 16 It is very important to know how to convert from decimal to binary and binary to decimal. Converting to Hexadecimal will be taught during the first week of class, but please feel free to learn about them. Please take some time to read the following: To convert the number (decimal) 57 to binary (base 2), you should make a box and write down Binary number : Power of 2: 2 6 2 5 2 4 2 3 2 2 2 1 2 0 Since I know 2 6 is 64, I know I went over. Therefore I only need up to 2 5. Binary numbers can only take on the two numbers 1 and 0. You cannot use any other value. Take a look at the chart below to see how 57 (base 10) is 111001 2 binary number: 1 1 1 0 0 1 power of 2: 2 5 2 4 2 3 2 2 2 1 2 0 111001 2 = 1 2 5 +1 2 4 +1 2 3 +0 2 2 +0 2 1 +1 2 0 = 57 Similarly, if you have the binary 111001 2 then what you should do is make a 6 lines (because in this example there are six numbers) and below the lines you write the powers of 2. 2 5 2 4 2 3 2 2 2 1 2 0 Then place the binary on top of each one and compute the value as shown in the table above. 1 1 1 0 0 1 2 5 2 4 2 3 2 2 2 1 2 0 When you understand try the following examples. The answers are below the examples so that you can check your work. NOTE: Some answers have many zeros in the beginning and that is because many people write binary using 8 digits. However, the zeros in the beginning are not necessary and it is not recommended that you put them there. Again if you need more help, please watch a YouTube video. There are many great ones.
TRY THIS: Problem Set 1: Convert from Binary numbers to Decimal 1. 11001011 2. 00110101 3. 10000011 4. 10001111 5. 11100011 6. 00000100 7. 00010010 8. 00111111 9. 10101010 10. 01010101
Answers Binary to Decimal 1. 11001011 203 2. 00110101 53 3. 10000011 131 4. 10001111 143 5. 11100011 227 6. 00000100 4 7. 00010010 18 8. 00111111 63 9. 10101010 170 10.01010101 85
Problem Set 2: Convert from Decimal to Binary 11. 213 12. 9 13. 67 14. 99 15. 23 16. 143 17. 6 18. 1 19. 197 20.252
Answers for converting Decimal to Binary 11. 213 11010101 12. 9 00001001 13. 67 01000011 14. 99 01100011 15. 23 00010111 16. 143 10001111 17. 6 00000110 18. 1 00000001 19. 197 11000101 20. 252 11111100
Logic Section A statement can either be true or false. We usually represent a statement with a letter that is associated to the statement somehow. For example, Aaron went to the store. Aaron purchased eggs and bacon can be represented as: Let S: represent Aaron went to the store. Let E: represent Aaron purchased eggs. Let B: represent Aaron purchased bacon. Notice that we do not use A for Aaron because Aaron comes up in more than one sentence. Some logic that we should know: Conjunction is the truth-functional connective which forms compound propositions which are true if and only if both statements are true. Also known as the and statement, it is represented in mathematics by the symbol ^. The only way a conjunction can be true is if both statements are true. In computer programming, the symbol for and is a double ampersand &&. T T Disjunction is a connective which forms compound propositions which is true if one statement is true Also known as the or statement, it is represented in mathematics by the symbol V. T. The only way a disjunction can be True if one statement is True. In computer programming, the symbol for or is a double line. Negation: The negation statement is the not statement. It changes the value from true to false and false to true. The mathematical symbol for negation is ~. In computer programming, we use the! symbol to represent negation. Demorgan s Law are rules of logic that show what happens when you negate a conjunction or negate a disjunction. This is very important to remember. ~(p q) is logically equivalent to ~p ~q ~(p q) is logically equivalent to ~p ~q
This can be shown by creating the following truth table 1 2 3 4 5 6 7 p q p q ~(p q) ~p ~q ~p ~q T T T F F F F T F F T F T T F T F T T F T F F F T T T T Column 4 and column 7 are equivalent showing that the two statements are equivalent. To do this, I dissected each part. In other words, I asked myself, what parts of the puzzle do I need to show that this is true. Well, you needed the parts that I put in the column. TRY THIS: Show this for the second statement. That is, show ~(p V q) is logically equivalent to ~p ~q. Fill in the chart. p q p q ~(p q) ~p ~q ~p ~q T T T F F T F F Law of Contrapositive: Also logically equivalent to an original statement is its contrapositive (switching the statements around and negating them). p q is logically equivalent to ~q ~p Law of Disjunctive Inference is when you are given two statements that are compounded with an or. Only one of the two statements will happen. Depending on the statement, the conclusion is the opposite. For example, Law of Disjunctive Inference: Statement 1: I will drink milk OR I will drink water. Statement 2: I will not drink milk Conclusion: I will drink water. Using symbols, this looks like Statement 1: M W
Statement 2: ~W Conclusion: M Law of Syllogism (Chain Rule): Statement 1: If I go to the movies, then I will buy popcorn Statement 2: If I buy popcorn, then I will buy soda. Conclusion: If I go to the movies, then I will buy soda. This can be written symbolically in the following way, Statement 1: M P Statement 2: P S Conclusion: M S Law of Detachment Statement 1: If I drive to the park, I will need gas for my car. Statement 2: I drive to the park. Conclusion: I will need gas for my car. Law of Modus Tollens (denying the consequent): It makes more sense if we take a look at this by example. If a watchdog detects an intruder then the watchdog will bark. The watchdog does not bark. Therefore, the watchdog did not detect the intruder. Symbolically shown: Statement 1: D B Statement 2: ~B Conclusion: ~D Putting all these laws together, let s try the following example Given: If I get a summer job, then I will earn money. If I fail mathematics, then I will not earn money. I get a summer job or I am not happy. I am happy or I am not successful. I am successful.
Prove: I did not fail mathematics. Statement 1) If I get a summer job, then I will earn money. 2) If I fail mathematics, then I will not earn money. 3) I get a summer job or I am not happy. 4) I am happy or I am not successful. 5) I am successful. Reason Given 6) I am not happy Disjunctive inference (using statements 4, 5) 7) I get a summer job Disjunctive inference (using statements 3, 6) 8) I will earn money Detachment (using statements 7 and 1) 9) I will not fail mathematics Modus Tollens (using statements 2 and 8) TRY THIS: A ~B D ~C (~D ~E) F C v B A ~F Prove: E TRY THIS: Use statement-reason method to prove it. Given: Beta is not true Alpha is true or beta is true If gamma is not true, then alpha is not true If sigma is not true, then delta is true If gamma is true, then delta is not true or epsilon is not true or epsilon is not true Epsilon is true Prove: Sigma is true
TRY THIS: Given: If I save money, then I buy a car. If I do not save money, then I will take the train. If I buy a car and I buy a bike, then I need insurance. I do not need insurance. I buy a bike. Prove: I take the train.