منتدى مصر التقني
هل تريد التفاعل مع هذه المساهمة؟ كل ما عليك هو إنشاء حساب جديد ببضع خطوات أو تسجيل الدخول للمتابعة.

تمارين بلغة الجافا...أكتب برنامج لحساب مساحة المثلث و المربع و مساحة وحجم المكعب

اذهب الى الأسفل

تمارين بلغة الجافا...أكتب برنامج لحساب مساحة المثلث و المربع و مساحة وحجم المكعب Empty تمارين بلغة الجافا...أكتب برنامج لحساب مساحة المثلث و المربع و مساحة وحجم المكعب

مُساهمة من طرف أحمد مناع الأحد أبريل 26, 2020 2:22 pm

اهلا وسهلا بكم

راسلنى احد الاصدقاء على صفحات الفيس طلبا لحل النشاط التالى :

Anyone help me to create this Program,i want it to be done


Shape - Area Volume Calculator
Create an abstract public class Shape with the below public abstract methods :
public double area()
public double volume()
Create a public class Rectangle with private attributes :
double length
double width
Write the public getters and setters for these attributes.
Rectangle class should inherit the Shape class
Area of rectangle is length * width
Create a public class Triangle with private attributes :
double base
double height
Write the public getters and setters for these attributes.
Triangle class should inherit the Shape class
Area of triangle is  1/2 * base * height
Create a public class Cube with private attributes :
double length
double width
double height
Write the public getters and setters for these attributes.
Cube class should inherit the Shape class
Area of cube is  2 * length * width + 2 * length * height + 2* width * height
Volume of cube is  length * width * height
Create a public class Sphere with private attributes :

و حل السؤال على النحو التالى :

الفئة المجردة Shape.java


الكود:

public abstract class Shape {

   public double area();
   public double volume();
    
}


Rectangle.java

الكود:

public class Rectangle extends Shape {
    private double width, length;

  
    
    public void setwidth(double w){
      this.width = w;
      
    }
     public double getwidth(){
      return  this.width;
     }
    
    public void setlength(double l){
      this.length = l;
      
    }
     public double getlength(){
      return  this.length ;
     }
    

    @Override
    public double area() {
      
        return width * length;
    }

}

Triangle.java

الكود:

public class Triangle extends Shape {
    private  double base,height;

    public void setheight(double h){
      this.height = h;
      
    }
     public double getheight(){
      return  this.height;
     }
    
      public void setbase(double b){
      this.base = b;
      
    }
     public double getbase(){
      return  this.base;
     }

    @Override
    public double area() {
        
        double s = (base * height) / 2;
        return s;
    }

  
}


Cube.java

الكود:

public class Cube extends Shape{
    
    private double width, length,height;
    
     public void setwidth(double w){
      this.width = w;
      
    }
     public double getwidth(){
      return  this.width;
     }
    
    public void setlength(double l){
      this.length = l;
      
    }
     public double getlength(){
      return  this.length ;
     }
    
     public void setheight(double h){
      this.height = h;
      
    }
     public double getheight(){
      return  this.height;
     }
    
     @Override
    public double area() {
      
        return 2*width * length+2*length*height+2*width*height;
    }
    
     @Override
    public double volume() {
      
        return 2*width * length+2*length*height+2*width*height;
    }
}



الفئة التى تحتوى على الدالة الرئسية لتفيذ البرنامج:   myTest.java


الكود:

public class myTest {

    public static void main(String[] args) {
        
        // Rectangle test
        Rectangle rectangle = new Rectangle();
        rectangle.setwidth(70);
        rectangle.setlength(40);
        
        System.out.println("The Resulting area: " + rectangle.area()  + "\n");

        //Triangle test
        Triangle t = new Triangle();
        t.setbase(70);
        t.setheight(50);
        System.out.println("The Triangle area: " + t.area()  + "\n");
        
        //Triangle test
        Cube c =new Cube();
        c.setheight(50);
        c.setlength(60);
        c.setwidth(80);
        System.out.println("The Cube area: " + c.area()  + "\n");
        System.out.println("The volume of Cube : " + c.area()  + "\n");
        
        
        
    }
    
}


المخرجات :

تمارين بلغة الجافا...أكتب برنامج لحساب مساحة المثلث و المربع و مساحة وحجم المكعب 94433206_2854453037957362_3419446746810417152_n.png?_nc_cat=100&_nc_sid=1480c5&_nc_eui2=AeGULpyaMsyCVUqRsdF1j4-Xf9bQKcKrVBt_1tApwqtUG32PnbEE2t-HfGJdlHzkdc9GgUHINzOAwo8SmEE1pss7&_nc_ohc=Q-sDAuHwDqkAX9lzxqU&_nc_ht=scontent.fkrt2-2

ـــــــــــــــــــ التوقيع ــــــــــــــــــــ
سبحان الله وبحمدة .....سبحان الله العظيم
أحمد مناع
أحمد مناع
.
.

تاريخ التسجيل : 15/02/2011
المساهمات : 1108
النقاط : 202034
التقيم : 144
الدولة : مصر
الجنس : ذكر

https://egy-tech.forumegypt.net

الرجوع الى أعلى الصفحة اذهب الى الأسفل

الرجوع الى أعلى الصفحة

ََ

مواضيع ذات صلة


 
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى