fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8.  
  9. /* package whatever; // don't place package name! */
  10.  
  11. import java.util.*;
  12. import java.lang.*;
  13. import java.io.*;
  14.  
  15. /* Name of the class has to be "Main" only if the class is public. */
  16.  
  17.  
  18. class Car {
  19. // الخصائص Attributes
  20. String brand;
  21. String model;
  22. int year;
  23. double price;
  24.  
  25. // Constructor
  26. public Car(String brand, String model, int year, double price) {
  27. this.brand = brand;
  28. this.model = model;
  29. this.year = year;
  30. this.price = price;
  31. }
  32.  
  33. // عرض معلومات السيارة
  34. public void displayInfo() {
  35. System.out.println("اسم الشركة: " + brand);
  36. System.out.println("طراز السيارة: " + model);
  37. System.out.println("سنة الصنع: " + year);
  38. System.out.println("السعر: " + price);
  39. }
  40.  
  41. // دالة تصنيف السيارة حسب السعر
  42. public void checkStatus() {
  43. if (price >= 30000) {
  44. System.out.println("سيارة فخمة");
  45. }
  46. else if (price >= 15000 && price < 30000) {
  47. System.out.println("سيارة متوسطة");
  48. }
  49. else {
  50. System.out.println("سيارة اقتصادية");
  51. }
  52. }
  53. }
  54.  
  55. // الكلاس الرئيسي
  56. public class Main {
  57. public static void main(String[] args) {
  58.  
  59. // إنشاء كائنات
  60. Car c1 = new Car("Toyota", "Corolla", 2022, 25000);
  61. Car c2 = new Car("BMW", "X5", 2023, 55000);
  62. Car c3 = new Car("Kia", "Rio", 2020, 12000);
  63.  
  64. // عرض النتائج
  65. c1.displayInfo();
  66. c1.checkStatus();
  67. System.out.println(".....................");
  68.  
  69. c2.displayInfo();
  70. c2.checkStatus();
  71. System.out.println(".....................");
  72.  
  73. c3.displayInfo();
  74. c3.checkStatus();
  75. }
  76. }
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
Success #stdin #stdout 0.16s 57868KB
stdin
Standard input is empty
stdout
اسم الشركة: Toyota
طراز السيارة: Corolla
سنة الصنع: 2022
السعر: 25000.0
سيارة متوسطة
.....................
اسم الشركة: BMW
طراز السيارة: X5
سنة الصنع: 2023
السعر: 55000.0
سيارة فخمة
.....................
اسم الشركة: Kia
طراز السيارة: Rio
سنة الصنع: 2020
السعر: 12000.0
سيارة اقتصادية