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 program in java    Design a class that holds the following personal data: name, address, age, and phone number.Write appropriate accessor and mutator methods. Demonstrate the class by writing aprogram that creates three instances of it. One instance should hold your information, andthe other two should hold your friends’ or family members’ information.
JAVA A company needs to develop an object-oriented library with a few Java classes forthe following task. Overall, they want the classes to model the geometric shapes and calculatetheir areas. These geometric shapes include Square, Rectangle, Circle, and Triangle.The above four shapes share common attributes such as name and color. The area of a shapecan be calculated by using a method area( ) which can be implemented only until the exactshape is known. Different shapes need a different area( ) method.1) Design a Java abstract class called Shape to model this situation, which will serve as a parentclass. Write its code;2). All the above shapes should be drawable by the users by calling the draw( ) method.Different shapes are drawn differently. You should design a Java interface named Drawableto provide this method for the shape classes to implement in their own ways. Write its code;3). Write the code for the four classes: Square, Rectangle, Circle, and Triangle.Note:• You should decide…
Programing language is Java. Define a class Person that represents a person. People have a name, an age, anda phone number. Since people always have a name and an age, your class shouldhave a constructor that has those as parameters. Define a toString() method whichdisplays all of the relevant information using a format like this: “Jim Lahey - Age 57- Phone 9025555555”.

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