Design a Java JFood class for a food which implements both cloneable and comparable interfaces The class should have the following private member variables:
Design a Java JFood class for a food which implements both cloneable and comparable interfaces The class should have the following private member variables:
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
1. Design a Java JFood class for a food which implements both cloneable and comparable interfaces
The class should have the following private member variables:
- mId: an integer that holds the food ID
- mName: a string that holds the food name
- mQuantity: an integer that holds quantity of servings of food
- mCalory: a double that holds calory of one serving of food
- mIngredients: an array of String that holds the names of all ingredients and its size is three
and the class should have the following public member functions:
- default constructor: initializes the product to some default one
- constructor #2: accepts id, name, quantity, calory and ingredients as arguments. The method should set these values to the appropriate instance variables
- setFood: accepts quantity, calory and ingredients as arguments. The method should set the arguments to the appropriate instance variables. Please note ingredients need be set as deep copy.
- Five respective get functions to retrieve the five instance variables' values. Please note OOP's Encapsulation needs to be conformed.
- Overrided compareTo()method: use total calory for comparison (total calory is the multiplication of quantity of servings and claory of one serving).
- Overrided clone() method which must conduct deep copy.
Please write your complete JProduct class and its testing class below
1a Write complete Java code for the above Java JFood class in JFood.java file.
1b In a new file named testFood.java, write your test Java class and its main method which will do the following:
- create two JFood objects(foodOne, foodTwo), foodOne with default constructor and foodTwo with the explicit constructor;
- then compare the two foods and output the one with less calory with its id, name, total calory (test of comparable interface) and all its ingredients;
- next create a third JFood object foodThree which is a clone of the one with less calory between foodOne and foodTwo, and then reset its quantity to a new quantity, its calory per serving to a new calory per serving and its ingredients to a new set of ingredients and output its ID, name, quantity, total calory and all of its ingredients.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY