Computers and Technology

The third programming project 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, one class method and one 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 Project3 should contain the main method. It should generate the GUI shown below:

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.

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 00:30, alex7078
Quick pl which one of the following is considered a peripheral? a software b mouse c usb connector d motherboard
Answers: 1
image
Computers and Technology, 23.06.2019 05:20, jaylenmiller437
Which operating system is a version of linux?
Answers: 1
image
Computers and Technology, 23.06.2019 15:30, jokerr6323
1. ask the user how many questions are in the quiz. 2. ask the user to enter the key (that is, the correct answers). there should be one answer for each question in the quiz, and each answer should be an integer. e. g., 34 7 13 100 81 3 9 10 321 12 might be the key for a 10-question quiz. you will need to store the key in an array. 3. ask the user to enter the answers for the quiz to be graded. there needs to be one answer for each question. note that these answers do not need to be stored; each answer can simply be compared to the key as it is entered. 4. when the user has entered all of the answers to be graded, print the number correct and the percent correct. 5. add a loop so that the user can grade any number of quizzes with a single key. after the results have been printed for each quiz, ask "grade another quiz? (y/n)." note: you only have one array (the key). you are not creating a new key for each set of quiz answers.
Answers: 3
image
Computers and Technology, 23.06.2019 23:40, lexiecooley
4. what is the reason for including the following code snippet in the header file animal. h? #ifndef animal_h #define animal_h class animal { public: animal(); animal(double new_area_hunt); void birth(); void hunt(double new_area_hunt); void death(); double get_area_hunt() const; private: double area_hunt; }; #endif
Answers: 3
Do you know the correct answer?
The third programming project involves writing a program that draws two types of shapes, ovals and r...

Questions in other subjects:

Konu
Chemistry, 11.10.2019 05:30