الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كيف اربط برنامج جافا مع كلاس جافا في المثال المرفق

بدأه FunnyWolF في 6 مايو 2009 · 7 رد · 827 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكــم ورحمـة الله وبركاتــه ،،

انا عندي مشكله بسيطه _ بحكم انكم خبراء _ المشكله انو عندي برنامج جافا يعطي خيارات للمستخدم لحساب اشكال هندسيه

والبرنامج يجب ان يكون مربوط مع كلاس, انا البرنامج اوكي ناقصني بس طريقة استدعاء جزء معين من الكلاس على حسب اخيار المستخدم

هذا كود البرنامج

 import java.util.Scanner;

 public class GeometryCalc
 {
 public static void main(String[] args)
	 {
	 int choice;
	 int input;
	 // Create a Scanner object to read input.
	 Scanner keyboard = new Scanner(System.in);
	 // Ask the user to enter his choice
	 System.out.println("Geometry Calculator");
	 System.out.println("1. Calculate the Area of a Circle");
	 System.out.println("2. Calculate the Area of a Rectangle");
	 System.out.println("3. Calculate the Area of a Triangle");
	 System.out.println("4. Quit ");
	 System.out.println("Enter your choice (1-4):");
	 input =  keyboard.nextint();
	 choice = input.nextint();  // Get the user choice
	 // Determine which number the user entered.
	 switch (choice)
		 {
		 case 1:
			 System.out.println("You entered 1.");
		   break;
	   case 2:
		   System.out.println("You entered 2");
		   break;
	   case 3:
			 System.out.println("You entered 3");
		   break;
	   case 4:
			   System.out.println("Goodbye!");	  
	   default:
			 System.out.println("Error: Enter 1, 2, 3, or 4");
	   }
	 }
 }

وهذا الكلاس حقي المفقع هههههههههههههههههههههههههههههههه

   public class Geometry
 {



	 double radius, area;
	 // Input radius from keyboard
	 radius = Keyin.inDouble("Enter the circle radius: ");
	 // Perform calculations and display result
	 area = Math.PI * (radius * radius);
	 System.out.println("The area is: " + area);





	 int len, wed;
	 double area;
	 len = Keyin.inDouble("Enter the lenght of the rectangle: ");
	 wed = Keyin.inDouble("Enter the wedth of the rectangle: ");
	 area = len*wed;
	  System.out.println("Area of the Rectangle is" + area);






	  double base, height;
	  base = Keyin.inDouble("Enter the value of the tringle base:");
	  height = Keyin.inDouble("Enter the value of the tringle Height:");
	 area= (base*height)/2;
	 System.out.println("The area of triangle is :"+ area);



 }

ويعطيكم العافيه مقدما

#2

السلام عليكــم ورحمـة الله وبركاتــه ،،

يجب أن تعدلي الكلاس Geometry



public static void circleArea() {
double radius, area;
// Input radius from keyboard
radius = Keyin.inDouble("Enter the circle radius: ");
// Perform calculations and display result
area = Math.PI * (radius * radius);
System.out.println("The area is: " + area);
}

public static void rectangleArea() {
int len, wed;
double area;
len = Keyin.inDouble("Enter the lenght of the rectangle: ");
wed = Keyin.inDouble("Enter the width of the rectangle: ");
area = len*wed;
System.out.println("Area of the Rectangle is" + area);
}

public static void triangleArea() {
double base, height;
base = Keyin.inDouble("Enter the value of the triangle base: ");
height = Keyin.inDouble("Enter the value of the triangle Height: ");
area = (base*height)/2;
System.out.println("The area of triangle is :"+ area);
}
}
public class Geometry {

وفي الmain، تقومين بالمناداة على ميثود حسب اختيار المستعمل

مثلا عند اختيار 1،


Geometry.circleArea();
break;
case 1:

#3

يعطيك الف الف الف عافيه

لكن عندي ايرور في الكلاس ومش غارف المشكله بالذات

public class Geometry
{

  public static void circleArea()
  {
	double radius, area;
   // Input radius from keyboard
   radius = keyboard.nextDouble("Enter the circle radius: ");
   // Perform calculations and display result
   area = Math.PI * (radius * radius);
   System.out.println("The area is: " + area);
   }

   public static void rectangleArea()
   {
	int len, wed;
	double area;
	len = keyboard.nextInt("Enter the lenght of the rectangle: ");
	wed = keyboard.nextInt("Enter the width of the rectangle: ");
	area = len*wed;
	System.out.println("Area of the Rectangle is" + area);
	}

