Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction To Programming Information Technology , 1’st Semester

Similar presentations


Presentation on theme: "Introduction To Programming Information Technology , 1’st Semester"— Presentation transcript:

1 Introduction To Programming Information Technology , 1’st Semester
MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Using Java Introduction To Programming Information Technology , 1’st Semester Lecture 17 Methods in Java Practices Teacher: Mahmoud Rafeek Alfarra

2 Practice 1 For the class Craps in Methods_Practice1 document , state the scope of each of the following entities: The variable randomNumbers. The variable die1. The method rollDice. The method play. The variable sumOfDice Presented & Prepared by: Mahmoud R. Alfarra

3 Practice 2 Give the method header for each of the following methods:
Method hypotenuse, which takes two double-precision, floating-point arguments side1 and side2 and returns a double-precision, floating-point result. Method smallest, which takes three integers x, y and z and returns an integer. Presented & Prepared by: Mahmoud R. Alfarra

4 Practice 2 Give the method header for each of the following methods:
Method instructions, which does not take any arguments and does not return a value. Method intToFloat, which takes an integer argument number and returns a floating-point result. Presented & Prepared by: Mahmoud R. Alfarra 4

5 Practice 3 Find the error in each of the following program segments. Explain how to correct the error. Presented & Prepared by: Mahmoud R. Alfarra

6 Practice 3 Find the error in each of the following program segments. Explain how to correct the error. Presented & Prepared by: Mahmoud R. Alfarra 6

7 Practice 3 Find the error in each of the following program segments. Explain how to correct the error. Presented & Prepared by: Mahmoud R. Alfarra 7

8 Practice 3 Find the error in each of the following program segments. Explain how to correct the error. Presented & Prepared by: Mahmoud R. Alfarra 8

9 Practice 4 Using Methods, Write a complete Java application to prompt the user for the double radius of a sphere, and call method sphereVolume to calculate and display the volume of the sphere. Use the following statement to calculate the volume: double volume = (4.0/ 3.0) * Math.PI * Math.pow( radius,3 ( Presented & Prepared by: Mahmoud R. Alfarra

10 Practice 5 What is the value of x after each of the following statements is executed? Presented & Prepared by: Mahmoud R. Alfarra

11 Practice 6 Write a method multiple that determines, for a pair of integers, whether the second integer is a multiple of the first. The method should take two integer arguments and return TRue if the second is a multiple of the first and false otherwise. Incorporate this method into an application that inputs a series of pairs of integers (one pair at a time) and determines whether the second value in each pair is a multiple of the first. Presented & Prepared by: Mahmoud R. Alfarra

12 Practice 7 Write a method isEven that uses the remainder operator (%) to determine whether an integer is even. The method should take an integer argument and return true if the integer is even and false otherwise. Incorporate this method into an application that inputs a sequence of integers (one at a time) and determines whether each is even or odd. Presented & Prepared by: Mahmoud R. Alfarra

13 Practice 8 Write a method squareOfAsterisks that displays a solid square (the same number of rows and columns) of asterisks whose side is specified in integer parameter side. For example, if side is 4, the method should display a square (4*4) . Incorporate this method into an application that reads an integer value for side from the user and outputs the asterisks with the squareOfAsterisks method. Presented & Prepared by: Mahmoud R. Alfarra

14 Practice 9 Modify the method created in Practice 8 to form the square out of whatever character is contained in character parameter fillCharacter. Thus, if side is 5 and fillCharacter is "#" ##### Presented & Prepared by: Mahmoud R. Alfarra

15 Practice 10 Trace the following program:
Calculate the integer part of the quotient when integer a is divided by integer b. Calculate the integer remainder when integer a is divided by integer b. Use the program pieces developed in parts (a) and (b) to write a method displayDigits that receives an integer between 1 and and displays it as a sequence of digits, separating each pair of digits by two spaces. For example, the integer 4562 should appear as Presented & Prepared by: Mahmoud R. Alfarra

16 Practice 10 Trace the following program:
Use the program pieces developed in parts (a) and (b) to write a method displayDigits that receives an integer between 1 and and displays it as a sequence of digits, separating each pair of digits by two spaces. For example, the integer 4562 should appear as Presented & Prepared by: Mahmoud R. Alfarra 16

17 Practice 10 Trace the following program:
Incorporate the method developed in part (c) into an application that inputs an integer and calls displayDigits by passing the method the integer entered. Display the results. Presented & Prepared by: Mahmoud R. Alfarra 17

18 Practice 11 An integer is said to be prime if it is divisible by only 1 and itself. For example, 2, 3, 5 and 7 are prime, but 4, 6, 8 and 9 are not. Write a method that determines whether a number is prime. Presented & Prepared by: Mahmoud R. Alfarra 18

19 Practice 12 Using methods, write application to sort the arrays, the method of sorting will receive the array and then sort it. Presented & Prepared by: Mahmoud R. Alfarra 19

20 More practices in the text book, chapters 6 & 7
Presented & Prepared by: Mahmoud R. Alfarra

21 يستغفر الله في المجلس الواحد أكثر من 70 مرة و يختم الصالحات بالاستغفار
Emank X Mezank كان النبي صلى الله عليه وسلم : يستغفر الله في المجلس الواحد أكثر من 70 مرة و يختم الصالحات بالاستغفار Presented & Prepared by: Mahmoud R. Alfarra

22 Next… Practices Presented & Prepared by: Mahmoud R. Alfarra


Download ppt "Introduction To Programming Information Technology , 1’st Semester"

Similar presentations


Ads by Google