Data Structures and Algorithms in Java
Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
Question
Book Icon
Chapter 1, Problem 10R
Program Plan Intro

Flowers

Program plan:

  • Create a class Flower to display the name, number of petals and price of flower.
    • Declare the required variables.
    • In main() function,
      • Create the objects for the class.
      • Use the instance flower to set and return the name, petals and price values of flower.
      • Call the function display() using the instance flower and display the flower name, pedals and price.
    • Create the default constructor with no arguments.
    • Create the parameterized constructor with the arguments “n”, “p”, and “d” to assign the name, pedals and price value respectively.
    • In the method setName(),
      • It passes the argument “n” to set the name of the flower.
    • In the method setPetals(),
      • It passes the argument “p” to set the number of petals in the flower.
    • In the method setPrice(),
      • It passes the argument “p” to set the price of the flower.
    • In the method getName(),
      • Return the name of the flower.
    • In the method getPetals(),
      • Return the petals of the flower.
    • In the method getPrice(),
      • Return the price of the flower.
    • In the method display (),
      • Print the details of the flower.

Blurred answer
Students have asked these similar questions
Create a Java Project (with a class and a test class) to represent some real-world entity such as a technology item (TV, Fan etc), an animal, a person, a vehicle, etc. In our class, we have already seen example classes such as Circle, Student, Rectangle, TV etc.
Write a Java program with at least two classes. Use a circle object to represent it. The class must offer at least one (non-static) setter method and one (non-static) getter method. Implement at least one test that invokes the setter method and the corresponding getter method so that the value out == the value in. Also use assert.Equal(60, circle1.getCircumference(), 10); and assert.Equals(10, circle1.get Radius(), 0.1); for radius
Please write a Java program with at least two classes. Use a circle to represent it! The class should have at least one non-static setter method and one non-static getter. Implement at least one method test that invokes the setter method and the corresponding getter method so that the value out == the value in!

Chapter 1 Solutions

Data Structures and Algorithms in Java

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education