quiz حل الأسئلة الجامعية manage_search الأرشيف

تم الحل ✓
categoryبرمجة وتطوير البرمجيات schoolبكالوريوس event_available2026-07-15

السؤال

Transcribed Image Text:

This PoD is focused on dependency. You will write a method that will take a Banana as input, and will return true or false, depending on whether the banana could be considered edible. Details Input The input for this problem has been handled for you. Processing You need to write the "checklfEdible" method at the bottom of PoD.java. The method has the following signature: public static boolean checklfEdible (Banana b) This method is quite simple. It returns true if the banana is ripe and not rotten. These values can be accessed using "b.getlsRipe[]" and "b.getlsRotten[]". Take a look at the Banana.java file that has been provided. That's it! Background: The point of the problem is to show you dependency, which is a fairly simple concept. Notice that this method takes in a Banana object as input, and clearly we need to access the "isRipe" and the "isRotten" attributes of that object. But, what if we changed the Banana class to no longer have a "isRipe" attribute? Our method would break! This is what makes this method "depend" on the Banana class. You might notice that the code for this problem is really not too hard, but the point is to show you how dependencies can appear. Output Output has been handled for you. Output Output has been handled for you. Sample Input/output: Sample Input Sample Output true true false true true false false false true false true true false false true false This banana is NOT edible! Banana: ripe-true rotten=true This banana is NOT edible! Banana: ripe=false rotten=true This banana is edible! Banana: ripe-true rotten=false This banana is NOT edible! Banana: ripe=false rotten=false This banana is edible! Banana: ripe-true rotten=false This banana is NOT edible! Banana: ripe-true rotten=true This banana is NOT edible! Banana: ripe=false rotten=false This banana is edible! Banana: ripe-true rotten=false Banana.Java PoD.Java New public class Banana { private boolean isRipe; private boolean isRotten; public Banana (boolean isRipe, boolean isRotten) { } this.isRipe = isRipe; this.isRotten = isRotten; public boolean getIsRipe() { } return this.isRipe; public boolean getIsRotten() { } return this.isRotten; public void setIsRipe (boolean ripe) { this.isRipe = ripe; } public void setIs Rotten (boolean rotten) { } this.isRotten = rotten; public String toString() { return "Banana: ripe="+this.isRipe+" rotten="+this.isRotten; } } Banana.Java PoD.Java New import java.util.*; public class POD { public static void main(String [] args) { Scanner input = new Scanner (System.in); while (input.hasNext()) { boolean ripe = input.nextBoolean(); boolean rotten = input.nextBoolean(); Banana b = new Banana(ripe, rotten); if (checkIfEdible(b)) { System.out.println("This banana is edible! "+b); } else { System.out.println("This banana is NOT edible! "+b); } } } } // Write the "checkIfEdible" method here. // Remember to make it public and static!

check_circle الجواب — حل مفصل خطوة بخطوة

hourglass_top