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

محتاجة مساعدة بسرعة

بدأه صمت الفراشات في 22 أكتوبر 2010 · 2 رد · 396 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

يا جماعة هذه أول مشاركة الي .. الحقيقة كنت ببحث عن حل لسؤال ما عرفت احله .. او بالاحرى مش فاهمة شو بدو

فيا ريت تساعدوني بسرعة و مشكورين

Apply the following then mention and discuss the output

class Shape {

void draw() {}

void erase() {}

}

class Circle extends Shape {

void draw() {

System.out.println("Circle.draw()");

}

void erase() {

System.out.println("Circle.erase()");

} }

class Square extends Shape {

void draw() {

System.out.println("Square.draw()");

}

void erase() {

System.out.println("Square.erase()");

}}

class Triangle extends Shape {

void draw() {

System.out.println("Triangle.draw()");

}

void erase() {

System.out.println("Triangle.erase()");

}}

   1. Build the main class Shapes that contains a static method randShapeegg that produces a reference to a randomly-selected Shape object each time you call it.
      The mainegg should contains an array of ten Shape references filled through randShapeegg. through this array call drawegg for each one
   2. Add a new type of Shape and verify in mainegg that polymorphism works for your new type as it does in the old types.
   3. Add a new method in the base class that prints a message, but don’t override it in the derived classes, call it in the main as you did with draw(),.Explain what happens. Now override it in one of the derived classes but not the others, and see what happens. Finally, override it in all the derived classes.
   4. Add a new method in the Square class that prints its name, call it in the main as you did with draw(),explain what happens, explain how we can use it correctly?
#2

يرجى وضع محاولاتك

لعدم غلق الموضوع لمخالفته قوانينن المنتدى فقره حل الواجبات

Software Developer
Mahmoudkelany.com


 

#3
Mahmoud Kelany كتب:

يرجى وضع محاولاتك

لعدم غلق الموضوع لمخالفته قوانينن المنتدى فقره حل الواجبات

package shape;
import java.lang.*;
import java.util.*;
import java.math.*;





       public class Main {

     public static void main(String[] args) {
         Shape []stuff = new Shape[10] ;
         for (int i=0;i<=10;i++)
             stuff.randShape();
         for (Shape s : stuff)
             s.draw();



       }
   }




class Shape {
void randShape(){
     Random rand = new Random();
     int j = rand.nextInt();
}
void draw() {
System.out.print();
}

void erase() {}

}

class Circle extends Shape {

void draw() {

//System.out.println("Circle.draw()");

}

void erase() {

System.out.println("Circle.erase()");

} }

class Square extends Shape {

void draw() {

System.out.println("Square.draw()");


}

void erase() {

System.out.println("Square.erase()");

}}

class Triangle extends Shape {

void draw() {

System.out.println("Triangle.draw()");

}

void erase() {

System.out.println("Triangle.erase()");

}}

بس ما ادري وين خطأ البرنامج ؟

تم تعديل هذه المشاركة بواسطة صمت الفراشات في 22 أكتوبر 2010 في 21:23

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