Assume the following UML class diagram is given: Choose one object-oriented prog
ID: 3840269 • Letter: A
Question
Assume the following UML class diagram is given: Choose one object-oriented programming language and implement the solution according to the given class diagram. The solution must consist of class declarations and their method declarations/definitions. You can add to classes additional properties/methods and call standard library types if it is appropriate to support your solution The implementation is up to you, however, the evaluation will be based on your skills to apply encapsulation, constructors, inheritance, delegation, dynamic polymorphism and exception throwing/handling. The absence of precise syntax will not decrease the evaluation substantially. Don't demonstrate the use of implemented class instances! Write your solution on the provided sheets and sign them with your name before handing in.Explanation / Answer
public class Basket {
static final int MAX_SIZE=10;
Eatable[] item;
int count=0;
public Basket(){
item=new Eatable[MAX_SIZE];
}
public void put(Eatable new_item){
if(count<MAX_SIZE){
item[count]=new_item;
}else{
System.out.println("Basket is full");
}
}
void show_Content(){
System.out.println("The basket content is **************************");
for (int i = 0; i < MAX_SIZE; i++) {
System.out.println(item[i]);
}
}
}
public class Eatable {
String name;
public Eatable(String item){
name=item;
}
String getName(){
return name;
}
void show(){
System.out.println("Eatable item name is: "+name);
}
}
public class Apple extends Eatable{
String sort;
Apple(String name,String sort){
super(name);
this.sort=sort;
}
String get_sort(){
return sort;
}
@Override
void show(){
System.out.println("Eatable item name is: "+name);
}
public static void main(String args[]){
Apple a=new Apple("apple","app");
System.out.println(a.get_sort());
System.out.println(a.getName());
a.show();
Eatable e=new Eatable(a.getName());
Eatable e1=new Eatable("Orange");
Basket b=new Basket();
b.put(e);
b.put(e1);
b.show_Content();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.