	public static void triangleArea()
	{
	 double base, height, area;
	 base = keyboard.nextDouble("Enter the value of the triangle base: ");
	 height = keyboard.nextDouble("Enter the value of the triangle Height: ");
	 area = (base*height)/2;
	 System.out.println("The area of triangle is :"+ area);
	 }
}

والمشكله هي

cannot find symbol symbol  : variable keyboard
location: class Geometry
radius = keyboard.nextDouble("Enter the circle radius: ");

المشكله انو مو متعرف على ال

keyboard

وانا برضو جربت

keyin

وكانت نفس المشكله

#4

السلام عليكــم ورحمـة الله وبركاتــه ،،

طبيعي، لأنه لا توجد متحولة إسمها keyboard داخل الكلاس Geometry

يجب إضافة

import java.util.Scanner;

في بداية الكود

و

static Scanner keyboard = new Scanner(System.in);

داخل الكلاس Geometry


public class Geometry
{
static Scanner keyboard = new Scanner(System.in);
public static void circleArea()
{
double radius, area;
// Input radius from keyboard
radius = keyboard.nextDouble("Enter the circle radius: ");
// Perform calculations and display result
area = Math.PI * (radius * radius);
System.out.println("The area is: " + area);
}

public static void rectangleArea()
{
int len, wed;
double area;
len = keyboard.nextInt("Enter the lenght of the rectangle: ");
wed = keyboard.nextInt("Enter the width of the rectangle: ");
area = len*wed;
System.out.println("Area of the Rectangle is" + area);
}

public static void triangleArea()
{
double base, height, area;
base = keyboard.nextDouble("Enter the value of the triangle base: ");
height = keyboard.nextDouble("Enter the value of the triangle Height: ");
area = (base*height)/2;
System.out.println("The area of triangle is :"+ area);
}
}
 import java.util.Scanner;

تم تعديل هذه المشاركة بواسطة herch في 6 مايو 2009 في 16:32

#5

طيب اخي

انا تطلعلي 5 ايرور

 javac GeometryCalc.java
./Geometry.java:10: nextDouble() in java.util.Scanner cannot be applied to (java.lang.String)
   radius = keyboard.nextDouble("Enter the circle radius: ");
						  ^
./Geometry.java:20: cannot find symbol
symbol  : method nextInt(java.lang.String)
location: class java.util.Scanner
	len = keyboard.nextInt("Enter the lenght of the rectangle: ");
					   ^
./Geometry.java:21: cannot find symbol
symbol  : method nextInt(java.lang.String)
location: class java.util.Scanner
	wed = keyboard.nextInt("Enter the width of the rectangle: ");
						 ^
./Geometry.java:29: nextDouble() in java.util.Scanner cannot be applied to (java.lang.String)
	 base = keyboard.nextDouble("Enter the value of the triangle base: ");
						  ^
./Geometry.java:30: nextDouble() in java.util.Scanner cannot be applied to (java.lang.String)
	 height = keyboard.nextDouble("Enter the value of the triangle Height: ");
							 ^
5 errors

وللمعلوميه انا استخدم نظام لينكس

فهل هذا سبب ؟

#6

لا علاقة للينوكس بالمشكل

لا توجد ميثود nextInt أو nextDouble تستقبل String

الموجود هو nextInt() و nextDouble() بدون parameter

استعمل فقط System.out.println("your message") لكتابة ما تريد

#7

شكراً لك اخي الكريم انا مو عارف كيف اشكرك

لكن بقى عندي خطأ واحد اللي هو

./Geometry.java:10: incompatible types
found   : void
required: double
   radius = System.out.println("Enter the circle radius: ");
							  ^
1 error

فهل لانو انا اسندت قيمة

radius

للجمله كلها؟

وجزاك الله الف الف خير

#8

يا أخي قم بنفس الذي قمت به في الكلاس الأولى التي كتبت عندما تقرأ إختيار المستعمل


radius = keyboard.nextDouble();

.............................

System.out.println("Enter the lenght of the rectangle: ");
len = keyboard.nextInt();
System.out.println("Enter the width of the rectangle: ");
wed = keyboard.nextInt();
....................................

//same thing for triangle
System.out.println("Enter the circle radius: ");

System.out.println تقوم بالكتابة وليس القراءة وأنا قلت إستعملها للكتابة وليس لقراءة ما كتب المستعمل

للقراءة استعمل الميثود الخاصة بScanner

nextInt, nextDouble ...

تم تعديل هذه المشاركة بواسطة herch في 6 مايو 2009 في 20:16

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…