טוען...
טוען...
לפניך חלק מפרויקט העוסק בכלֵי תחבורה וכולל את המחלקות האלה:
| המחלקה | תפקידה |
|---|---|
Vehicle | מייצגת כלִי תחבורה |
Train | מייצגת רכבת שהיא כלי תחבורה |
Boat | מייצגת סירה שהיא כלי תחבורה |
Airplane | מייצגת מטוס שהיא כלי תחבורה |
TransportationCompany | מייצגת חברה שיש לה כלֵי תחבורה מסוגים שונים |
public class Vehicle {
private String type;
private String way;
private int maxSpeed;
public Vehicle(String type, String way, int maxSpeed) {
this.type = type;
this.way = way;
this.maxSpeed = maxSpeed;
}
}
public class Train extends Vehicle {
private int numOfCarriages;
public Train(int maxSpeed, int numOfCarriages) {
super("land", "tracks", maxSpeed);
this.numOfCarriages = numOfCarriages;
}
public void incNumOfCarriages(int n) {
this.numOfCarriages = this.numOfCarriages + n;
}
}
public class Boat extends Vehicle {
public Boat(String way, int maxSpeed) {
super("water", way, maxSpeed);
}
}
public class Airplane extends Vehicle {
private int maxHeight;
public Airplane(int maxSpeed, int maxHeight) {
super("sky", "air", maxSpeed);
this.maxHeight = maxHeight;
}
}
public class TransportationCompany {
private Vehicle[] vehicles = new Vehicle[50];
private int counter = 0;
public void addVehicle(Vehicle v) {
this.vehicles[counter] = v;
this.counter++;
}
}ממש ב־Java מחלקה ראשית Program ובה פעולה ראשית, שתבצע את המשימות האלה:
i בנייה של עצם מטיפוס חברה של כלֵי תחבורה — TransportationCompany — הנקרא company1.
ii הוספה של סירה אחת ורכבת אחת לחברה company1.
בחר לתכונות ערכים כרצונך.
במחלקה TransportationCompany הוגדרה הפעולה:
java1public void display()
2{
3 for (int i=0; i<this.counter; i++)
4 {
5 System.out.println((i+1) + ":" + this.vehicles[i]);
6 }
7}
ממש ב־Java פעולות שיאפשרו ביצוע תקין של הפעולה display(), כך שבעבור כל כלִי תחבורה יודפסו כל התכונות שלו. הגדר את הפעולות באופן המתאים ביותר לעקרונות של תכנות מונחה עצמים (הכמסה — encapsulation, הורשה — inheritance, פולימורפיזם — polymorphism).
בעבור כל פעולה שאתה מממש, רשוֹם לאיזו מחלקה היא שייכת.
אין לשנות את הפעולה display().
ממש ב־Java פעולה, שתקבל מספר שלם n ותוסיף n קרונות לכל הרכבות ששייכות לחברה שיש לה כלֵי תחבורה מסוגים שונים. תעד את הפעולה, ורשום באיזו מחלקה יש להגדיר אותה. אין לשנות את הפעולות הקיימות בפרויקט.
לפניך חלק מפרויקט העוסק בכלֵי תחבורה וכולל את המחלקות האלה:
| המחלקה | תפקידה |
|---|---|
Vehicle | מייצגת כלִי תחבורה |
Train | מייצגת רכבת שהיא כלי תחבורה |
Boat | מייצגת סירה שהיא כלי תחבורה |
Airplane | מייצגת מטוס שהיא כלי תחבורה |
TransportationCompany | מייצגת חברה שיש לה כלֵי תחבורה מסוגים שונים |
public class Vehicle {
private String type;
private String way;
private int maxSpeed;
public Vehicle(String type, String way, int maxSpeed) {
this.type = type;
this.way = way;
this.maxSpeed = maxSpeed;
}
}
public class Train extends Vehicle {
private int numOfCarriages;
public Train(int maxSpeed, int numOfCarriages) {
super("land", "tracks", maxSpeed);
this.numOfCarriages = numOfCarriages;
}
public void incNumOfCarriages(int n) {
this.numOfCarriages = this.numOfCarriages + n;
}
}
public class Boat extends Vehicle {
public Boat(String way, int maxSpeed) {
super("water", way, maxSpeed);
}
}
public class Airplane extends Vehicle {
private int maxHeight;
public Airplane(int maxSpeed, int maxHeight) {
super("sky", "air", maxSpeed);
this.maxHeight = maxHeight;
}
}
public class TransportationCompany {
private Vehicle[] vehicles = new Vehicle[50];
private int counter = 0;
public void addVehicle(Vehicle v) {
this.vehicles[counter] = v;
this.counter++;
}
}ממש ב־Java מחלקה ראשית Program ובה פעולה ראשית, שתבצע את המשימות האלה:
i בנייה של עצם מטיפוס חברה של כלֵי תחבורה — TransportationCompany — הנקרא company1.
ii הוספה של סירה אחת ורכבת אחת לחברה company1.
בחר לתכונות ערכים כרצונך.
במחלקה TransportationCompany הוגדרה הפעולה:
java1public void display()
2{
3 for (int i=0; i<this.counter; i++)
4 {
5 System.out.println((i+1) + ":" + this.vehicles[i]);
6 }
7}
ממש ב־Java פעולות שיאפשרו ביצוע תקין של הפעולה display(), כך שבעבור כל כלִי תחבורה יודפסו כל התכונות שלו. הגדר את הפעולות באופן המתאים ביותר לעקרונות של תכנות מונחה עצמים (הכמסה — encapsulation, הורשה — inheritance, פולימורפיזם — polymorphism).
בעבור כל פעולה שאתה מממש, רשוֹם לאיזו מחלקה היא שייכת.
אין לשנות את הפעולה display().
ממש ב־Java פעולה, שתקבל מספר שלם n ותוסיף n קרונות לכל הרכבות ששייכות לחברה שיש לה כלֵי תחבורה מסוגים שונים. תעד את הפעולה, ורשום באיזו מחלקה יש להגדיר אותה. אין לשנות את הפעולות הקיימות בפרויקט.