Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 13.2, Problem 13.2.2CP
The getArea() and getPerimeter() methods may be removed from the GeometricObject class. What are the benefits of defining getArea() and getPerimeter() as abstract methods in the GeometricObject class?
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Iterating over a collection of items is the job of the for construct's looping
mechanism. So long as there are things to process, it will keep running forever.
So, what do you make of this?
This is for pygame
Ball Class:
The Ball class inherits from Drawable and it will draw a circle at its current location. You must implement at the very least the required methods of the base class (draw and get_rect), as well as a constructor. You may need to implement other methods as part of the public interface.
This is the Drawable Class
Shape
-width: double
-length: double
+allmutatorMethods
Shapes2D
Shapes3D
-height:double
*calSize():double
+calVolume():double
1.
Define class Shape, 2DShape and 3DShape as per UML class diagram given.
2.
Define all mutator methods(set and get) for all classes.
3.
Define methods calArea() with formula area - width * length for 2DShapes.
4.
Define methods calArea() with formula calvolume, volume = width*length*height for 3DShapes.
In the main program, declare and set data in 1 object of 3DShapes. Create an array OR ArrayList of 2DShapes, set and display the info of all
objects as shown in the output.
5.
Chapter 13 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 13.2 - Prob. 13.2.1CPCh. 13.2 - The getArea() and getPerimeter() methods may be...Ch. 13.2 - True or false? a.An abstract class can be used...Ch. 13.3 - Prob. 13.3.1CPCh. 13.3 - Prob. 13.3.2CPCh. 13.3 - Prob. 13.3.3CPCh. 13.3 - What is wrong in the following code? (Note the...Ch. 13.3 - What is wrong in the following code? public class...Ch. 13.4 - Can you create a Calendar object using the...Ch. 13.4 - Prob. 13.4.2CP
Ch. 13.4 - How do you create a Calendar object for the...Ch. 13.4 - For a Calendar object c, how do you get its year,...Ch. 13.5 - Prob. 13.5.1CPCh. 13.5 - Prob. 13.5.2CPCh. 13.5 - Prob. 13.5.3CPCh. 13.5 - Prob. 13.5.4CPCh. 13.6 - Prob. 13.6.1CPCh. 13.6 - Prob. 13.6.2CPCh. 13.6 - Can the following code be compiled? Why? Integer...Ch. 13.6 - Prob. 13.6.4CPCh. 13.6 - What is wrong in the following code? public class...Ch. 13.6 - Prob. 13.6.6CPCh. 13.6 - Listing 13.5 has an error. If you add list.add...Ch. 13.7 - Can a class invoke the super.clone() when...Ch. 13.7 - Prob. 13.7.2CPCh. 13.7 - Show the output of the following code:...Ch. 13.7 - Prob. 13.7.4CPCh. 13.7 - What is wrong in the following code? public class...Ch. 13.7 - Show the output of the following code: public...Ch. 13.8 - Prob. 13.8.1CPCh. 13.8 - Prob. 13.8.2CPCh. 13.8 - Prob. 13.8.3CPCh. 13.9 - Show the output of the following code: Rational r1...Ch. 13.9 - Prob. 13.9.2CPCh. 13.9 - Prob. 13.9.3CPCh. 13.9 - Simplify the code in lines 8285 in Listing 13.13...Ch. 13.9 - Prob. 13.9.5CPCh. 13.9 - The preceding question shows a bug in the toString...Ch. 13.10 - Describe class-design guidelines.Ch. 13 - (Triangle class) Design a new Triangle class that...Ch. 13 - (Shuffle ArrayList) Write the following method...Ch. 13 - (Sort ArrayList) Write the following method that...Ch. 13 - (Display calendars) Rewrite the PrintCalendar...Ch. 13 - (Enable GeometricObject comparable) Modify the...Ch. 13 - Prob. 13.6PECh. 13 - (The Colorable interface) Design an interface...Ch. 13 - (Revise the MyStack class) Rewrite the MyStack...Ch. 13 - Prob. 13.9PECh. 13 - Prob. 13.10PECh. 13 - (The Octagon class) Write a class named Octagon...Ch. 13 - Prob. 13.12PECh. 13 - Prob. 13.13PECh. 13 - (Demonstrate the benefits of encapsulation)...Ch. 13 - Prob. 13.15PECh. 13 - (Math: The Complex class) A complex number is a...Ch. 13 - (Use the Rational class) Write a program that...Ch. 13 - (Convert decimals to fractious) Write a program...Ch. 13 - (Algebra: solve quadratic equations) Rewrite...Ch. 13 - (Algebra: vertex form equations) The equation of a...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
What was the first application for Java?
Concepts Of Programming Languages
Referring back to Questions 3 of Section 2.3, if the machine used the pipeline technique discussed in the text,...
Computer Science: An Overview (12th Edition)
T F A class may only have one destructor.
Starting Out with C++ from Control Structures to Objects (9th Edition)
Write an SQL statement to display the name and breed of all pets, sorted by PetName.
Database Concepts (7th Edition)
(Interest Calculator) The simple interest on a loan is calculated by the formula Interest = principal * rate * ...
C How to Program (8th Edition)
When displaying a Java applet, the browser invokes the _____ to interpret the bytecode into the appropriate mac...
Web Development and Design Foundations with HTML5 (8th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- In this assignment, you will implement part of a bigger program that deals with jewelry. You must submit the full implementation for the following interface: public interface JewelryBagInterface { public boolean addJewelryItem(int id, Jewelry j, double weight); public boolean removeJewelryItem(int id); public double getTotalWeight (); public double getTotalPrice (); public double getTotalGoldWeight (); public double getTotalSilverWeight (); public double getTotalBronzeWeight (); public void printBagContents(); public void setMaximumWeight (double max_weight); public void removeAllGoldItems(); public void removeAllsilverItems (); public void removeAllBronzeItems (); public int getTotalNumberOfitems(); public int getTotalNumberOfGoldItems (); public int getTotalNumberOfSilverItems (); public int getTotalNumberOfBronzeItems (); The interface JewelryBag java is available on Moodle (including the method descriptions). In your Java program, define the following enumerated type: Public enum…arrow_forwardHelp, I am making a elevator simulation using polymorphism. I am not sure to do now. Any help would be appreciated. My code is at the bottom, that's all I could think off. There are 4 types of passengers in the system:Standard: This is the most common type of passenger and has a request percentage of 70%. Standard passengers have no special requirements.VIP: This type of passenger has a request percentage of 10%. VIP passengers are given priority and are more likely to be picked up by express elevators.Freight: This type of passenger has a request percentage of 15%. Freight passengers have large items that need to be transported and are more likely to be picked up by freight elevators.Glass: This type of passenger has a request percentage of 5%. Glass passengers have fragile items that need to be transported and are more likely to be picked up by glass elevators. public abstract class Passenger { public static int passangerCounter = 0; private String passengerID; protected…arrow_forwardElevator simulation. I need help fixing this class The Simulation Class initializes and holds objects for Passengers, Elevators, and Floors. It reads and parses input files to create the necessary objects and sets the number of simulation iterations. The class also has methods to move the elevators up and down the building, as well as to pick up and drop off passengers. public class Simulation { private int numFloors; private ArrayList<Passenger> passengers; private ArrayList<Elevator> elevators; private ArrayList<Floor> floors; private int numIterations; public Simulation(String inputFile) throws FileNotFoundException { passengers = new ArrayList<>(); elevators = new ArrayList<>(); floors = new ArrayList<>(); // Read input file and initialize simulation parameters Scanner scanner = new Scanner(new File(inputFile)); while (scanner.hasNextLine()) { String line =…arrow_forward
- Please write the code in Java eclipse.arrow_forwardDesign a new Triangle class that extends the abstract GeometricObject class:Draw the UML diagram for the classes Triangle and GeometricObject0arrow_forwardThis is for pygame Text Class The Text class inherits from Drawable and it will be used to display the player’s score. You must implement at the very least the required methods of the base class (draw and get_rect), as well as a constructor. You may need to implement other methods as part of the public interface. This is the Drawable Classarrow_forward
- Define a Polygon interface that has methods area() and perimeter(). Then implement classes for Triangle, Quadrilateral, Pentagon, Hexagon, and Octagon, which implement this interface, with the obvious meanings for the area() and perimeter() methods. Also implement classes, IsoscelesTriangle, Equilateral- Triangle, Rectangle, and Square, which have the appropriate inheritance relationships. Finally, write a simple user interface, which allows users to create polygons of the various types, input their geometric dimensions, and then out- put their area and perimeter. For extra effort, allow users to input polygons by specifying their vertex coordinates and be able to test if two such polygons are similar ORIGINAL WORKS ONLYarrow_forwardIt's messy that in the Balrog class's getDamage() function and the Cyberdemon class's getDamage() function we have to write the name of the species before calling the Demon class's getDamage() function. It would be better if the Demon class's getDamage() function could print the name of the species. Taking this a step further, it would be even better if we didn't have to repeat the cout statement "The <whatever> attacks for ?? points!" in every class's getDamage() function. It would be better if that cout statement could occur just once, in the Creature class's getDamage() function. In the Creature class's getDamage() function, insert the following statement:cout << "The " << getSpecies() << " attacks for " << damage << " points!" << endl; Delete (or, if you prefer, comment out) the similar cout statements that appear in the getDamage() function of each of the 5 derived classes. (There will be one such cout statement to delete in each of the 5…arrow_forwardIt's messy that in the Balrog class's getDamage() function and the Cyberdemon class's getDamage() function we have to write the name of the species before calling the Demon class's getDamage() function. It would be better if the Demon class's getDamage() function could print the name of the species. Taking this a step further, it would be even better if we didn't have to repeat the cout statement "The <whatever> attacks for ?? points!" in every class's getDamage() function. It would be better if that cout statement could occur just once, in the Creature class's getDamage() function. In the Creature class's getDamage() function, insert the following statement: cout << "The " << getSpecies() << " attacks for " << damage << " points!" << endl; Delete (or, if you prefer, comment out) the similar cout statements that appear in the getDamage() function of each of the 5 derived classes. (There will be one such cout statement to delete in each of…arrow_forward
- Write a constructor for the IceCreamCup class. The constructor takes the name, and a List of Flavor s (name it fList) as parameters. It initializes the instance variables with the parameters. Use shallow copy for initializing the list of Flavor s. (Throw an IllegalArgumentException if the name is null, or the Flavor list is null or empty.) Note that successful instantiation should increase nCups by 1.arrow_forwardGiven the Solid class, extend it with: Pyramid Cylinder RectangularPrism Sphere Make sure to create the constructor and override the volume and surfaceArea methods. Also extend RectangularPrism with Cube. HINT: You can look up formulas for how to compute the volume and surface area of a certain type of shape online. ========================================== public class SolidTester{public static void main(String[] args){String name;double volume;double surfaceArea; // Pyramid constructor should take name, length, width, height// in that orderPyramid pyramid = new Pyramid("My pyramid", 1, 3, 5);name = pyramid.getName();volume = round(pyramid.volume(), 2);surfaceArea = round(pyramid.surfaceArea(), 2);System.out.println("Pyramid '" + name + "' has volume: " + volume +" and surface area: " + surfaceArea + "."); // Sphere constructor should take name then radiusSphere sphere = new Sphere("My sphere", 4);name = sphere.getName();volume = round(sphere.volume(), 2);surfaceArea =…arrow_forwardOverride the testOverriding() method in the Triangle class. Make it print “This is theoverridden testOverriding() method”. (add it to triangle class don't make a new code based on testOverriding in SimpleGeometricObject class.) (this was the step before this one) Add a void testOverriding() method to the SimpleGeometricObject class. Make it print“This is the testOverriding() method of the SimpleGeometricObject class”arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY