Presentation is loading. Please wait.

Presentation is loading. Please wait.

Practice and Evaluation. Practice Develop a java class called: SumCalculator.java which computes a sum of all integer from 1 to 100 and displays the result.

Similar presentations


Presentation on theme: "Practice and Evaluation. Practice Develop a java class called: SumCalculator.java which computes a sum of all integer from 1 to 100 and displays the result."— Presentation transcript:

1 Practice and Evaluation

2 Practice Develop a java class called: SumCalculator.java which computes a sum of all integer from 1 to 100 and displays the result to the screen

3 Problems with practice exercise Problem solving skill: –Recognize and understand problems –Develop an algorithm –Coding Java syntax –Translate from algorithm to code –Practice. Practice. Practice

4 Flowchart and Algorithm - a computer is only a problem-solving tool! - Java is one tool used to solve problems

5 Method of Problem Solving Recognize and understand the problem. Accumulate facts. Select appropriate theory. Make necessary assumptions. Solve the problem. Verify results.

6 Method of Problem Solving Develop an Algorithm. Write the program in a computer language. (i.e. in C, Java etc) Enter the program into the computer. Test and debug the program. Run the program, input data, and get the results from the computer.

7 Algorithm and Flowchart An Algorithm is just a detailed sequence of simple steps that are needed to solve a problem. A Flowchart is a graphical representation of an algorithm.

8 Algorithm (Week 3 practice) Develop a java class called: SumCalculator.java which computes a sum of all integers from 1 to 100 and displays the result to the screen Step 1: Understand the problem: Computes a sum of all integers from 1 to 100 Step 2: What is the input? Step 3: What is the output? Start from 1, stop if reach 100 or (1 and 100) Sum

9 Algorithm Step 4: How do we compute the output? (first solution) Step 4.1: Start with the current integer: 1 Step 4.3: Add the current integer to Sum Step 4.2: Sum starts with 0 Step 4.4: If the current integer is less than 100, keep on adding the current integer to sum and increase It by 1(i.e, go back to 4.3). Step 4.5:Otherwise, print out the sum

10 Algorithm StartStop Sequential steps Condition/ Decision

11 Flowchart Step 4.3: Add the current integer to Sum Step 4.1: Start with the first integer: 1 Step 4.2: Sum starts with 0 Step 4.4: If the current integer is less than 100, go to next integer and keep on adding the current integer to sum (i.e, go back to 4.3). Step 4.5:Otherwise, print out the sum Stop Current Integer=1 Sum=0 Sum = Sum + Current Integer < 100 Increase Current Integer by 1 Print Sum Start

12 Practice Step 4 (second solution): sum = 100*(100+1)/2

13 Testing a program Ideal: Test cases should be designed BEFORE writing the code Practice: Test cases are only designed AFTER the code is written Time to write codes <= Time to test

14 What should we test Philosophy: –Test everything that could reasonably break. For example: Test if the inputs received from a user is valid Test if the computation is done correctly

15 How to develop a test case A test case is a document that contains - test case id - description of what this test case is - an input, - an action, or event and - an expected response to determine if a feature of an application is working correctly.

16 Example Test Case Id: Testcase01 Description: Testing if the program exits when an invalid number of weeks is entered Input: an integer represents a number of weeks and is outside of [1..12] Expected response: the program will display a message and exit

17 Testing Amortization.java Please test the Amortization.java in (c), (d) and (e) following the test cases given

18 Practice -Modify the existing SumCalculator.java program to print out the average:

19 Practice Develop a class called PrintEven to print only even integers from 1 to 100 Modify the existing PrintEven to print only even integers from 1 to n. Allow a user to enter the value for n.

20 Check list Make sure comments are included in LoanCalculator.java Make sure that the directories are created, classes and java files are copied according to the requirements of the project Make sure to copy the design document Email (zip files), or submit your project on floppy disk or CD on time

21 Practice Write the code ComputeMin to print out the minimum of three integers. Three integers are inputs from a user Reuse the code ComputeMin to develop ComputeMax which prints out the maximum of three integers. Three integers are inputs from a user

22 Practice Develop a class call PrimeNumber that: –Get an integer as input from users –If the integer is a prime number, print out a message that says: Prime number –If not, print out a message that says: It is not a prime number

23 Algorithm Run a for loop that tests to see if any number from 2 up to sqrt(n) divides evenly into the given number. If you find one, then the number isn't prime. If you don't find one, the number is prime.


Download ppt "Practice and Evaluation. Practice Develop a java class called: SumCalculator.java which computes a sum of all integer from 1 to 100 and displays the result."

Similar presentations


Ads by Google