الأجوبة
class Food {
private String name; //0.25
public Food(String name) { //0.25
this.name = name;
}
public String toString() { //0.25
return "Name: " + name;
}
}
public class SeaFood extends Food { //0.5
private double pricePerKilo; //0.25
private int quantity; //0.25
public SeaFood(String name, double price, int qty) { //0.75; 0.25 for
super
super(name);
pricePerKilo = price;
quantity = qty;
}
public String toString() { //0.5; 0.25 for super
return super.toString() + ", Price/kg: " + pricePerKilo + " SAR,
Quantity: "+ quantity + " kg";
}
public static void main(String[] args) {
double total = 0.0;
SeaFood sf[] = new SeaFood[3]; //0.5
sf[0] = new SeaFood("Shrimp", 60, 4); //0.5; for 3 objects
sf[1] = new SeaFood("Salmon", 50, 5);
sf[2] = new SeaFood("Tuna", 30, 2);
for (SeaFood item : sf) { //0.5
System.out.println(item); //0.25
total += (item.pricePerKilo*item.quantity); //0.5
}
System.out.println("Total price: " + total + " SAR"); //0.25
}
}
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال
معلومات ذات صلة
- جامعة الامير سطام
- برمجة2 programming2 CS2301
- برمجة جافا | Java programming
- ابحث عن مسائل برمجة جافا | Java programming بالانجليزي