Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

the fruit class contains attributes for a fruits type, color, and quant…

Question

the fruit class contains attributes for a fruits type, color, and quantity. the class also contains methods to allow the attributes to be accessed outside the class.
a class design diagram for the fruit class contains three sections. the first section contains the class name, the second section contains three instance variables and their data types, and the third section contains three methods and their return types.
the + symbol indicates a public designation, and the - symbol indicates a private designation.
fruit

  • type : string
  • color : string
  • (missing instance variable)

+ gettype() : string
+ getcolor() : string
+ (missing method)
which of the following are the most appropriate replacements for (missing instance variable) and (missing method)?
a replacing (missing instance variable) with - quantity : string and replacing (missing method) with + getquantity() : string
b replacing (missing instance variable) with - quantity : int and replacing (missing method) with + getquantity() : int
c replacing (missing instance variable) with - quantity : int and replacing (missing method) with + getquantity() : string
d replacing (missing instance variable) with - quantity : string and replacing (missing method) with + getquantity() : int

Explanation:

Step1: Analyze instance variable type

Instance variables in a class are typically declared with their appropriate data types. Quantity is likely to be an integer (int) as it represents a count, not a string. So the instance variable should be quantity : int.

Step2: Analyze method naming and return type

Methods that access instance variables (getter methods) in Java follow the naming convention getVariableName(). Since quantity is an int, the method getQuantity() should return an int. So the method should be + getQuantity() : int

Answer:

B. Replacing (missing instance variable) with quantity : int and replacing (missing method) with + getQuantity() : int