Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Question
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.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents 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
Ch. 1 - Prob. 1RCh. 1 - Suppose that we create an array A of GameEntry...Ch. 1 - Write a short Java method, isMultiple, that takes...Ch. 1 - Write a short Java method, isEven, that takes an...Ch. 1 - Write a short Java method that takes an integer n...Ch. 1 - Write a short Java method that takes an integer n...Ch. 1 - Write a short Java method that takes an integer n...Ch. 1 - Write a short Java method that counts the number...Ch. 1 - Prob. 9RCh. 1 - Prob. 10R
Ch. 1 - Modify the CreditCard class from Code Fragment 1.5...Ch. 1 - Prob. 12RCh. 1 - Modify the declaration of the first for loop in...Ch. 1 - Prob. 14CCh. 1 - Write a pseudocode description of a method for...Ch. 1 - Write a short program that takes as input three...Ch. 1 - Write a short Java method that takes an array of...Ch. 1 - Prob. 18CCh. 1 - Write a Java program that can take a positive...Ch. 1 - Write a Java method that takes an array of float...Ch. 1 - Write a Java method that takes an array containing...Ch. 1 - Prob. 22CCh. 1 - Write a short Java program that takes two arrays a...Ch. 1 - Modify the CreditCard class from Code Fragment 1.5...Ch. 1 - Modify the CreditCard class to add a toString()...Ch. 1 - Write a short Java program that takes all the...Ch. 1 - Write a Java program that can simulate a simple...Ch. 1 - A common punishment for school children is to...Ch. 1 - The birthday paradox says that the probability...Ch. 1 - (For those who know Java graphical user interface...
Knowledge Booster
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.arrow_forwardin 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…arrow_forwardImplement the following using JAVA: a.Design a class named Person and its two subclasses named Student andEmployee. b.Make Faculty and Staff subclasses of Employee. Please note that,● A person has a name, address, phone number, and email address. A student has aclass status (freshman,sophomore, junior, or senior). You can define the status as aconstant.● An employee has office & salary.● A faculty member has office hours and a rank.● A staff member has a title. c. Draw a UML diagram of the system.arrow_forward
- Use the class diagram below to create a Parking Charge class for an object-oriented parking system. Write your code using java. Classes should contain properties and method implementations. N.B. Try to make your code readable.arrow_forwardAssignment must have a Java project and two separate classes.arrow_forwardWriting a java program that contains a class representing the vehicle And it contains basic specifications such as safe speed It is pre-installed and another variable for velocity is an amount The speed of the car and can be increased or decreased, and others Other specifications as desired by the student, as well L-car functions such as movement, stop and reverse, among others Of the jobs, according to the request of the student, so that the car is built By moving at a certain speed and when increasing and equaling the speed For safe speed, it will alert you when the speed is exceeded Safety the car stops permanently and speeds up Become zero. Note: Not all concepts are used In object-oriented programmingarrow_forward
- Java User-Defined Classes Write the definition of the class SwimmingPool, to implement the properties of a swimming pool. Your class should have the instance variables to atore the length(in feet), width (in feet), depth (in feet), the rate (in gallons per minute), at which the water is filling the pool, and the rate (in gallons per minute) at which the water is draining from the pool. And appropriate constructors to initialize the instance variables. Also, add member functions, to do the following: 1. Dtermine the amount of water needed to fill an empty pool or partially filled pool. 2. The time need to completely or partially fill the pool, or empty the pool; add water or drain for a specific amount of time. Here is my code that I have but not sure if it is correct. hank you: public static void main(String[] args) {double poolLength;double poolWidth;double poolDepth;double gallonsOfWater;double shallowEnd;double deepEnd;// System.out.println("Please enter the dimension of the…arrow_forwardNote: Write a Java program given below Question # 1: Define a class for Students with field name, age, marks. Define getter and setter for all the fields. In the setter method, if age is less than 0, print that Age is less than zero. Similarly, if marks is less than zero or greater than 100, print in correct marks and don’t assign marks to member variable. In the Test class, create student’s object and assign the marks and age to appropriate values. Try assigning incorrect values to check if getter and setter methods work as expected.arrow_forwardjava languageCreate a class with following attributes: The car's make The car's model The car's year Now let's identify the class's methods. Specifically, the actions are: Constructor of Car class Set and get the car's make Set and get the car's model Set and get the car's year Now create few instance of the Car in a Test class. Use getter and setter to set the instance variables. Create a class with following attributes: The car's make The car's model The car's year Now let's identify the class's methods. Specifically, the actions are: Constructor of Car class Set and get the car's make Set and get the car's model Set and get the car's year Now create few instance of the Car in a Test class. Use getter and setter to set the instance variables.arrow_forward
- Java Programming problem Create a checking account class with three attributes: account number, owner’s name, and balance. Create constructor, getters and setters. If one is to set the initial balance of an account as a negative value in a setter or a constructor, remind the user about the error and set it as 0. Create a CheckingAccountDemo class, and create a main method in which Ask for the name, account number, and initial balance for one account from the keyboard input. With these input values as arguments in a call to the constructor, create a CheckingAccount object. Print the summary of this account that includes information on the name, account number, and balance by calling the getters.arrow_forwardwrite a java program A course has a name, a course number, a department code(for example, CS, MATH) and a room number.• Include a static variable used to assign the course number to each Course in theconstructor. The value of the variable will start at 1000.• Write the instance variables, the accessors (getters), the mutators (setters) and twoconstructors for the class. One of the constructors should be the no args constructorWrite a second class, XXX_ TestCourse (XXX is your Kean Id) ,which will have amain method.• Create an Array of Course objects, which can hold 3 elements.• Using a loop:• Ask the user for the name, department and room number for 3 courses.• Create course objects.• Store the objects in the Array• At the end, traverse the array of courses and print each course on a separate linearrow_forwardWe have a need to develop an Object-Oriented Parking System. Attached below are all the classes in our system, but we only need a parking office class for this problem. Use the class diagrams and the full specification below to create a Parking Office class for an object-oriented parking system. Write your code using java. Full specification We have a need to develop an Object-Oriented Parking System. The system has several parking lots and the parking fees are different for each parking lot. Some parking lots scan permits only on entry. Charge is on entry, plus daily charges if car is parked overnight. Some parking lots scan permits on entry and exit, and charge is based on total hours parked, upon exit. Customers must have registered with the parking office in order to use any parking lot. Customers can use any parking lot. Each parking transaction will incur a charge to their account. Customers can have more than one car, and so they may request more than one parking permit for…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education