Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create an abstract class named Food with the following attributes: food _ ID ( int ) , food _ Name ( String ) , food

Create an abstract class named Food with the following attributes: food_ID (int), food_Name (String), food_Price (double), where the food_ID is a unique identifier that starts from the value (your student ID %10) and auto increments with each creation of a new child object of the Food class. Create a toString() method that returns the values of the food_ID, food_Name, and food_Price for any Food object. (4 Marks)
Create Apple and Orange classes which inherit from the Food class, with the following additional attributes for each of the child classes: color (String) and taste (String). Create the Setters and Getters for all attributes. In addition, override the toString() method that is inhereted from the Food class. None of the classes in the project should be able to inheret neither from the Apple nor the Orange classes. (4 Marks)
Create an interface named (Your First Name) with three methods as follows: (4 Marks)
void printFood(ArrayList food);
Food searchMaxPrice(ArrayList food);
int countOranges(ArrayList food);
The printFood method takes an ArrayList of Food objects as input and prints their details (depending on the toString() method defined in the Food class or any of its child classes (Apple and Orange).
The searchMaxPrice method takes an ArrayList of Food objects as input and returns the Food that has the maximum price (it can be a generic Food object, an Apple or Orange).
The countOranges method takes an ArrayList of Food objects as input and returns the number of Orange objects that are in the ArrayList.
Create a MainProgram class that implements the created interface. In the main method of the MainProgram class, create an ArrayList of Food objects and add three objects to the list as follows: one Apple object and two Orange objects. In the main method of the MainProgram class, call the three methods that have been implemented in the MainProgram class based on their definition in the interface. (8 Marks)
Upload your solution (using NetBeans) through Moodle, in one compressed file (your_name_yourID.zip)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions