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
Write a class in Java , named Patient that has fields for the following data: First name, middle name, and last name Address, city, state, and ZIP code Phone number Name and phone number of emergency contact The patient class should have a constructor, accessor, and mutator that accept an argument for each field.
in java A class called Author (as shown in the class diagram) is designed to model a book's author. It contains: Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'); One constructor to initialize the name, email and gender with the given values; public Author (String name, String email, char gender) {......} (There is no default constructor for Author, as there are no defaults for name, email and gender.) public getters/setters: getName(), getEmail(), setEmail(), and getGender();(There are no setters for name and gender, as these attributes cannot be changed.) A toString() method that returns string representation of author. A class called Book is designed (as shown in the class diagram) to model a book written by one author. It contains: Four private instance variables: name (String), author (of the class Author you have just created, assume that a book has one and only one author), price (double), and qty (int); Two…
Design a class named Person with properties for holding a person’s name, address, and telephone number. Next, design a class named Customer, which is derived from the Person class. The Customer class should have a property for a customer number and a Boolean property indicating whether the customer wishes to be on a mailing list. Demonstrate an object of the Customer class in a simple application.

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