Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create a class named fruit with two private data members: name : representing a fruit name. Default value is Fruit. price : representing a fruit
-
- Create a class named fruit with two private data members:
- name: representing a fruit name. Default value is Fruit.
- price: representing a fruit price as a non-negative floating point number. Default value is 1.0.
Additionally, the class should also include the following methods:
- A default constructor to initialize the data members.
- A set method with parameters to set name and price.
- Two get methods to return values of name and price.
- Create a class named fruit with two private data members:
- write a java program that the following :
- define an object of type fruit named F1 and ask the user to enter its name and price
- define an object of type fruit named F2 with name "Orange" and price "3.5"
- print the data of F1 and F2.
- change F2 price to be 36.5
- print the data of F1 and F2.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started