السلام عليكم
الله يجزاك الف خير
بس ممكن تحل هذي السؤالين >
1. Write method distance to calculate the distance between two points (x1, y1) and (x2, y2). All numbers and return values should be of type double. Incorporate this method into an application that enables the user to enter the coordinates of the points.
Hints:
• The distance between two points can be calculated by taking the square root of
( x2 - x1 )2 + ( y2 - y1 )2
• Use Math class methods to compute the distance.
• Your output should appear as follows
ويطلع االاوت بوت
Type the end-of-file indicator to terminate
On UNIX/Linux/Mac OS X type <ctrl> d then press Enter
On Windows type <ctrl> z then press Enter
Or Enter X1: 1
Enter Y1: 1
Enter X2: 4
Enter Y2: 5
Distance is 5.000000
Type the end-of-file indicator to terminate
On UNIX/Linux/Mac OS X type <ctrl> d then press Enter
On Windows type <ctrl> z then press Enter
Or Enter X1: ^Z
|
الأسئلة هذي مستواها أعلى من المتوسط، كيف تاخذوها ؟
حل السؤال الاول:
كود PHP:
package squareroot;
import java.util.Scanner;
public class Points{
public void calculateDistance(){
Scanner input = new Scanner( System.in );
System.out.printf( "%s\n %s\n %s\n",
"Type the end-of-file indicator to terminate",
"On UNIX/Linux/Mac OS X type <ctrl> d then press Enter",
"On Windows type <ctrl> z then press Enter" );
System.out.print( "Or Enter X1: " );
while ( input.hasNext() ){
double x1 = input.nextDouble();
System.out.print( "Enter Y1: " );
double y1 = input.nextDouble();
System.out.print( "Enter X2: " );
double x2 = input.nextDouble();
System.out.print( "Enter Y2: " );
double y2 = input.nextDouble();
double distance = distance(x1,y1,x2,y2 );
System.out.printf( "Distance is %f\n\n", distance );
System.out.printf( "%s\n %s\n %s\n",
"Type the end-of-file indicator to terminate",
"On UNIX/Linux/Mac OS X type <ctrl> d then press Enter",
"On Windows type <ctrl> z then press Enter" );
System.out.print( "Or Enter X1: " );}}
public double distance( double x1, double y1, double x2, double y2 ){
return Math.sqrt( Math.pow( ( x1 - x2 ), 2 ) +
Math.pow( ( y1 - y2 ), 2 ) );}
public static void main( String args[] ){
Points application = new Points();
application.calculateDistance();}
}
السؤال الثاني
2. Write an application that prompts the user for the radius of a circle and uses a method called circleArea to calculate the area of the circle.
Hints:
• Use the constant Math.PI in the area calculation.
• This application should be similar to the one in Coding Exercise 6.
• Your output should appear as follows:
Enter the radius (negative to quit): 10
Area is 314.159265
Enter the radius (negative to quit): -1
|
حل السؤال الثاني:
كود PHP:
package circle;
import java.util.Scanner;
public class Circle{
public void calculateAreas(){
Scanner input = new Scanner( System.in );
System.out.print( "Enter the radius (negative to quit): " );
double radius = input.nextDouble();
while (radius>=0){
circleArea(radius);
System.out.print( "Enter the radius (negative to quit): " );
radius = input.nextDouble();}}
public void circleArea(double radius){
System.out.printf( "Area is %f\n", Math.PI * radius * radius );}
public static void main( String args[] ){
Circle application = new Circle();
application.calculateAreas();}
}
وشكرا
والله ماتتصور قد ايش دعيتلك مع الفجر
هالواجبات مالها داعي مع الاختبارات
|
الله يجزاكِ كل خير على الدعوات ،، بالتوفيق أختي والله يسهلك الاختبارات إن شاء الله