اذهب إلى المحتوى
  • 0

طريقة عمل كلاس بلغة الجافا للمنتجات

RAA

السؤال

احتاج مساعده في عمل كلاس في برنامج جافا عباره عن مواصفات المنتجات  من اسم ونوع  وسعر و IDومن ثم اعمل  arraylist من ال object 

وايضا بنفس الكلاس يكون في ميثود خاصة بعملية البحث عن منتج معين بالاسم او Id 

وميثود خاصة بعملية الشراء

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 0
بتاريخ 16 ساعات قال مسعود زاهي:

مرحبا Ra All،

قم بمحاولة كتابة هذه الكلاس لوحدك فهي بسيطة وضع الشيفرة هنا كي نساعدك ونوجهك.

تحياتي. 

import java.util.ArrayList;


public class SuperMarket {
    
  public static void main(String[] args) 
  {
    Product[] vegetables= new Product[3];
    vegetables[0] = new Product ("toomatoes","vegetables",35525,30);
    vegetables[1] = new Product ("onions","vegetables",39064,20);
    vegetables[2] = new Product ("carrots","vegetables",33987,25);


    Product[] fruits= new Product[3];
    fruits[0] = new Product ("Apple","fruits",23469,35);
    fruits[1] = new Product ("banana","fruits",29064,29);
    fruits[2] = new Product ("orange","fruits",23987,15);


    System.out.println(fruits[1].toString());

  }
    
}



public class Product 
{
    
   private String productsName;
   private String productsType;
   private int productsID;
   private double productsPrice;
    
    
    public Product()
    {
        productsName= null;
        productsType= null;
        productsID = 0;
        productsPrice = 0.0;
    }
    
    public Product(String productsName,String productsType,int productsID,double productsPrice )
    {
        this.productsName = productsName;
        this.productsType = productsType;
        this.productsID = productsID;
        this.productsPrice = productsPrice;
    }
    
    
    
    public void setproductsName(String productsName)
    {
        this.productsName = productsName;
    }
    
   public void setproductsType(String productsType)
    {
        this.productsType = productsType;
    }
   
    
   public void setproductsID(int productsID)
    {
        this.productsID = productsID;
    } 
   
  public void setproductsPrice(int productsPrice)
    {
        this.productsPrice = productsPrice;
    }  
  
  
    public String getproductsName()
    {
      return this.productsName;
    }
  
    public String getproductsType()
    {
      return this.productsType;
    }
  
  	public int getproductsID()
    {
        return this.productsID;
    }

	public double getproductsPrice()
    {
        return this.productsPrice;
    }


    public String toString()

    {
      String str = "Products name : " + productsName + 
              "\nProducts type: " + productsType + 
              "\nProducts ID: " + productsID  +
                      "\n Products price: " + productsPrice;
       return str;
    }

}

احتاج مساعدة في عمل ميثود ل search البحث باستخدام اسم المنتج او ID 

وميثود ل select

وميثود ل order

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0
بتاريخ 11 ساعات قال Ra All:

احتاج مساعدة في عمل ميثود ل search البحث باستخدام اسم المنتج او ID 

نلاحظ أن هاته الدوال ليست دوال تابعة لكائن من الصنف Product وإنما تابعة للصنف ككل.

لهذا يمكن إنشاء هذه الدوال على شكل دوال ساكنة static method بحيث يمكننا إستدعاؤها على الشكل التالي:

ArrayList<Product> products = Product.search("نكتب هنا كلمة البحث", allProducts);
// حيث
// allProducts هو مصفوفة كل المنتجات
Product selectedProduct = Product.select(1, allProducts);
ArrayList<Product> products = Product.order(allProducts);

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...