Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, so i am on a tutorial site, and i am running into a problem completing this coding. I have tried to do it many

Hello, so i am on a tutorial site, and i am running into a problem completing this coding. I have tried to do it many times and i keep failing it. I tried writing it many ways and i fail. If the entire thing can be done properly so i can actually see it, i can actually learn from looking at the completed code. Please i need this completed, thank you. The criteria is below. I will not submit this work as my own, and it is from a tutorial, i just need to see how the completed code looks so i can actually learn.

This code involves writing a program that draws two types of shapes, ovals and rectangles. This program consists of six classes. The first class is the Shape class, which is an abstract class that extends the predefined Java class Rectangle. It should contain two instance variables, the color of the shape and whether the shape is solid or hollow. It should also contain a class (static) variable that keeps track of how many shapes have been created.. It should have three instance methods, 1 class method and 1 abstract method:

1. A constructor that accepts three parameters for the purpose of initializing the characteristics of the shape, a Rectangle object that defines the dimensions and position of the shape, the color of the shape and whether the shape is solid or hollow. It should also update the number of shapes created so far. 2. An instance method named setColor that accepts the Graphics object as a parameter and sets the color for the next draw operation to the color of the current shape. 3. An instance method named getSolid that returns whether the shape is solid or hollow. 4. A class method named getNoOfShapes that returns the number of shapes created so far. 5. An abstract method named draw that accepts a Graphics object as a parameter.

The Shape class has two subclasses. The first is Oval. It should have the following two methods:

1. A constructor that accepts three parameters for the purpose of initializing the characteristics of the shape, a Rectangle object that defines the dimensions and position of the shape, the color of the shape and whether the shape is solid or hollow. 2. An overridden method draw that draws the Oval object on the Graphics object passed as a parameter.

The second subclass is Rectangular. It should have the following two methods:

1. A constructor that accepts three parameters for the purpose of initializing the characteristics of the shape, a Rectangle object that defines the dimensions and position of the shape, the color of the shape and whether the shape is solid or hollow. 2. An overridden method draw that draws the Rectangular object on the Graphics object passed as a parameter.

The fourth class is named Drawing, which should extend the predefined Java class JPanel. It has one instance variable that contains the shape that is currently drawn.. It should have three methods:

1. An overridden paintComponent method that draws the current shape on the Graphics object that is passed to it as a parameter. It should also draw the number of shapes that have been created thus far in the upper left corner.2. An overridden getPreferredSize method that specifies the dimensions of the drawing panel as 200 pixels wide and 200 pixels high.

3. An instance method named drawShape that is passed the current shape to be drawn. It first checks whether the shape provided will completely fit within the panel. If not, it throws an OutsideBounds exception. Otherwise, it saves the shape in the corresponding instance variable. It then calls repaint to cause that shape to be drawn.

No additional public methods should be included in any of the above classes.

The fifth class named OutsideBounds should define a checked exception.

The sixth class named GeoDrawing should contain the main method.It should generate the GUI shown below:

image text in transcribed
Geometric Drawing - 0 X Shape Type Oval Shape Drawing Fill Type Solid Color Red Width 100 Height 125 x coordinate 40 y coordinate 30 Draw The combo-box for the shape type should allow two choices, either Rectangle or Oval. The combo-box for the fill type should also allow two choices, either Hollow or Solid. The combo- box for the color should allow seven choices, Black, Red, Orange, Yellow, Green, Blue or Magenta. Clicking the Draw button should first check whether any non integer values have been entered in any of the fields that require integers. If so, an error message should be displayed in a JOptionPane window. Otherwise an appropriate Shape object should be created and passed to the drawShape method of the Drawing class. If that call results in an outsideBounds exception being thrown, an appropriate error message should be displayed in a JoptionPane window. Be sure to follow good programming style, which means making all instance variables private, naming all constants and avoiding the duplication of code. Furthermore you must select enough different kinds of shapes to completely test the program

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions