Related questions
JAVA
A company needs to develop an object-oriented library with a few Java classes for
the following task. Overall, they want the classes to model the geometric shapes and calculate
their 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 shape
can be calculated by using a method area( ) which can be implemented only until the exact
shape 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 parent
class. 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 Drawable
to 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 what data members you should have for each class based on
mathematical concepts;
• You should determine the relationship between the four classes and Drawable and Shape;
• You should provide all constructors, get/set methods, the draw( ) method, the area( )
method, and toString() methods.
• Use the following formulas for calculating areas of the four shapes:
o Area of Square = side x side;
o Area of Rectangle = length x width;
o Area of Circle = PI x radius x radius;
o Area of Triangle = 0.5 x base x height;
• In the test driver code, create an object of each of the four classes with some dimension
data, put the objects in an array, and pass the object array to a method called
displayShapeAreas(Shape[ ] shapeArray) and have their areas displayed.
Step by stepSolved in 8 steps with 1 images
- An object of the class Timer is used to indicate when a certain amount of time (in seconds) has elapsed, after which it provides a "DING". The required data field is remainingTime which is the number of seconds until the "DING". When a Timer object is constructed, it is set with the desired number of seconds. When the timer "ticks", it is one second closer to the "DING". This is represented with the tick) method. The dingChecko method indicates whether the timer should be "DINGING". Provide the code for the constructor method, and the methods getRemainingTime), tick(), and dingCheck). public class Timer // Methods // Data private int KeuainingTinei }arrow_forwardWrite PHP code for a class that contains three private variables and a method that consumes those variables and which displays an output. One of the variables must be a date/time class instance and another variable must be an arrayarrow_forwardWhat are the advantages of passing this data into a method as opposed to just passing it into the current class object?arrow_forward
- 1. Define a Class: Circle Circle - radius: double + Circle() +Circle(double r) +setradius(double r): void +getradius() : double +calculateArea(): double +calculateCircumference: double 2. Use a Circle instance (object) in a main() method Program.arrow_forwardConsider the following class definition. public class Gadget { private static int status = 0; public Gadget () { status - 10; public static void setstatus (int s) { status The following code segment appears in a method in a class other than Gadget. Gadget a = new Gadget () ; Gadget.setstatus(3); Gadget b = new Gadget () ; Which of the following best describes the behavior of the code segment? a. The code segment does not compile because the setstatus method should be called on an object of the class Gadget, not on the class itself. b. The code segment creates two Gadget objects a and b. The class Gadget's static variable status is set to 10, then to 3, and then back to 10. c. The code segment creates two Gadget objects a and b. After executing the code segment, the object a has a status value of 3 and the object b has a status value of 3. d. The code segment creates two Gadget objects a and b. After executing the code segment, the object a has a status value of 3 and the object b has a...arrow_forwardJAVA. THIS IS A PROGRAMMING ASSIGNMENT NOT A WRITING ASSIGNMENT IF YOU ANSWERED BEFORE DO NOT ANSWER AGAIN PLEASE DO NOT PASTE A PAPER Design a class to store the following information about computer scientists⦁ Name⦁ Research area(s)⦁ Major contribution A scientist may have more than one area of research.⦁ Implement the usual setters and getters methods ⦁ Implement a method that takes a research area as an input and return thenames of scientists associated with that area ⦁ Implement a method that takes a word as an input and return the names ofscientists whose contribution mention that word Next, perform desktop research to find at least five prominent black computerscientists, with their research area(s) and major contribution, and store this data intoobjects of the class you designed. You can just hardcode this data. No user input needed.Define JUnit tests to check your research area and contribution search methods.arrow_forward
- Create a UML Diagram of a class named Investment with fields called principal and interest. It also contains methods named value_after that returns the value of the investment after n years. The formula for this is p(1+i)n, where p is the principal, and i is the interest rate.arrow_forwardDesign and implement the class Day that implements the day of the week in a program. The program should be able to perform the following operations on an object of the type Day: Set the day. Print the day. Return the day. Return the next day. Return the previous day. Add a comment with your full name in it in any part of the program.arrow_forwardJava programarrow_forward
- Pythonarrow_forwardJava Programming Please help me with this Java Progamming project NOT GRADED. Practice homework Please comment the code well and organize the classes so I can understand. Thank you! If solution if the one that is desirable, I will upvote! I really appreciate this, Bartleby! Waiting Times should not be negative. You sent back a solution but the waiting time was negative and that was incorrect. Please take your time and help me with this.arrow_forwardDesign a class called Stopwatch. The job of this class is to simulate a stopwatch. It should provide two methods: Start and Stop. We call the start method first, and the stop method next. Then we ask the stopwatch about the duration between start and stop. Duration should be a value in TimeSpan. Display the duration on the console. We should also be able to use a stopwatch multiple times. So we may start and stop it and then start and stop it again. Make sure the duration value each time is calculated properly. We should not be able to start a stopwatch twice in a row (because that may overwrite the initial start time). So the class should throw an InvalidOperationException if its started twice. 1arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education