Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 180 Problem Solving and Object Oriented Programming Fall 2011 Notes for Week 3: September 5-9, 2011 Aditya Mathur Department of Computer Science Purdue.

Similar presentations


Presentation on theme: "CS 180 Problem Solving and Object Oriented Programming Fall 2011 Notes for Week 3: September 5-9, 2011 Aditya Mathur Department of Computer Science Purdue."— Presentation transcript:

1 CS 180 Problem Solving and Object Oriented Programming Fall 2011 Notes for Week 3: September 5-9, 2011 Aditya Mathur Department of Computer Science Purdue University West Lafayette, IN, USA http://www.cs.purdue.edu/homes/apm/courses/CS180Fall2011/ This week: 1.Quiz 2.Questions/Review 3.Writing simple programs to solve simple problems

2 Readings and Self-help Exercises for Week 3 Readings: Chapter 3: 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7 Self help Exercises [Not to be turned in]: 3.1, 3.2, 3.3, 3.7, 3.8, 3.23. 2©Aditya Mathur. CS 180. Fall 2011. Week 39/7/2011

3 Announcements 3©Aditya Mathur. CS 180. Fall 2011. Week 39/7/2011 Feast with faculty: To resume on September 14. Monday lecture by Dr Korb. Type conversions and handling strings. Project 1 deadline Friday September 23, 201. Late submission is not in your best interest. Programs in the textbook are now available for you to download and play with. Go to the course web site and click on the link marked Textbook Programs

4 Programming Competition 4©Aditya Mathur. CS 180. Fall 2011. Week 39/7/2011 Winning team gets a free: Please send me (apm@cs.purdue.edu) mail to register. I need names of the team members and of the team leader.

5 Questions? Frequency Code for your iClicker: AA 5©Aditya Mathur. CS 180. Fall 2011. Week 39/7/2011

6 Quiz 6©Aditya Mathur. CS 180. Fall 2011. Week 39/7/2011

7 Q1. The value of a will be 0 after which one of the following assignments? (a) float a=(float)1/2; (b) float a=1/2; (c ) int a=1/2; 7©Aditya Mathur. CS 180. Fall 2011. Week 39/7/2011 Correct answer: c

8 Q2. Which one of the following is not a primitive type in Java? (a)int (b)Float (c)float (d)double 8©Aditya Mathur. CS 180. Fall 2011. Week 39/7/2011 Correct answer: b

9 Q3. What is the value of the expression 7%2? (a)1 (b)0 (c)2 (d)3 9©Aditya Mathur. CS 180. Fall 2011. Week 39/7/2011 Correct answer: a

10 Q4. Given int a=4; what is the value of the expression a<<2? (a)8 (b)16 (c)32 (d)64 10©Aditya Mathur. CS 180. Fall 2011. Week 39/7/2011 Correct answer: b

11 Let us write a simple Java program: The problem 11©Aditya Mathur. CS 180. Fall 2011. Week 39/7/2011 Write a Java program to compute the net sale in dollars given the price of each ticket in dollars and the number of tickets sold. Assume that a randomly selected discount of between 3 to 7% is given on any sale.

12 Problem: Understanding 12©Aditya Mathur. CS 180. Fall 2011. Week 39/7/2011 This is an easy problem!

13 Problem: Design of solution 13©Aditya Mathur. CS 180. Fall 2011. Week 39/7/2011 Keep this step independent of Java! Step 1: Get data [price of a ticket and total tickets sold] Step 2: Compute total sale[multiply the items input] Step 3: Find discount to be given [3 to 7%] Step 4: Compute discounted sale price [=total sale-(total sale*discount)]. Step 5: Display the discounted sale price.

14 Problem: Refine solution: Get data 14©Aditya Mathur. CS 180. Fall 2011. Week 39/7/2011 Keep this step independent of Java! Step 1.1: Prompt for price Step 1.2: Read price Step 1.3: Prompt for number of tickets sold Step 1.4: Read number of tickets sold

15 Problem: Refine solution: Compute total sale 15©Aditya Mathur. CS 180. Fall 2011. Week 39/7/2011 Keep this step independent of Java! Step 2: Compute Total sale=price of a ticket * number of tickets sold

16 Problem: Refine solution: Compute discount 16©Aditya Mathur. CS 180. Fall 2011. Week 39/7/2011 Keep this step independent of Java! Step 3: Generate a random number (say, r) between 0 and 1 and convert this to a number (say, d) between 3 and 7. d=mr+c [Remember the straight line y=mx+c?] d r 01 7 3 m= ? c= ?

17 Problem: Refine solution: Compute discounted price 17©Aditya Mathur. CS 180. Fall 2011. Week 39/7/2011 Keep this step independent of Java! Step 4: Compute discounted price= total price-(total price*discount)

18 Problem: Refine solution: Display discounted price 18©Aditya Mathur. CS 180. Fall 2011. Week 39/7/2011 Keep this step independent of Java! Step 5: Display discounted price (as easy as that!!).

19 Code the solution in Java. Test it. 19©Aditya Mathur. CS 180. Fall 2011. Week 39/7/2011

20 Week 3: September 5-9, 2011 Hope you enjoyed this week! Questions? Contact your recitation instructor. Make full use of our office hours. 20©Aditya Mathur. CS 180. Fall 2011. Week 39/7/2011


Download ppt "CS 180 Problem Solving and Object Oriented Programming Fall 2011 Notes for Week 3: September 5-9, 2011 Aditya Mathur Department of Computer Science Purdue."

Similar presentations


Ads by Google