Answered step by step
Verified Expert Solution
Link Copied!

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

    1. 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.
  1. 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

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_2

Step: 3

blur-text-image_3

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

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

=+34-1 Define cognition, and describe the functions of concepts.

Answered: 1 week ago