(The Octagon class) Write a class named Octagon that extends GeometricObject and implements the Comparable and Cloneable interfaces. Assume all eight sides of the octagon are of equal length. The area can be computed using the following formula:
The Octagon class has a private double data field named side with its getter and setter methods. The class has a no-arg constructor that creates an Octagon with side 0, and a constructor to create an Octagon with a specified side.
Draw the UML diagram that involves Octagon, GeometricObject, Comparable, and Cloneable. Write a test program that creates an Octagon object with side value 5 and displays its area and perimeter. Create a new object using the clone method, and compare the two objects using the compareTo method.
Want to see the full answer?
Check out a sample textbook solutionChapter 13 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Starting Out with Java: Early Objects (6th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Artificial Intelligence: A Modern Approach
Problem Solving with C++ (9th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
- (Geometry: MyRectangle2D class) Define the MyRectangle2D class that contains: Two double data fields named x and y that specify the center of the rectangle with getter and setter methods. (Assume the rectangle sides are parallel to the x- or y-axis.) The data fields width and height with getter and setter methods. A no-arg constructor that creates a default rectangle with (0, 0) for (x, y) and 1 for both width and height. A Constructor that creates a rectangle with the specified x, y, width, and height. A method getArea() that returns the area of the rectangle. A method getPerimeter() that returns the perimeter of the rectangle. A method contains(double x, double y) that returns true if the specified point (x, y) is inside this rectangle (see Figure 10.24a ). A method contains(MyRectangle2D r) that returns true if the specified rectangle is inside this rectangle (see Figure 10.24b ). A method overlaps(MyRectangle2D r) that returns true if the specified rectangle overlaps with this…arrow_forwardCreate a Matrix class and implement the following member functions: The constructors and the destructor getSize() which returns the size of the matrix; setValue( int position, int value) which sets the value in the matrix at given position; getValue (int position) which returns the current value at given position; an add method which adds two matrices together; A= ● ● a subtract method which subtract two matrices together; a multiply methods which multiplies two matrices together, if possible; an overlap function which overlaps two matrices together. The augment function takes two matrices A and B of size mlxnl and m2xn2, respectively, and produce a new matrix C of size mLxnL, where mL (resp. nL) is the largest between m1 and m2 (resp. nl and n2). The values of C will either come from the original matrices by overlapping matrix B over matrix A. Wherever a value is not available it initialized to default value 0. For example: If you overlap two matrices A of size 4x2 and B of size 3x5,…arrow_forwardActivity: Create a collection of objects using Java generics. use java to write code. Create a Month class that can accept integer or String data type as an argument. The parameter type will be decided at run time. For this exercise, we will use Month class to store integer and string values that contains 12 months. For example, the integer value of 12 corresponds to string value of “December.” Use the following minimal class definition for Month class. public class Month<T> { private T month; public void setMonth(T month); public T getMonth(); }; Create a new class, MonthApp. This new class will have main method, and will instantiate Month objects to store month indices and names. Here is an example using arrays. // defineMonth<Integer>[] monthsByNumber = new Month<>[12];Month<String>[] monthsByName = new Month<>[12];// adding valuesmonthsByNumber[0] = new Month<Integer>();monthsByNumber[0].setMonth(1);monthsByName[0] = new…arrow_forward
- Description: Create a class named ComparableDog that extends Animal and implements Comparable interface. Implement the compareTo method to compare the Dogs on the basis of age. Write a test class to find the bigger age of two instances of ComparableDog Objects, and complement the ComparableDog class with the missing part. 1) The test program, the ComparableDog class, and its super class Animal are given as follows. // Main method public static void main(String[] args) { // Create two comparable Dogs ComparableDog dog1 = new ComparableDog(3); ComparableDog dog2 = new ComparableDog(4); System.out.println("Dog1:" + dog1); System.out.println("Dog2:" + dog2); if(dog1.compareTo(dog2) == 1) System.out.println("Dog1 is older than Dog2"); else if(dog1.compareTo(dog2) == -1) System.out.println("Dog1 is younger than Dog2"); else System.out.println("Dog1 and Dog2 have the same age"); }…arrow_forwardWrite the definitions of the member functions of the classes arrayListType and unorderedArrayListType that are not given in this chapter. The specific methods that need to be implemented are listed below. Implement the following methods in arrayListType.h: isEmpty isFull listSize maxListSize clearList Copy constructor Implement the following method in unorderedArrayListType.h insertAt Also, write a program (in main.cpp) to test your function.arrow_forwardQ#: Create a class Book that has the following data members: Name ISBN Author Edition Create a constructor to initialize all data members. Write a method PrintInfo to print information containing the fields of class. Write another class called Library that must contain a Main method. Inside Main, make at least 10 instances of Book, stored in an array (or list) of type Book. Call the method printInfo() for each instance. (Hint: use of foreach loop will be beneficial).arrow_forward
- LocalResource(String date, String sector)- Actions of the constructor include accepting a date in the format “dd/mm/yyyy”, initializing the base class, storing the sector and storing an id as a consecutively increasing integer. Note that the constructor must ensure that the date of birth information is recorded. b. getId():Integer - returns the ID of the current instance of LocalResource c. getSector():String – returns the sector associated with the current instance of localResource d. getTRN():String – returns the trn number of the current instance of LocalResource. The process used to determine the TRN is to add the id to the number 100000000 and then returning the string equivalent. e. Update the NineToFiver class to ensure it properly extends the LocalResource class f. In method getContact() of NineToFiver, remove the comments so that the method returns "Local Employee #"+and the id of the contact. Write a concrete class LocalConsultant that extends LocalResource, and implements…arrow_forwardPlease help me with this , I am stuck ! PLEASE WRITE IT IN C++ Thanks 1) bagUnion: The union of two bags is a new bag containing the combined contents of the original two bags. Design and specify a method union for the ArrayBag that returns as a new bag the union of the bag receiving the call to the method and the bag that is the method's parameter. The method signature (which should appear in the .h file and be implemented in the .cpp file is: ArrayBag<T> bagUnion(const ArrayBag<T> &otherBag) const; This method would be called in main() with: ArrayBag<int> bag1u2 = bag1.bagUnion(bag2); Note that the union of two bags might contain duplicate items. For example, if object x occurs five times in one bag and twice in another, the union of these bags contains x seven times. The union does not affect the contents of the original bags. Here is the main file: #include <cstdlib>#include <iostream>#include "ArrayBag.h"using namespace std; template…arrow_forward1. Implement the above system using inheritance in the best possible way. Keep every object size as small as possible. Implement all methods (setter/getter/constructors and destructors) Note that the region area is 0 while the city is len*width and the country is the sum of their cities. 2. Create array of countries called Arab of 22 countries, Write a function fill that fills the arrav Arab 3. Write a method that finds the city that has the max area in a country 4. Write a method that sorts the cities in a country from the largest to the smallest area 5. Write a function that retums array of countries of the same area of Arab 6. Write a function that compares between two countries. It returns true if countryl area greater than country2 area. 7. Write a function to move a city from one country to another.arrow_forward
- Please add a destructor to the code. Solve this in C++arrow_forward1) Implement a class Students Scores that models the scores of 30 students in four assessment components (Midterm, HWs, Labtest and Final). The class should use 2D array of double values and should provide methods to set and get the scores for any student at any assessment component. It should also provide methods to get the maximum, minimum, and average scores for any component. Your methods may look like the following: public void setScore (int studentID, String component, double temperature) public double getScore (int studentID, String component) public int getMaximumScore (String component) public int getMinimumScore (String component) public int getAverageScore (String component) 2) Document your class and produce a test program 'ScoresTester' that fill the scores with random marks and display the maximum, minimum and average scors.arrow_forwardCreate a Vector2D class with properties x and y and a proper constructor method. Plus, minus and multiplication with a scalar operators should be overloaded. Create a Body class with properties of pos, vel, mass and constructor(float Mass, Vector2D Pos, Vector2D Vel), addForce(Vector2D F) and Move(float dt) methods. Your program should create an array or collection of Bodies, at each time step (dt), calculate forces that bodies exert each other and apply accordingly. Finally, in a 2D space, bodies should move freely based on their properties and applied forces. You can use option buttons or another element to represent bodies and move them inside the form.arrow_forward
- 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