قديم منذ /12-10-2016, 03:57 PM   #1

طالب جديد

mylove1 غير متواجد حالياً

 

مواضيعي | ردودي

 رقم العضوية : 11923
 تاريخ الإنتساب : Oct 2014
 المشاركات : 27
 الجنس : ذكر
 مستوى التقييم : mylove1 is on a distinguished road
النقاط : 0

شكراً: 6
تم شكره 0 مرة في 0 مشاركة
افتراضي Assignment 1 -CS141


نحتاج الى تعاون الجميع لحل الواجب


Q1. Explain why and give examples. “In OO programming Polymorphism is only possible when using Interface or Inheritance” . (5 points)


Q2. Can we create an object of type Interface? Explain your answer. (5 points)


Q3. Complete the following code, and run to demonstrate the use of Interface. (10 points)
The main class tester is given to you, complete the code in the Interface and the two Classes.
Notice when coding Interface using Eclipse choose New Interface, NOT New Class
Here is a sample Run:
Return 0.0
Return 2000.5
Return 1.0
Return 0.25

public class chapt9Tester ** // the tester is complete, just run it after you finish the rest of the code
public static void main(String[] args) **
// create two bankaccount objects a1 using constructor without parameters, and object a2 using constructor with parameter sending it the amount 2000.50
BankAccount a1 = new BankAccount();
BankAccount a2 = new BankAccount(2000.50);
// create two coin objects c1 using constructor without parameters and c2 using constructor and sending 0.25 and "Quarter"
Coin c1 = new Coin();
Coin c2 = new Coin(0.25, "Quarter");
// now create an array of 4 elements of type Measurable and load it with the 4 objects that you just created
Measurable marr[] = ** a1, a2, c1, c2 **;
for ( int i=0; i< marr.length; i++) **
double r = marr[i].getMeasure(); // getMeasure() will behave differently depending on the object that called it
System.out.println("Return " + r);
**
// notice that a variable of type Measure marr can refer to BankAccount object or Coin object without casting.
// however it can only call the methods that are declared in the Measure interface
**

**
// This is the Interface complete the missing code, (if you use Eclipse: click on File -> New -> Interface )
public _______________ Measurable **
double getMeasure();
**
// BankAccount class will use the interface
public class BankAccount ___________________ Measurable{
private double balance;
public BankAccount(double amt) ** //constructor with parameter
balance = amt;
**
public BankAccount() ** //constructor without parameter, set balance to 0
____________________
**
public void deposit(double amt)**
balance = balance + amt;
**
public void withdraw(double amt)**
balance = balance - amt;
**
@Override
public double getMeasure() **
return balance;
**
**

// Coin class will use the same interface
public class Coin ________________ ____________________ **
private double value = 1;
private String name = "Dollar";
public Coin(double v, String n)** // constructor with two parameters
value = v;
name = n;
**
public _______________ ** // constructor without parameters
value = 1;
_____________________;
**

// implement the interface method getMeasure here

public _________ ___________________ **
return value;
**
**



Q4. What is the output of the following code: (10 points)
public class InheritanceTester **

public static void main(String[] args) **
MySubClass mysub = new MySubClass();
System.out.println(mysub.myMethod());
**

**

public class MySubClass extends MySuperClass{

public MySubClass()
**
System.out.println("Subclass constructor has been called..");
**

**

public class MySuperClass **

public MySuperClass()
**
System.out.println("Superclass constructor has been called..");
**

public String myMethod()
**
return "Superclass method has been called";
**
**



Q5. Consider the following problem description and write java code: (20 points)



A company need to store its employees information. Each employee has an id, name, date of birth, phone number and salary. Using the diagram, write your java classes that shows the inheritance between these classes, and consider the following:

1. Class employee has a method work() which returns the statement “I am an employee”
2. Class employee overrides toString() method to return the employee information. Or if you don’t what to override toString() you can write your own method to return the employee info. (both ways are accepted)
3. Each subclass should overrides the method work() to return its work. You need to call work() of the superclass. For example:
Method work() in executive class should returns:
I am an employee.. I work as an executive.

So in each subclass work() method first call it’s parent work() method by using super. Which will return “I am an employee ..” and then add the child own details. in this example “I work as an executive”

4. Implement the main class Company which constructs objects from the 3 subclasses, and test all of their methods.

Sample Run will result in:

I am an employee.. I work as an executive.
My ID is: 1234567890
My Name is: John Smith
My Date of Birth is: 1-1-1981
My phone is: 555-555-12345
My Salary is: 12,000

I am an employee.. I work as a Software Engineer.
My ID is: 0987654321
My Name is: Jane Doe
My Date of Birth is: 1-1-1988
My phone is: 555-555-12345
My Salary is: 10,000

I am an employee.. I work as a Software Manager.
My ID is: 9988776655
My Name is: Joe Green
My Date of Birth is: 1-1-1978
My phone is: 555-555-12345
My Salary is: 11,000







  رد مع اقتباس

قديم منذ /12-10-2016, 07:48 PM   #2

طالب جديد

راضي غير متواجد حالياً

 

مواضيعي | ردودي

 رقم العضوية : 12858
 تاريخ الإنتساب : Dec 2014
 المشاركات : 12
 الجنس : أنثى
 مستوى التقييم : راضي is on a distinguished road
النقاط : 0

شكراً: 0
تم شكره 0 مرة في 0 مشاركة
افتراضي


االلي يعرف الحل بليززز








  رد مع اقتباس
قديم منذ /13-10-2016, 02:07 AM   #3

طالب جديد

Frozen_H غير متواجد حالياً

 

مواضيعي | ردودي

 رقم العضوية : 14355
 تاريخ الإنتساب : Apr 2015
 المشاركات : 17
 الجنس : ذكر
 مستوى التقييم : Frozen_H is on a distinguished road
النقاط : 0

شكراً: 5
تم شكره 0 مرة في 0 مشاركة
افتراضي


اسعفونا بالحل تكفون ،








  رد مع اقتباس
قديم منذ /13-10-2016, 06:29 AM   #4

طالب جديد

hataro غير متواجد حالياً

 

مواضيعي | ردودي

 رقم العضوية : 8065
 تاريخ الإنتساب : Jan 2014
 المشاركات : 15
 الجنس : ذكر
 مستوى التقييم : hataro is on a distinguished road
النقاط : 0

شكراً: 0
تم شكره مرة واحدة في مشاركة واحدة
افتراضي


Superclass constructor has been called..
Subclass constructor has been called..
Superclass method has been called

جواب الرابع
ملاحظة النقاط تجي بعد كلمة called








  رد مع اقتباس
قديم منذ /14-10-2016, 06:25 PM   #5

طالب جديد

amarhon غير متواجد حالياً

 

مواضيعي | ردودي

 رقم العضوية : 17121
 تاريخ الإنتساب : Sep 2015
 المشاركات : 34
 الجنس : ذكر
 مستوى التقييم : amarhon is on a distinguished road
النقاط : 0

شكراً: 3
تم شكره 2 مرة في مشاركة واحدة
افتراضي


اجابة السؤال الثالث

موفقين






  رد مع اقتباس
قديم منذ /14-10-2016, 10:19 PM   #6

طالب جديد

mylove1 غير متواجد حالياً

 

مواضيعي | ردودي

 رقم العضوية : 11923
 تاريخ الإنتساب : Oct 2014
 المشاركات : 27
 الجنس : ذكر
 مستوى التقييم : mylove1 is on a distinguished road
النقاط : 0

شكراً: 6
تم شكره 0 مرة في 0 مشاركة
افتراضي


amarhon

الف شكر








  رد مع اقتباس
قديم منذ /15-10-2016, 05:37 AM   #7

طالب جديد

amarhon غير متواجد حالياً

 

مواضيعي | ردودي

 رقم العضوية : 17121
 تاريخ الإنتساب : Sep 2015
 المشاركات : 34
 الجنس : ذكر
 مستوى التقييم : amarhon is on a distinguished road
النقاط : 0

شكراً: 3
تم شكره 2 مرة في مشاركة واحدة
افتراضي


جواب السؤال الرابع
Superclass constructor has been called..
Subclass constructor has been called..
Superclass method has been called








  رد مع اقتباس
قديم منذ /15-10-2016, 01:04 PM   #8

طالب جديد

فيروز غير متواجد حالياً

 

مواضيعي | ردودي

 رقم العضوية : 19140
 تاريخ الإنتساب : Nov 2015
 المشاركات : 26
 الجنس : أنثى
 مستوى التقييم : فيروز is on a distinguished road
النقاط : 0

شكراً: 0
تم شكره 2 مرة في مشاركة واحدة
افتراضي


ي ليت احد يساعدنا ف الكود








  رد مع اقتباس
قديم منذ /15-10-2016, 07:40 PM   #9

طالب جديد

amarhon غير متواجد حالياً

 

مواضيعي | ردودي

 رقم العضوية : 17121
 تاريخ الإنتساب : Sep 2015
 المشاركات : 34
 الجنس : ذكر
 مستوى التقييم : amarhon is on a distinguished road
النقاط : 0

شكراً: 3
تم شكره 2 مرة في مشاركة واحدة
افتراضي


ممكن الأستفادة من الفديو ذا شبيه بحل السؤال الخامس أذا أحد عنده شيء ممكن يفيدنا








  رد مع اقتباس
قديم منذ /15-10-2016, 08:25 PM   #10

طالب نشيط

um 3bullah غير متواجد حالياً

 

مواضيعي | ردودي

 رقم العضوية : 4917
 تاريخ الإنتساب : Jul 2013
 المشاركات : 101
 الجنس : أنثى
 مستوى التقييم : um 3bullah is on a distinguished road
النقاط : 40

شكراً: 19
تم شكره 4 مرة في 3 مشاركة
افتراضي


نبي حل السؤال 5








  رد مع اقتباس
إضافة رد

مواقع النشر (المفضلة)

أدوات الموضوع
انواع عرض الموضوع

تعليمات المشاركة
لا تستطيع إضافة مواضيع جديدة
لا تستطيع الرد على المواضيع
لا تستطيع إرفاق ملفات
لا تستطيع تعديل مشاركاتك

BB code is متاحة
كود [IMG] متاحة
كود HTML معطلة
Trackbacks are متاحة
Pingbacks are متاحة
Refbacks are متاحة