تمارين بلغة الجافا...أكتب برنامج لحساب مساحة المثلث و المربع و مساحة وحجم المكعب
منتدى مصر التقني :: قسم لغات البرمجة Programming languages :: لغة الجافا Java :: نقاش و أستفسارات الاعضاء
صفحة 1 من اصل 1 • شاطر
تمارين بلغة الجافا...أكتب برنامج لحساب مساحة المثلث و المربع و مساحة وحجم المكعب
اهلا وسهلا بكم
راسلنى احد الاصدقاء على صفحات الفيس طلبا لحل النشاط التالى :
و حل السؤال على النحو التالى :
المخرجات :
راسلنى احد الاصدقاء على صفحات الفيس طلبا لحل النشاط التالى :
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 - 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");
}
}
المخرجات :
ـــــــــــــــــــ التوقيع ــــــــــــــــــــ
سبحان الله وبحمدة .....سبحان الله العظيم
| |
منتدى مصر التقني :: قسم لغات البرمجة Programming languages :: لغة الجافا Java :: نقاش و أستفسارات الاعضاء
صفحة 1 من اصل 1
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى
الخميس أبريل 25, 2024 8:56 pm من طرف moslema_r
» شركة مكافحة حشرات في راس الخيمة
الخميس أبريل 25, 2024 8:34 pm من طرف moslema_r
» تطبيقIncogniton لإدارة ملفات تعريف متعددة للمتصفح
الأربعاء أبريل 24, 2024 3:51 pm من طرف زاكااا
» افضل شركة مكافحة النمل الابيض بالرياض
الإثنين أبريل 22, 2024 9:41 pm من طرف moslema_r
» Exemplary Сasual Dating - Verified Women
الخميس أبريل 18, 2024 9:18 pm من طرف wdqwd
» رش الدفان بالرياض
الخميس أبريل 18, 2024 7:11 pm من طرف moslema_r
» شركة تنظيف خزانات الشارقة
الخميس أبريل 18, 2024 6:57 pm من طرف moslema_r
» شركة مكافحة الفئران بالرياض
الإثنين أبريل 15, 2024 8:23 pm من طرف moslema_r
» افضل شركة كشف تسربات المياه بالباحة
الخميس أبريل 04, 2024 7:02 am من طرف gmalnagy
» ساعدوني وفهموني help me
الجمعة مارس 29, 2024 8:37 am من طرف linesoft